diff options
Diffstat (limited to 'xlators/protocol')
73 files changed, 40944 insertions, 39811 deletions
diff --git a/xlators/protocol/auth/addr/src/Makefile.am b/xlators/protocol/auth/addr/src/Makefile.am index 7f1dd7445bf..4694d254f12 100644 --- a/xlators/protocol/auth/addr/src/Makefile.am +++ b/xlators/protocol/auth/addr/src/Makefile.am @@ -1,11 +1,14 @@ auth_LTLIBRARIES = addr.la authdir = $(libdir)/glusterfs/$(PACKAGE_VERSION)/auth -addr_la_LDFLAGS = -module -avoidversion +addr_la_LDFLAGS = -module $(GF_XLATOR_LDFLAGS) addr_la_SOURCES = addr.c addr_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la -AM_CFLAGS = -fPIC -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -Wall -D$(GF_HOST_OS)\ - -I$(top_srcdir)/libglusterfs/src -shared -nostartfiles $(GF_CFLAGS) \ - -I$(top_srcdir)/xlators/protocol/server/src +AM_CPPFLAGS = $(GF_CPPFLAGS) -I$(top_srcdir)/libglusterfs/src \ + -I$(top_srcdir)/xlators/protocol/server/src \ + -I$(top_srcdir)/rpc/xdr/src/ -I$(top_builddir)/rpc/xdr/src/ \ + -I$(top_srcdir)/rpc/rpc-lib/src/ + +AM_CFLAGS = -Wall $(GF_CFLAGS) diff --git a/xlators/protocol/auth/addr/src/addr.c b/xlators/protocol/auth/addr/src/addr.c index 729233fa182..bf12c455d7c 100644 --- a/xlators/protocol/auth/addr/src/addr.c +++ b/xlators/protocol/auth/addr/src/addr.c @@ -1,231 +1,341 @@ /* - Copyright (c) 2007-2009 Gluster, Inc. <http://www.gluster.com> - This file is part of GlusterFS. - - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. -*/ - + Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.com> + This file is part of GlusterFS. -#ifndef _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif + 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 <fnmatch.h> #include <sys/socket.h> #include <netdb.h> #include "authenticate.h" -#include "dict.h" +#include <glusterfs/dict.h> +#include "rpc-transport.h" -#define ADDR_DELIMITER " ," +#define ENTRY_DELIMITER "," +#define ADDR_DELIMITER "|" #define PRIVILEGED_PORT_CEILING 1024 #ifndef AF_INET_SDP #define AF_INET_SDP 27 #endif -/* TODO: duplicate declaration */ -typedef struct peer_info { - struct sockaddr_storage sockaddr; - socklen_t sockaddr_len; - char identifier[UNIX_PATH_MAX]; -}peer_info_t; +/* An option for subdir validation be like below */ -auth_result_t -gf_auth (dict_t *input_params, dict_t *config_params) -{ - int ret = 0; - char *name = NULL; - char *searchstr = NULL; - char peer_addr[UNIX_PATH_MAX]; - data_t *peer_info_data = NULL; - peer_info_t *peer_info = NULL; - data_t *allow_addr = NULL, *reject_addr = NULL; - char is_inet_sdp = 0; - - name = data_to_str (dict_get (input_params, "remote-subvolume")); - if (!name) { - gf_log ("authenticate/addr", - GF_LOG_ERROR, - "remote-subvolume not specified"); - return AUTH_DONT_CARE; - } - - ret = asprintf (&searchstr, "auth.addr.%s.allow", name); - if (-1 == ret) { - gf_log ("auth/addr", GF_LOG_ERROR, - "asprintf failed while setting search string"); - return AUTH_DONT_CARE; - } - allow_addr = dict_get (config_params, - searchstr); - free (searchstr); - - ret = asprintf (&searchstr, "auth.addr.%s.reject", name); - if (-1 == ret) { - gf_log ("auth/addr", GF_LOG_ERROR, - "asprintf failed while setting search string"); - return AUTH_DONT_CARE; - } - reject_addr = dict_get (config_params, - searchstr); - free (searchstr); - - if (!allow_addr) { - /* TODO: backword compatibility */ - ret = asprintf (&searchstr, "auth.ip.%s.allow", name); - if (-1 == ret) { - gf_log ("auth/addr", GF_LOG_ERROR, - "asprintf failed while setting search string"); - return AUTH_DONT_CARE; - } - allow_addr = dict_get (config_params, searchstr); - free (searchstr); - } - - if (!(allow_addr || reject_addr)) { - gf_log ("auth/addr", GF_LOG_DEBUG, - "none of the options auth.addr.%s.allow or " - "auth.addr.%s.reject specified, returning auth_dont_care", - name, name); - return AUTH_DONT_CARE; - } - - peer_info_data = dict_get (input_params, "peer-info"); - if (!peer_info_data) { - gf_log ("authenticate/addr", - GF_LOG_ERROR, - "peer-info not present"); - return AUTH_DONT_CARE; - } - - peer_info = data_to_ptr (peer_info_data); - - switch (((struct sockaddr *) &peer_info->sockaddr)->sa_family) - { - case AF_INET_SDP: - is_inet_sdp = 1; - ((struct sockaddr *) &peer_info->sockaddr)->sa_family = AF_INET; - - case AF_INET: - case AF_INET6: - { - char *service; - uint16_t peer_port; - strcpy (peer_addr, peer_info->identifier); - service = strrchr (peer_addr, ':'); - *service = '\0'; - service ++; - - if (is_inet_sdp) { - ((struct sockaddr *) &peer_info->sockaddr)->sa_family = AF_INET_SDP; - } - - peer_port = atoi (service); - if (peer_port >= PRIVILEGED_PORT_CEILING) { - gf_log ("auth/addr", GF_LOG_ERROR, - "client is bound to port %d which is not privileged", - peer_port); - return AUTH_DONT_CARE; - } - break; - - case AF_UNIX: - strcpy (peer_addr, peer_info->identifier); - break; - - default: - gf_log ("authenticate/addr", GF_LOG_ERROR, - "unknown address family %d", - ((struct sockaddr *) &peer_info->sockaddr)->sa_family); - return AUTH_DONT_CARE; - } - } +/* 1. '*' + 2. '192.168.*' + 3. ' + 4. '!10.10.1*' (Today as per the code, if negate is set on one entry, its + never reset) + 5. '192.168.1.*, 10.1.10.*';168.168.2.* =/dir;* =/another-dir' + +*/ - if (reject_addr) { +int +compare_addr_and_update(char *option_str, char *peer_addr, char *subvol, + char *delimiter, auth_result_t *result, + auth_result_t status) +{ char *addr_str = NULL; - char *tmp; - char *addr_cpy = strdup (reject_addr->data); - - addr_str = strtok_r (addr_cpy, ADDR_DELIMITER, &tmp); - + char *tmp = NULL; + char negate = 0; + char match = 0; + int length = 0; + int ret = 0; + + addr_str = strtok_r(option_str, delimiter, &tmp); + while (addr_str) { - char negate = 0, match =0; - gf_log (name, GF_LOG_DEBUG, - "rejected = \"%s\", received addr = \"%s\"", - addr_str, peer_addr); - if (addr_str[0] == '!') { - negate = 1; - addr_str++; - } - - match = fnmatch (addr_str, - peer_addr, - 0); - if (negate ? match : !match) { - free (addr_cpy); - return AUTH_REJECT; - } - addr_str = strtok_r (NULL, ADDR_DELIMITER, &tmp); + gf_log(subvol, GF_LOG_INFO, "%s = \"%s\", received addr = \"%s\"", + (status == AUTH_ACCEPT) ? "allowed" : "rejected", addr_str, + peer_addr); + if (addr_str[0] == '!') { + negate = 1; + addr_str++; + } + + length = strlen(addr_str); + if ((addr_str[0] != '*') && valid_host_name(addr_str, length)) { + match = gf_is_same_address(addr_str, peer_addr); + if (match) { + *result = status; + goto out; + } + } else { + if (strstr(addr_str, "/")) { + match = gf_is_ip_in_net(addr_str, peer_addr); + if (negate ? !match : match) { + *result = status; + goto out; + } + } else { + match = fnmatch(addr_str, peer_addr, 0); + if (negate ? match : !match) { + *result = status; + goto out; + } + } + } + + addr_str = strtok_r(NULL, delimiter, &tmp); } - free (addr_cpy); - } - if (allow_addr) { + ret = -1; +out: + return ret; +} + +void +parse_entries_and_compare(char *option_str, char *peer_addr, char *subvol, + char *subdir, auth_result_t *result, + auth_result_t status) +{ + char *entry = NULL; + char *entry_cpy = NULL; + char *directory = NULL; + char *entries = NULL; char *addr_str = NULL; - char *tmp; - char *addr_cpy = strdup (allow_addr->data); - - addr_str = strtok_r (addr_cpy, ADDR_DELIMITER, &tmp); - - while (addr_str) { - char negate = 0, match = 0; - gf_log (name, GF_LOG_DEBUG, - "allowed = \"%s\", received addr = \"%s\"", - addr_str, peer_addr); - if (addr_str[0] == '!') { - negate = 1; - addr_str++; - } - - match = fnmatch (addr_str, - peer_addr, - 0); - - if (negate ? match : !match) { - free (addr_cpy); - return AUTH_ACCEPT; - } - addr_str = strtok_r (NULL, ADDR_DELIMITER, &tmp); + char *addr = NULL; + char *tmp = NULL; + char *tmpdir = NULL; + int ret = 0; + + if (!subdir) { + gf_log(subvol, GF_LOG_WARNING, + "subdir entry not present, not performing any operation."); + goto out; + } + + entries = gf_strdup(option_str); + if (!entries) + goto out; + + if (entries[0] != '/' && !strchr(entries, '(')) { + /* Backward compatible option */ + ret = compare_addr_and_update(entries, peer_addr, subvol, ",", result, + status); + goto out; + } + + entry = strtok_r(entries, ENTRY_DELIMITER, &tmp); + while (entry) { + entry_cpy = gf_strdup(entry); + if (!entry_cpy) { + goto out; + } + + directory = strtok_r(entry_cpy, "(", &tmpdir); + if (directory[0] != '/') + goto out; + + /* send second portion, after ' =' if directory matches */ + if (strcmp(subdir, directory)) + goto next_entry; + + addr_str = strtok_r(NULL, ")", &tmpdir); + if (!addr_str) + goto out; + + addr = gf_strdup(addr_str); + if (!addr) + goto out; + + gf_log(subvol, GF_LOG_INFO, + "Found an entry for dir %s (%s)," + " performing validation", + subdir, addr); + + ret = compare_addr_and_update(addr, peer_addr, subvol, ADDR_DELIMITER, + result, status); + if (ret == 0) { + break; + } + + GF_FREE(addr); + addr = NULL; + + next_entry: + entry = strtok_r(NULL, ENTRY_DELIMITER, &tmp); + GF_FREE(entry_cpy); + entry_cpy = NULL; + } + +out: + GF_FREE(entries); + GF_FREE(entry_cpy); + GF_FREE(addr); +} + +auth_result_t +gf_auth(dict_t *input_params, dict_t *config_params) +{ + auth_result_t result = AUTH_DONT_CARE; + int ret = 0; + char *name = NULL; + char *searchstr = NULL; + peer_info_t *peer_info = NULL; + data_t *peer_info_data = NULL; + data_t *allow_addr = NULL; + data_t *reject_addr = NULL; + char *service = NULL; + uint16_t peer_port = 0; + char peer_addr[UNIX_PATH_MAX] = { + 0, + }; + char *type = NULL; + gf_boolean_t allow_insecure = _gf_false; + char *subdir = NULL; + + name = data_to_str(dict_get(input_params, "remote-subvolume")); + if (!name) { + gf_log("authenticate/addr", GF_LOG_DEBUG, + "remote-subvolume not specified"); + goto out; } - free (addr_cpy); - } - - return AUTH_DONT_CARE; + + ret = gf_asprintf(&searchstr, "auth.addr.%s.allow", name); + if (-1 == ret) { + gf_log("auth/addr", GF_LOG_DEBUG, + "asprintf failed while setting search string"); + goto out; + } + + allow_addr = dict_get(config_params, searchstr); + GF_FREE(searchstr); + + ret = gf_asprintf(&searchstr, "auth.addr.%s.reject", name); + if (-1 == ret) { + gf_log("auth/addr", GF_LOG_ERROR, + "asprintf failed while setting search string"); + goto out; + } + reject_addr = dict_get(config_params, searchstr); + GF_FREE(searchstr); + + if (!allow_addr) { + /* TODO: backward compatibility */ + ret = gf_asprintf(&searchstr, "auth.ip.%s.allow", name); + if (-1 == ret) { + gf_log("auth/addr", GF_LOG_ERROR, + "asprintf failed while setting search string"); + goto out; + } + allow_addr = dict_get(config_params, searchstr); + GF_FREE(searchstr); + } + + if (!(allow_addr || reject_addr)) { + gf_log("auth/addr", GF_LOG_DEBUG, + "none of the options auth.addr.%s.allow or " + "auth.addr.%s.reject specified, returning auth_dont_care", + name, name); + goto out; + } + + peer_info_data = dict_get(input_params, "peer-info"); + if (!peer_info_data) { + gf_log("auth/addr", GF_LOG_ERROR, "peer-info not present"); + goto out; + } + + ret = dict_get_str(input_params, "subdir-mount", &subdir); + if (ret) { + subdir = "/"; + } + + peer_info = data_to_ptr(peer_info_data); + + switch (((struct sockaddr *)&peer_info->sockaddr)->sa_family) { + case AF_INET_SDP: + case AF_INET: + case AF_INET6: + strcpy(peer_addr, peer_info->identifier); + service = strrchr(peer_addr, ':'); + *service = '\0'; + service++; + + ret = dict_get_str(config_params, "rpc-auth-allow-insecure", &type); + if (ret == 0) { + ret = gf_string2boolean(type, &allow_insecure); + if (ret < 0) { + gf_log("auth/addr", GF_LOG_WARNING, + "rpc-auth-allow-insecure option %s " + "is not a valid bool option", + type); + goto out; + } + } + + peer_port = atoi(service); + if (peer_port >= PRIVILEGED_PORT_CEILING && !allow_insecure) { + gf_log("auth/addr", GF_LOG_ERROR, + "client is bound to port %d which is not privileged", + peer_port); + result = AUTH_REJECT; + goto out; + } + break; + + case AF_UNIX: + strcpy(peer_addr, peer_info->identifier); + break; + + default: + gf_log("authenticate/addr", GF_LOG_ERROR, + "unknown address family %d", + ((struct sockaddr *)&peer_info->sockaddr)->sa_family); + goto out; + } + + if (reject_addr) { + parse_entries_and_compare(reject_addr->data, peer_addr, name, subdir, + &result, AUTH_REJECT); + if (result == AUTH_REJECT) + goto out; + } + + if (allow_addr) { + parse_entries_and_compare(allow_addr->data, peer_addr, name, subdir, + &result, AUTH_ACCEPT); + } + +out: + return result; } struct volume_options options[] = { - { .key = {"auth.addr.*.allow"}, - .type = GF_OPTION_TYPE_ANY - }, - { .key = {"auth.addr.*.reject"}, - .type = GF_OPTION_TYPE_ANY - }, - /* Backword compatibility */ - { .key = {"auth.ip.*.allow"}, - .type = GF_OPTION_TYPE_ANY - }, - { .key = {NULL} } -}; + { + .key = {"auth.addr.*.allow"}, + .type = GF_OPTION_TYPE_INTERNET_ADDRESS_LIST, + .default_value = "*", + .description = "List of addresses to be allowed to access volume", + .op_version = {1}, + .flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC, + .tags = {}, + /* option_validation_fn validate_fn; */ + }, + { + .key = {"auth.addr.*.reject"}, + .type = GF_OPTION_TYPE_INTERNET_ADDRESS_LIST, + .default_value = "*", + .description = "List of addresses to be rejected to access volume", + .op_version = {1}, + .flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC, + .tags = {}, + /* option_validation_fn validate_fn; */ + }, + /* Backward compatibility */ + { + .key = {"auth.ip.*.allow"}, + .type = GF_OPTION_TYPE_INTERNET_ADDRESS_LIST, + .default_value = "*", + .description = "List of addresses to be allowed to access volume", + .op_version = {1}, + .flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC, + .tags = {}, + /* option_validation_fn validate_fn; */ + }, + {.key = {NULL}}}; diff --git a/xlators/protocol/auth/login/src/Makefile.am b/xlators/protocol/auth/login/src/Makefile.am index b4719d1a72f..9837437b11e 100644 --- a/xlators/protocol/auth/login/src/Makefile.am +++ b/xlators/protocol/auth/login/src/Makefile.am @@ -1,11 +1,13 @@ auth_LTLIBRARIES = login.la authdir = $(libdir)/glusterfs/$(PACKAGE_VERSION)/auth -login_la_LDFLAGS = -module -avoidversion +login_la_LDFLAGS = -module $(GF_XLATOR_LDFLAGS) login_la_SOURCES = login.c login_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la -AM_CFLAGS = -fPIC -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -Wall -D$(GF_HOST_OS)\ - -I$(top_srcdir)/libglusterfs/src -shared -nostartfiles $(GF_CFLAGS) \ - -I$(top_srcdir)/xlators/protocol/server/src +AM_CPPFLAGS = $(GF_CPPFLAGS) -I$(top_srcdir)/libglusterfs/src \ + -I$(top_srcdir)/xlators/protocol/server/src \ + -I$(top_srcdir)/rpc/xdr/src -I$(top_builddir)/rpc/xdr/src + +AM_CFLAGS = -Wall $(GF_CFLAGS) diff --git a/xlators/protocol/auth/login/src/login.c b/xlators/protocol/auth/login/src/login.c index 0c85292f717..64521267bfe 100644 --- a/xlators/protocol/auth/login/src/login.c +++ b/xlators/protocol/auth/login/src/login.c @@ -1,114 +1,210 @@ /* - Copyright (c) 2007-2009 Gluster, Inc. <http://www.gluster.com> - This file is part of GlusterFS. - - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. -*/ + Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.com> + This file is part of GlusterFS. -#ifndef _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif + 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 <fnmatch.h> #include "authenticate.h" -auth_result_t gf_auth (dict_t *input_params, dict_t *config_params) +/* Note on strict_auth + * - Strict auth kicks in when authentication is using the username, password + * in the volfile to login + * - If enabled, auth is rejected if the username and password is not matched + * or is not present + * - When using SSL names, this is automatically strict, and allows only those + * names that are present in the allow list, IOW strict auth checking has no + * implication when using SSL names + */ + +auth_result_t +gf_auth(dict_t *input_params, dict_t *config_params) { - int ret = 0; - char *username = NULL, *password = NULL; - data_t *allow_user = NULL, *username_data = NULL, *password_data = NULL; - int32_t result = AUTH_DONT_CARE; - char *brick_name = NULL, *searchstr = NULL; - - username_data = dict_get (input_params, "username"); - if (!username_data) - return AUTH_DONT_CARE; - - username = data_to_str (username_data); - - password_data = dict_get (input_params, "password"); - if (!password_data) - return AUTH_DONT_CARE; - - password = data_to_str (password_data); - - brick_name = data_to_str (dict_get (input_params, "remote-subvolume")); - if (!brick_name) { - gf_log ("auth/login", - GF_LOG_ERROR, - "remote-subvolume not specified"); - return AUTH_REJECT; - } - - ret = asprintf (&searchstr, "auth.login.%s.allow", brick_name); - if (-1 == ret) { - gf_log ("auth/login", GF_LOG_ERROR, - "asprintf failed while setting search string"); - return AUTH_DONT_CARE; - } - - allow_user = dict_get (config_params, - searchstr); - free (searchstr); - - if (allow_user) { + auth_result_t result = AUTH_DONT_CARE; + int ret = 0; + data_t *allow_user = NULL; + data_t *username_data = NULL; + data_t *passwd_data = NULL; + data_t *password_data = NULL; + char *username = NULL; + char *password = NULL; + char *brick_name = NULL; + char *searchstr = NULL; char *username_str = NULL; - char *tmp; - char *username_cpy = strdup (allow_user->data); - - username_str = strtok_r (username_cpy, " ,", &tmp); - - while (username_str) { - data_t *passwd_data = NULL; - if (!fnmatch (username_str, - username, - 0)) { - ret = asprintf (&searchstr, "auth.login.%s.password", username); - if (-1 == ret) { - gf_log ("auth/login", GF_LOG_ERROR, - "asprintf failed while setting search string"); - return AUTH_DONT_CARE; + char *tmp = NULL; + char *username_cpy = NULL; + gf_boolean_t using_ssl = _gf_false; + gf_boolean_t strict_auth = _gf_false; + + username_data = dict_get(input_params, "ssl-name"); + if (username_data) { + gf_log("auth/login", GF_LOG_INFO, "connecting user name: %s", + username_data->data); + using_ssl = _gf_true; + } else { + ret = dict_get_str_boolean(config_params, "strict-auth-accept", + _gf_false); + if (ret == -1) + strict_auth = _gf_false; + else + strict_auth = ret; + + username_data = dict_get(input_params, "username"); + if (!username_data) { + if (strict_auth) { + gf_log("auth/login", GF_LOG_DEBUG, + "username not found, strict auth" + " configured returning REJECT"); + result = AUTH_REJECT; + } else { + gf_log("auth/login", GF_LOG_DEBUG, + "username not found, returning" + " DONT-CARE"); + } + goto out; + } + password_data = dict_get(input_params, "password"); + if (!password_data) { + if (strict_auth) { + gf_log("auth/login", GF_LOG_DEBUG, + "password not found, strict auth" + " configured returning REJECT"); + result = AUTH_REJECT; + } else { + gf_log("auth/login", GF_LOG_WARNING, + "password not found, returning" + " DONT-CARE"); + } + goto out; + } + password = data_to_str(password_data); + } + username = data_to_str(username_data); + + brick_name = data_to_str(dict_get(input_params, "remote-subvolume")); + if (!brick_name) { + gf_log("auth/login", GF_LOG_ERROR, "remote-subvolume not specified"); + result = AUTH_REJECT; + goto out; + } + + ret = gf_asprintf(&searchstr, "auth.login.%s.%s", brick_name, + using_ssl ? "ssl-allow" : "allow"); + if (-1 == ret) { + gf_log("auth/login", GF_LOG_ERROR, + "asprintf failed while setting search string, " + "returning REJECT"); + result = AUTH_REJECT; + goto out; + } + + allow_user = dict_get(config_params, searchstr); + GF_FREE(searchstr); + + if (allow_user) { + gf_log("auth/login", GF_LOG_INFO, "allowed user names: %s", + allow_user->data); + /* + * There's a subtle difference between SSL and non-SSL behavior + * if we can't match anything in the "while" loop below. + * Intuitively, we should AUTH_REJECT if there's no match. + * However, existing code depends on allowing untrusted users + * to connect with *no credentials at all* by falling through + * the loop. They're still distinguished from trusted users + * who do provide a valid username and password (in fact that's + * pretty much the only thing we use non-SSL login auth for), + * but they are allowed to connect. It's wrong, but it's not + * worth changing elsewhere. Therefore, we do the sane thing + * only for SSL here. + * + * For SSL, if there's a list *you must be on it*. Note that + * if there's no list we don't care. In that case (and the + * ssl-allow=* case as well) authorization is effectively + * disabled, though authentication and encryption are still + * active. + * + * Read NOTE on strict_auth above. + */ + if (using_ssl || strict_auth) { + result = AUTH_REJECT; + } + username_cpy = gf_strdup(allow_user->data); + if (!username_cpy) + goto out; + + username_str = strtok_r(username_cpy, " ,", &tmp); + + /* + * We have to match a user's *authenticated* name to one in the + * list. If we're using SSL, they're already authenticated. + * Otherwise, they need a matching password to complete the + * process. + */ + while (username_str) { + if (!fnmatch(username_str, username, 0)) { + if (using_ssl) { + result = AUTH_ACCEPT; + break; + } + ret = gf_asprintf(&searchstr, "auth.login.%s.password", + username); + if (-1 == ret) { + gf_log("auth/login", GF_LOG_WARNING, + "asprintf failed while setting search string"); + goto out; + } + passwd_data = dict_get(config_params, searchstr); + GF_FREE(searchstr); + + if (!passwd_data) { + gf_log("auth/login", GF_LOG_ERROR, + "wrong username/password combination"); + result = AUTH_REJECT; + goto out; + } + + result = !((strcmp(data_to_str(passwd_data), password)) + ? AUTH_ACCEPT + : AUTH_REJECT); + if (result == AUTH_REJECT) + gf_log("auth/login", GF_LOG_ERROR, + "wrong password for user %s", username); + + break; + } + username_str = strtok_r(NULL, " ,", &tmp); } - passwd_data = dict_get (config_params, searchstr); - FREE (searchstr); - - if (!passwd_data) { - gf_log ("auth/login", - GF_LOG_DEBUG, - "wrong username/password combination"); - result = AUTH_REJECT; - } - else - result = !strcmp (data_to_str (passwd_data), password) ? AUTH_ACCEPT : AUTH_REJECT; - break; - } - username_str = strtok_r (NULL, " ,", &tmp); } - free (username_cpy); - } - return result; +out: + GF_FREE(username_cpy); + + return result; } struct volume_options options[] = { - { .key = {"auth.login.*.allow"}, - .type = GF_OPTION_TYPE_ANY - }, - { .key = {"auth.login.*.password"}, - .type = GF_OPTION_TYPE_ANY - }, - { .key = {NULL} } -}; + { + .key = {"auth.login.*.allow"}, + .type = GF_OPTION_TYPE_ANY, + .default_value = "*", + .description = "Username to be allowed access to the volume", + .op_version = {1}, + .flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC, + .tags = {}, + /* option_validation_fn validate_fn; */ + }, + { + .key = {"auth.login.*.password"}, + .type = GF_OPTION_TYPE_ANY, + .default_value = "*", + .description = "Password for the allowed username", + .op_version = {1}, + .flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC, + .tags = {}, + /* option_validation_fn validate_fn; */ + }, + {.key = {NULL}}}; diff --git a/xlators/protocol/client/src/Makefile.am b/xlators/protocol/client/src/Makefile.am index 007810e9901..785a51fc3b4 100644 --- a/xlators/protocol/client/src/Makefile.am +++ b/xlators/protocol/client/src/Makefile.am @@ -2,16 +2,20 @@ xlator_LTLIBRARIES = client.la xlatordir = $(libdir)/glusterfs/$(PACKAGE_VERSION)/xlator/protocol -client_la_LDFLAGS = -module -avoidversion +client_la_LDFLAGS = -module $(GF_XLATOR_DEFAULT_LDFLAGS) client_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la \ $(top_builddir)/rpc/rpc-lib/src/libgfrpc.la \ $(top_builddir)/rpc/xdr/src/libgfxdr.la -client_la_SOURCES = client.c client-helpers.c client3_1-fops.c \ - client-handshake.c client-callback.c -noinst_HEADERS = client.h client-mem-types.h +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-rpc-fops_v2.c -AM_CFLAGS = -fPIC -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -Wall -D$(GF_HOST_OS) \ - -I$(top_srcdir)/libglusterfs/src -shared -nostartfiles $(GF_CFLAGS) \ - -I$(top_srcdir)/rpc/xdr/src -I$(top_srcdir)/rpc/rpc-lib/src/ +noinst_HEADERS = client.h client-mem-types.h client-messages.h client-common.h + +AM_CPPFLAGS = $(GF_CPPFLAGS) -I$(top_srcdir)/libglusterfs/src \ + -I$(top_srcdir)/rpc/xdr/src -I$(top_builddir)/rpc/xdr/src \ + -I$(top_srcdir)/rpc/rpc-lib/src/ + +AM_CFLAGS = -Wall $(GF_CFLAGS) diff --git a/xlators/protocol/client/src/client-callback.c b/xlators/protocol/client/src/client-callback.c index 51bd3375845..d83d9c14899 100644 --- a/xlators/protocol/client/src/client-callback.c +++ b/xlators/protocol/client/src/client-callback.c @@ -1,60 +1,312 @@ /* - Copyright (c) 2010 Gluster, Inc. <http://www.gluster.com> + Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.com> This file is part of GlusterFS. - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. + 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. */ -#ifndef _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif - #include "client.h" #include "rpc-clnt.h" +#include <glusterfs/defaults.h> +#include "client-messages.h" -int -client_cbk_null (void *data) +static int +client_cbk_null(struct rpc_clnt *rpc, void *mydata, void *data) { - return 0; + gf_smsg(THIS->name, GF_LOG_WARNING, 0, PC_MSG_FUNCTION_CALL_ERROR, NULL); + return 0; } -int -client_cbk_fetchspec (void *data) +static int +client_cbk_fetchspec(struct rpc_clnt *rpc, void *mydata, void *data) { - gf_log ("", 1, "here i am"); - return 0; + gf_smsg(THIS->name, GF_LOG_WARNING, 0, PC_MSG_FUNCTION_CALL_ERROR, NULL); + return 0; } -int -client_cbk_ino_flush (void *data) +static int +client_cbk_ino_flush(struct rpc_clnt *rpc, void *mydata, void *data) { - return 0; + gf_smsg(THIS->name, GF_LOG_WARNING, 0, PC_MSG_FUNCTION_CALL_ERROR, NULL); + return 0; } -rpcclnt_cb_actor_t gluster_cbk_actors[] = { - [GF_CBK_NULL] = {"NULL", GF_CBK_NULL, client_cbk_null }, - [GF_CBK_FETCHSPEC] = {"FETCHSPEC", GF_CBK_FETCHSPEC, client_cbk_fetchspec }, - [GF_CBK_INO_FLUSH] = {"INO_FLUSH", GF_CBK_INO_FLUSH, client_cbk_ino_flush }, -}; +static int +client_cbk_recall_lease(struct rpc_clnt *rpc, void *mydata, void *data) +{ + int ret = -1; + struct iovec *iov = NULL; + struct gf_upcall upcall_data = { + 0, + }; + struct gf_upcall_recall_lease rl_data = { + 0, + }; + gfs3_recall_lease_req recall_lease = { + { + 0, + }, + }; + + GF_VALIDATE_OR_GOTO("client-callback", data, out); + + iov = (struct iovec *)data; + ret = xdr_to_generic(*iov, &recall_lease, + (xdrproc_t)xdr_gfs3_recall_lease_req); + + if (ret < 0) { + gf_smsg(THIS->name, GF_LOG_WARNING, -ret, PC_MSG_RECALL_LEASE_FAIL, + NULL); + goto out; + } + + upcall_data.data = &rl_data; + ret = gf_proto_recall_lease_to_upcall(&recall_lease, &upcall_data); + if (ret < 0) + goto out; + + upcall_data.event_type = GF_UPCALL_RECALL_LEASE; + + gf_msg_trace(THIS->name, 0, "Upcall gfid = %s, ret = %d", recall_lease.gfid, + ret); + + default_notify(THIS, GF_EVENT_UPCALL, &upcall_data); + +out: + if (recall_lease.xdata.xdata_val) + free(recall_lease.xdata.xdata_val); + + if (rl_data.dict) + dict_unref(rl_data.dict); + + return ret; +} + +static int +client_cbk_cache_invalidation(struct rpc_clnt *rpc, void *mydata, void *data) +{ + int ret = -1; + struct iovec *iov = NULL; + struct gf_upcall upcall_data = { + 0, + }; + struct gf_upcall_cache_invalidation ca_data = { + 0, + }; + gfs3_cbk_cache_invalidation_req ca_req = { + 0, + }; + + gf_msg_trace(THIS->name, 0, "Upcall callback is called"); + + if (!data) + goto out; + + iov = (struct iovec *)data; + ret = xdr_to_generic(*iov, &ca_req, + (xdrproc_t)xdr_gfs3_cbk_cache_invalidation_req); + + if (ret < 0) { + gf_smsg(THIS->name, GF_LOG_WARNING, -ret, + PC_MSG_CACHE_INVALIDATION_FAIL, NULL); + goto out; + } + + upcall_data.data = &ca_data; + ret = gf_proto_cache_invalidation_to_upcall(THIS, &ca_req, &upcall_data); + if (ret < 0) + goto out; + + gf_msg_trace(THIS->name, 0, + "Cache invalidation cbk received for gfid:" + " %s, ret = %d", + ca_req.gfid, ret); + + default_notify(THIS, GF_EVENT_UPCALL, &upcall_data); + +out: + if (ca_req.gfid) + free(ca_req.gfid); + + if (ca_req.xdata.xdata_val) + free(ca_req.xdata.xdata_val); + + if (ca_data.dict) + dict_unref(ca_data.dict); + + return 0; +} + +static int +client_cbk_child_up(struct rpc_clnt *rpc, void *mydata, void *data) +{ + clnt_conf_t *conf = NULL; + xlator_t *this = THIS; + + GF_VALIDATE_OR_GOTO("client", this, out); + conf = this->private; + GF_VALIDATE_OR_GOTO(this->name, conf, out); + + gf_msg_debug(this->name, 0, "Received CHILD_UP"); + conf->child_up = _gf_true; + + this->notify(this, GF_EVENT_CHILD_UP, NULL); +out: + return 0; +} + +static int +client_cbk_child_down(struct rpc_clnt *rpc, void *mydata, void *data) +{ + clnt_conf_t *conf = NULL; + xlator_t *this = THIS; + + GF_VALIDATE_OR_GOTO("client", this, out); + conf = this->private; + GF_VALIDATE_OR_GOTO(this->name, conf, out); + + gf_msg_debug(this->name, 0, "Received CHILD_DOWN"); + conf->child_up = _gf_false; + + this->notify(this, GF_EVENT_CHILD_DOWN, NULL); +out: + return 0; +} + +static int +client_cbk_inodelk_contention(struct rpc_clnt *rpc, void *mydata, void *data) +{ + int ret = -1; + struct iovec *iov = NULL; + struct gf_upcall upcall_data = { + 0, + }; + struct gf_upcall_inodelk_contention lc = { + { + 0, + }, + }; + gfs4_inodelk_contention_req proto_lc = { + { + 0, + }, + }; + + GF_VALIDATE_OR_GOTO("client-callback", data, out); + + iov = (struct iovec *)data; + ret = xdr_to_generic(*iov, &proto_lc, + (xdrproc_t)xdr_gfs4_inodelk_contention_req); + + if (ret < 0) { + gf_smsg(THIS->name, GF_LOG_WARNING, -ret, + PC_MSG_INODELK_CONTENTION_FAIL, NULL); + goto out; + } + + upcall_data.data = &lc; + ret = gf_proto_inodelk_contention_to_upcall(&proto_lc, &upcall_data); + if (ret < 0) + goto out; + + upcall_data.event_type = GF_UPCALL_INODELK_CONTENTION; + + default_notify(THIS, GF_EVENT_UPCALL, &upcall_data); + +out: + if (proto_lc.domain) + free(proto_lc.domain); + + if (proto_lc.xdata.xdata_val) + free(proto_lc.xdata.xdata_val); + + if (lc.xdata) + dict_unref(lc.xdata); + return ret; +} + +static int +client_cbk_entrylk_contention(struct rpc_clnt *rpc, void *mydata, void *data) +{ + int ret = -1; + struct iovec *iov = NULL; + struct gf_upcall upcall_data = { + 0, + }; + struct gf_upcall_entrylk_contention lc = { + 0, + }; + gfs4_entrylk_contention_req proto_lc = { + { + 0, + }, + }; + + GF_VALIDATE_OR_GOTO("client-callback", data, out); + + iov = (struct iovec *)data; + ret = xdr_to_generic(*iov, &proto_lc, + (xdrproc_t)xdr_gfs4_entrylk_contention_req); + + if (ret < 0) { + gf_smsg(THIS->name, GF_LOG_WARNING, -ret, + PC_MSG_ENTRYLK_CONTENTION_FAIL, NULL); + goto out; + } + + upcall_data.data = &lc; + ret = gf_proto_entrylk_contention_to_upcall(&proto_lc, &upcall_data); + if (ret < 0) + goto out; + + upcall_data.event_type = GF_UPCALL_ENTRYLK_CONTENTION; + + default_notify(THIS, GF_EVENT_UPCALL, &upcall_data); + +out: + if (proto_lc.name) + free(proto_lc.name); + + if (proto_lc.domain) + free(proto_lc.domain); + + if (proto_lc.xdata.xdata_val) + free(proto_lc.xdata.xdata_val); + + if (lc.xdata) + dict_unref(lc.xdata); + + return ret; +} + +static rpcclnt_cb_actor_t gluster_cbk_actors[GF_CBK_MAXVALUE] = { + [GF_CBK_NULL] = {"NULL", client_cbk_null, GF_CBK_NULL}, + [GF_CBK_FETCHSPEC] = {"FETCHSPEC", client_cbk_fetchspec, GF_CBK_FETCHSPEC}, + [GF_CBK_INO_FLUSH] = {"INO_FLUSH", client_cbk_ino_flush, GF_CBK_INO_FLUSH}, + [GF_CBK_CACHE_INVALIDATION] = {"CACHE_INVALIDATION", + client_cbk_cache_invalidation, + GF_CBK_CACHE_INVALIDATION}, + [GF_CBK_CHILD_UP] = {"CHILD_UP", client_cbk_child_up, GF_CBK_CHILD_UP}, + [GF_CBK_CHILD_DOWN] = {"CHILD_DOWN", client_cbk_child_down, + GF_CBK_CHILD_DOWN}, + [GF_CBK_RECALL_LEASE] = {"RECALL_LEASE", client_cbk_recall_lease, + GF_CBK_RECALL_LEASE}, + [GF_CBK_INODELK_CONTENTION] = {"INODELK_CONTENTION", + client_cbk_inodelk_contention, + GF_CBK_INODELK_CONTENTION}, + [GF_CBK_ENTRYLK_CONTENTION] = {"ENTRYLK_CONTENTION", + client_cbk_entrylk_contention, + GF_CBK_ENTRYLK_CONTENTION}, +}; struct rpcclnt_cb_program gluster_cbk_prog = { - .progname = "GlusterFS Callback", - .prognum = GLUSTER_CBK_PROGRAM, - .progver = GLUSTER_CBK_VERSION, - .actors = gluster_cbk_actors, - .numactors = GF_CBK_MAXVALUE, + .progname = "GlusterFS Callback", + .prognum = GLUSTER_CBK_PROGRAM, + .progver = GLUSTER_CBK_VERSION, + .actors = gluster_cbk_actors, + .numactors = GF_CBK_MAXVALUE, }; diff --git a/xlators/protocol/client/src/client-common.c b/xlators/protocol/client/src/client-common.c new file mode 100644 index 00000000000..c112820e407 --- /dev/null +++ b/xlators/protocol/client/src/client-common.c @@ -0,0 +1,3589 @@ +/* + Copyright (c) 2016 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 <glusterfs/dict.h> +#include <glusterfs/xlator.h> +#include "rpc-common-xdr.h" +#include "glusterfs3-xdr.h" +#include "glusterfs4-xdr.h" +#include "glusterfs3.h" +#include "client.h" + +/* processing to be done before fops are woudn down */ +int +client_pre_stat(xlator_t *this, gfs3_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); + + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, (&req->xdata.xdata_val), + req->xdata.xdata_len, op_errno, out); + + return 0; +out: + return -op_errno; +} + +int +client_pre_readlink(xlator_t *this, gfs3_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; + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, (&req->xdata.xdata_val), + req->xdata.xdata_len, op_errno, out); + return 0; +out: + return -op_errno; +} + +int +client_pre_mknod(xlator_t *this, gfs3_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; + + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, (&req->xdata.xdata_val), + req->xdata.xdata_len, op_errno, out); + + return 0; +out: + return -op_errno; +} + +int +client_pre_mkdir(xlator_t *this, gfs3_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; + + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, (&req->xdata.xdata_val), + req->xdata.xdata_len, op_errno, out); + + return 0; +out: + return -op_errno; +} + +int +client_pre_unlink(xlator_t *this, gfs3_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; + + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, (&req->xdata.xdata_val), + req->xdata.xdata_len, op_errno, out); + + return 0; +out: + return -op_errno; +} + +int +client_pre_rmdir(xlator_t *this, gfs3_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; + + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, (&req->xdata.xdata_val), + req->xdata.xdata_len, op_errno, out); + + return 0; +out: + return -op_errno; +} + +int +client_pre_symlink(xlator_t *this, gfs3_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; + + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, (&req->xdata.xdata_val), + req->xdata.xdata_len, op_errno, out); + return 0; +out: + return -op_errno; +} + +int +client_pre_rename(xlator_t *this, gfs3_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; + + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, (&req->xdata.xdata_val), + req->xdata.xdata_len, op_errno, out); + + return 0; +out: + return -op_errno; +} + +int +client_pre_link(xlator_t *this, gfs3_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; + + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, (&req->xdata.xdata_val), + req->xdata.xdata_len, op_errno, out); + + return 0; +out: + return -op_errno; +} + +int +client_pre_truncate(xlator_t *this, gfs3_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; + + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, (&req->xdata.xdata_val), + req->xdata.xdata_len, op_errno, out); + return 0; +out: + return -op_errno; +} + +int +client_pre_open(xlator_t *this, gfs3_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); + + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, (&req->xdata.xdata_val), + req->xdata.xdata_len, op_errno, out); + + return 0; +out: + return -op_errno; +} + +int +client_pre_readv(xlator_t *this, gfs3_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); + + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, (&req->xdata.xdata_val), + req->xdata.xdata_len, op_errno, out); + + return 0; +out: + return -op_errno; +} + +int +client_pre_writev(xlator_t *this, gfs3_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 + + GF_PROTOCOL_DICT_SERIALIZE(this, *xdata, (&req->xdata.xdata_val), + req->xdata.xdata_len, op_errno, out); + + return 0; +out: + return -op_errno; +} + +int +client_pre_statfs(xlator_t *this, gfs3_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); + + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, (&req->xdata.xdata_val), + req->xdata.xdata_len, op_errno, out); + + return 0; +out: + return -op_errno; +} + +int +client_pre_flush(xlator_t *this, gfs3_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); + + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, (&req->xdata.xdata_val), + req->xdata.xdata_len, op_errno, out); + + return 0; +out: + return -op_errno; +} + +int +client_pre_fsync(xlator_t *this, gfs3_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, FALLBACK_TO_ANON_FD, remote_fd, op_errno, + out); + + req->fd = remote_fd; + req->data = flags; + memcpy(req->gfid, fd->inode->gfid, 16); + + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, (&req->xdata.xdata_val), + req->xdata.xdata_len, op_errno, out); + + return 0; +out: + return -op_errno; +} + +int +client_pre_setxattr(xlator_t *this, gfs3_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) { + GF_PROTOCOL_DICT_SERIALIZE(this, xattr, (&req->dict.dict_val), + req->dict.dict_len, op_errno, out); + } + + req->flags = flags; + + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, (&req->xdata.xdata_val), + req->xdata.xdata_len, op_errno, out); + + return 0; +out: + return -op_errno; +} + +int +client_pre_getxattr(xlator_t *this, gfs3_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; + } + + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, (&req->xdata.xdata_val), + req->xdata.xdata_len, op_errno, out); + + return 0; +out: + return -op_errno; +} + +int +client_pre_removexattr(xlator_t *this, gfs3_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; + + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, (&req->xdata.xdata_val), + req->xdata.xdata_len, op_errno, out); + + return 0; +out: + return -op_errno; +} + +int +client_pre_opendir(xlator_t *this, gfs3_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); + + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, (&req->xdata.xdata_val), + req->xdata.xdata_len, op_errno, out); + + return 0; +out: + return -op_errno; +} + +int +client_pre_fsyncdir(xlator_t *this, gfs3_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); + + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, (&req->xdata.xdata_val), + req->xdata.xdata_len, op_errno, out); + + return 0; +out: + return -op_errno; +} + +int +client_pre_access(xlator_t *this, gfs3_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; + + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, (&req->xdata.xdata_val), + req->xdata.xdata_len, op_errno, out); + return 0; +out: + return -op_errno; +} + +int +client_pre_create(xlator_t *this, gfs3_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; + + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, (&req->xdata.xdata_val), + req->xdata.xdata_len, op_errno, out); + + return 0; +out: + return -op_errno; +} + +int +client_pre_ftruncate(xlator_t *this, gfs3_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); + + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, (&req->xdata.xdata_val), + req->xdata.xdata_len, op_errno, out); + return 0; +out: + return -op_errno; +} + +int +client_pre_fstat(xlator_t *this, gfs3_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); + + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, (&req->xdata.xdata_val), + req->xdata.xdata_len, op_errno, out); + + return 0; +out: + return -op_errno; +} + +int +client_pre_lk(xlator_t *this, gfs3_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_smsg(this->name, GF_LOG_WARNING, EINVAL, PC_MSG_UNKNOWN_CMD, + "gf_cmd=%d", gf_cmd, NULL); + 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); + + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, (&req->xdata.xdata_val), + req->xdata.xdata_len, op_errno, out); + + return 0; +out: + return -op_errno; +} + +int +client_pre_lookup(xlator_t *this, gfs3_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) { + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, (&req->xdata.xdata_val), + req->xdata.xdata_len, op_errno, out); + } + return 0; +out: + return -op_errno; +} + +int +client_pre_readdir(xlator_t *this, gfs3_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); + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, (&req->xdata.xdata_val), + req->xdata.xdata_len, op_errno, out); + + return 0; +out: + return -op_errno; +} + +int +client_pre_inodelk(xlator_t *this, gfs3_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_smsg(this->name, GF_LOG_WARNING, EINVAL, PC_MSG_UNKNOWN_CMD, + "gf_cmd=%d", gf_cmd, NULL); + 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); + + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, (&req->xdata.xdata_val), + req->xdata.xdata_len, op_errno, out); + + return 0; +out: + return -op_errno; +} + +int +client_pre_finodelk(xlator_t *this, gfs3_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_smsg(this->name, GF_LOG_WARNING, EINVAL, PC_MSG_UNKNOWN_CMD, + "gf_cmd=%d", gf_cmd, NULL); + 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); + + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, (&req->xdata.xdata_val), + req->xdata.xdata_len, op_errno, out); + return 0; +out: + return -op_errno; +} + +int +client_pre_entrylk(xlator_t *this, gfs3_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; + } + + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, (&req->xdata.xdata_val), + req->xdata.xdata_len, op_errno, out); + + return 0; +out: + return -op_errno; +} + +int +client_pre_fentrylk(xlator_t *this, gfs3_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); + + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, (&req->xdata.xdata_val), + req->xdata.xdata_len, op_errno, out); + + return 0; +out: + return -op_errno; +} + +int +client_pre_xattrop(xlator_t *this, gfs3_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); + if (xattr) { + GF_PROTOCOL_DICT_SERIALIZE(this, xattr, (&req->dict.dict_val), + req->dict.dict_len, op_errno, out); + } + + req->flags = flags; + + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, (&req->xdata.xdata_val), + req->xdata.xdata_len, op_errno, out); + + return 0; +out: + return -op_errno; +} + +int +client_pre_fxattrop(xlator_t *this, gfs3_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); + + if (xattr) { + GF_PROTOCOL_DICT_SERIALIZE(this, xattr, (&req->dict.dict_val), + req->dict.dict_len, op_errno, out); + } + + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, (&req->xdata.xdata_val), + req->xdata.xdata_len, op_errno, out); + + return 0; +out: + return -op_errno; +} + +int +client_pre_fgetxattr(xlator_t *this, gfs3_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); + + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, (&req->xdata.xdata_val), + req->xdata.xdata_len, op_errno, out); + + return 0; +out: + return -op_errno; +} + +int +client_pre_fsetxattr(xlator_t *this, gfs3_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) { + GF_PROTOCOL_DICT_SERIALIZE(this, xattr, (&req->dict.dict_val), + req->dict.dict_len, op_errno, out); + } + + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, (&req->xdata.xdata_val), + req->xdata.xdata_len, op_errno, out); + + return 0; +out: + return -op_errno; +} + +int +client_pre_rchecksum(xlator_t *this, gfs3_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; + + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, (&req->xdata.xdata_val), + req->xdata.xdata_len, op_errno, out); + + return 0; +out: + return -op_errno; +} + +int +client_pre_setattr(xlator_t *this, gfs3_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; + gf_stat_from_iatt(&req->stbuf, stbuf); + + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, (&req->xdata.xdata_val), + req->xdata.xdata_len, op_errno, out); + + return 0; +out: + return -op_errno; +} + +int +client_pre_fsetattr(xlator_t *this, gfs3_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); + + req->fd = remote_fd; + req->valid = valid; + gf_stat_from_iatt(&req->stbuf, stbuf); + + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, (&req->xdata.xdata_val), + req->xdata.xdata_len, op_errno, out); + return 0; +out: + return -op_errno; +} + +int +client_pre_readdirp(xlator_t *this, gfs3_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 */ + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, (&req->dict.dict_val), + req->dict.dict_len, op_errno, out); + + return 0; +out: + return -op_errno; +} + +int +client_pre_fremovexattr(xlator_t *this, gfs3_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; + + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, (&req->xdata.xdata_val), + req->xdata.xdata_len, op_errno, out); + + return 0; +out: + return -op_errno; +} + +int +client_pre_fallocate(xlator_t *this, gfs3_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); + + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, (&req->xdata.xdata_val), + req->xdata.xdata_len, op_errno, out); + return 0; +out: + return -op_errno; +} + +int +client_pre_discard(xlator_t *this, gfs3_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); + + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, (&req->xdata.xdata_val), + req->xdata.xdata_len, op_errno, out); + return 0; +out: + return -op_errno; +} + +int +client_pre_zerofill(xlator_t *this, gfs3_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); + + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, (&req->xdata.xdata_val), + req->xdata.xdata_len, op_errno, out); + return 0; +out: + return -op_errno; +} + +int +client_pre_ipc(xlator_t *this, gfs3_ipc_req *req, int32_t cmd, dict_t *xdata) +{ + int op_errno = ESTALE; + + req->op = cmd; + + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, (&req->xdata.xdata_val), + req->xdata.xdata_len, op_errno, out); + return 0; +out: + return -op_errno; +} + +int +client_pre_seek(xlator_t *this, gfs3_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; + + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, (&req->xdata.xdata_val), + req->xdata.xdata_len, op_errno, out); + + return 0; +out: + return -op_errno; +} + +int +client_pre_lease(xlator_t *this, gfs3_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); + + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, (&req->xdata.xdata_val), + req->xdata.xdata_len, op_errno, out); +out: + return -op_errno; +} + +/* processing done after fop responses are obtained */ +int +client_post_stat(xlator_t *this, gfs3_stat_rsp *rsp, struct iatt *iatt, + dict_t **xdata) +{ + int ret = 0; + + if (-1 != rsp->op_ret) { + gf_stat_to_iatt(&rsp->stat, iatt); + } + + GF_PROTOCOL_DICT_UNSERIALIZE(this, *xdata, (rsp->xdata.xdata_val), + (rsp->xdata.xdata_len), ret, rsp->op_errno, + out); + +out: + return ret; +} + +int +client_post_readlink(xlator_t *this, gfs3_readlink_rsp *rsp, struct iatt *iatt, + dict_t **xdata) +{ + int ret = 0; + + if (-1 != rsp->op_ret) { + gf_stat_to_iatt(&rsp->buf, iatt); + } + + GF_PROTOCOL_DICT_UNSERIALIZE(this, *xdata, (rsp->xdata.xdata_val), + (rsp->xdata.xdata_len), ret, rsp->op_errno, + out); + +out: + + return ret; +} + +int +client_post_mknod(xlator_t *this, gfs3_mknod_rsp *rsp, struct iatt *stbuf, + struct iatt *preparent, struct iatt *postparent, + dict_t **xdata) +{ + int ret = 0; + + if (-1 != rsp->op_ret) { + gf_stat_to_iatt(&rsp->stat, stbuf); + gf_stat_to_iatt(&rsp->preparent, preparent); + gf_stat_to_iatt(&rsp->postparent, postparent); + } + GF_PROTOCOL_DICT_UNSERIALIZE(this, *xdata, (rsp->xdata.xdata_val), + (rsp->xdata.xdata_len), ret, rsp->op_errno, + out); + +out: + return ret; +} + +int +client_post_mkdir(xlator_t *this, gfs3_mkdir_rsp *rsp, struct iatt *stbuf, + struct iatt *preparent, struct iatt *postparent, + dict_t **xdata) +{ + int ret = 0; + + if (-1 != rsp->op_ret) { + gf_stat_to_iatt(&rsp->stat, stbuf); + gf_stat_to_iatt(&rsp->preparent, preparent); + gf_stat_to_iatt(&rsp->postparent, postparent); + } + + GF_PROTOCOL_DICT_UNSERIALIZE(this, *xdata, (rsp->xdata.xdata_val), + (rsp->xdata.xdata_len), ret, rsp->op_errno, + out); + +out: + return ret; +} + +int +client_post_unlink(xlator_t *this, gfs3_unlink_rsp *rsp, struct iatt *preparent, + struct iatt *postparent, dict_t **xdata) +{ + int ret = 0; + + if (-1 != rsp->op_ret) { + gf_stat_to_iatt(&rsp->preparent, preparent); + gf_stat_to_iatt(&rsp->postparent, postparent); + } + + GF_PROTOCOL_DICT_UNSERIALIZE(this, *xdata, (rsp->xdata.xdata_val), + (rsp->xdata.xdata_len), ret, rsp->op_errno, + out); + + ret = gf_replace_new_iatt_in_dict(*xdata); +out: + return ret; +} + +int +client_post_rmdir(xlator_t *this, gfs3_rmdir_rsp *rsp, struct iatt *preparent, + struct iatt *postparent, dict_t **xdata) +{ + int ret = 0; + + if (-1 != rsp->op_ret) { + gf_stat_to_iatt(&rsp->preparent, preparent); + gf_stat_to_iatt(&rsp->postparent, postparent); + } + GF_PROTOCOL_DICT_UNSERIALIZE(this, *xdata, (rsp->xdata.xdata_val), + (rsp->xdata.xdata_len), ret, rsp->op_errno, + out); + +out: + return ret; +} + +int +client_post_symlink(xlator_t *this, gfs3_symlink_rsp *rsp, struct iatt *stbuf, + struct iatt *preparent, struct iatt *postparent, + dict_t **xdata) +{ + int ret = 0; + + if (-1 != rsp->op_ret) { + gf_stat_to_iatt(&rsp->stat, stbuf); + gf_stat_to_iatt(&rsp->preparent, preparent); + gf_stat_to_iatt(&rsp->postparent, postparent); + } + GF_PROTOCOL_DICT_UNSERIALIZE(this, *xdata, (rsp->xdata.xdata_val), + (rsp->xdata.xdata_len), ret, rsp->op_errno, + out); +out: + return ret; +} + +int +client_post_rename(xlator_t *this, gfs3_rename_rsp *rsp, struct iatt *stbuf, + struct iatt *preoldparent, struct iatt *postoldparent, + struct iatt *prenewparent, struct iatt *postnewparent, + dict_t **xdata) +{ + int ret = 0; + + if (-1 != rsp->op_ret) { + gf_stat_to_iatt(&rsp->stat, stbuf); + + gf_stat_to_iatt(&rsp->preoldparent, preoldparent); + gf_stat_to_iatt(&rsp->postoldparent, postoldparent); + + gf_stat_to_iatt(&rsp->prenewparent, prenewparent); + gf_stat_to_iatt(&rsp->postnewparent, postnewparent); + } + + GF_PROTOCOL_DICT_UNSERIALIZE(this, *xdata, (rsp->xdata.xdata_val), + (rsp->xdata.xdata_len), ret, rsp->op_errno, + out); +out: + return ret; +} + +int +client_post_link(xlator_t *this, gfs3_link_rsp *rsp, struct iatt *stbuf, + struct iatt *preparent, struct iatt *postparent, + dict_t **xdata) +{ + int ret = 0; + + if (-1 != rsp->op_ret) { + gf_stat_to_iatt(&rsp->stat, stbuf); + gf_stat_to_iatt(&rsp->preparent, preparent); + gf_stat_to_iatt(&rsp->postparent, postparent); + } + GF_PROTOCOL_DICT_UNSERIALIZE(this, *xdata, (rsp->xdata.xdata_val), + (rsp->xdata.xdata_len), ret, rsp->op_errno, + out); +out: + return ret; +} + +int +client_post_truncate(xlator_t *this, gfs3_truncate_rsp *rsp, + struct iatt *prestat, struct iatt *poststat, + dict_t **xdata) +{ + int ret = 0; + + if (-1 != rsp->op_ret) { + gf_stat_to_iatt(&rsp->prestat, prestat); + gf_stat_to_iatt(&rsp->poststat, poststat); + } + GF_PROTOCOL_DICT_UNSERIALIZE(this, *xdata, (rsp->xdata.xdata_val), + (rsp->xdata.xdata_len), ret, rsp->op_errno, + out); +out: + return ret; +} + +int +client_post_open(xlator_t *this, gfs3_open_rsp *rsp, dict_t **xdata) +{ + int ret = 0; + + GF_PROTOCOL_DICT_UNSERIALIZE(this, *xdata, (rsp->xdata.xdata_val), + (rsp->xdata.xdata_len), ret, rsp->op_errno, + out); +out: + return ret; +} + +int +client_post_readv(xlator_t *this, gfs3_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 = 0; + + if (rsp->op_ret != -1) { + *iobref = rsp_iobref; + gf_stat_to_iatt(&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; + } + GF_PROTOCOL_DICT_UNSERIALIZE(this, *xdata, (rsp->xdata.xdata_val), + (rsp->xdata.xdata_len), ret, rsp->op_errno, + out); + +#ifdef GF_TESTING_IO_XDATA + dict_dump_to_log(xdata); +#endif +out: + return ret; +} + +int +client_post_writev(xlator_t *this, gfs3_write_rsp *rsp, struct iatt *prestat, + struct iatt *poststat, dict_t **xdata) +{ + int ret = 0; + + if (-1 != rsp->op_ret) { + gf_stat_to_iatt(&rsp->prestat, prestat); + gf_stat_to_iatt(&rsp->poststat, poststat); + } + + GF_PROTOCOL_DICT_UNSERIALIZE(this, *xdata, (rsp->xdata.xdata_val), + (rsp->xdata.xdata_len), ret, rsp->op_errno, + out); + +out: + return ret; +} + +int +client_post_statfs(xlator_t *this, gfs3_statfs_rsp *rsp, struct statvfs *statfs, + dict_t **xdata) +{ + int ret = 0; + + if (-1 != rsp->op_ret) { + gf_statfs_to_statfs(&rsp->statfs, statfs); + } + GF_PROTOCOL_DICT_UNSERIALIZE(this, *xdata, (rsp->xdata.xdata_val), + (rsp->xdata.xdata_len), ret, rsp->op_errno, + out); +out: + return ret; +} + +int +client_post_flush(xlator_t *this, gf_common_rsp *rsp, dict_t **xdata) +{ + int ret = 0; + + GF_PROTOCOL_DICT_UNSERIALIZE(this, *xdata, (rsp->xdata.xdata_val), + (rsp->xdata.xdata_len), ret, rsp->op_errno, + out); + +out: + return ret; +} + +int +client_post_fsync(xlator_t *this, gfs3_fsync_rsp *rsp, struct iatt *prestat, + struct iatt *poststat, dict_t **xdata) +{ + int ret = 0; + + if (-1 != rsp->op_ret) { + gf_stat_to_iatt(&rsp->prestat, prestat); + gf_stat_to_iatt(&rsp->poststat, poststat); + } + GF_PROTOCOL_DICT_UNSERIALIZE(this, *xdata, (rsp->xdata.xdata_val), + (rsp->xdata.xdata_len), ret, rsp->op_errno, + out); +out: + return ret; +} + +int +client_post_setxattr(xlator_t *this, gf_common_rsp *rsp, dict_t **xdata) +{ + int ret = 0; + + GF_PROTOCOL_DICT_UNSERIALIZE(this, *xdata, (rsp->xdata.xdata_val), + (rsp->xdata.xdata_len), ret, rsp->op_errno, + out); + + ret = gf_replace_new_iatt_in_dict(*xdata); +out: + return ret; +} + +int +client_post_getxattr(xlator_t *this, gfs3_getxattr_rsp *rsp, dict_t **dict, + dict_t **xdata) +{ + int op_errno = 0; + int ret = 0; + + if (-1 != rsp->op_ret) { + GF_PROTOCOL_DICT_UNSERIALIZE(this, *dict, (rsp->dict.dict_val), + (rsp->dict.dict_len), rsp->op_ret, + op_errno, out); + } + GF_PROTOCOL_DICT_UNSERIALIZE(this, *xdata, (rsp->xdata.xdata_val), + (rsp->xdata.xdata_len), ret, op_errno, out); + +out: + return -op_errno; +} + +int +client_post_removexattr(xlator_t *this, gf_common_rsp *rsp, dict_t **xdata) +{ + int ret = 0; + + GF_PROTOCOL_DICT_UNSERIALIZE(this, *xdata, (rsp->xdata.xdata_val), + (rsp->xdata.xdata_len), ret, rsp->op_errno, + out); + + ret = gf_replace_new_iatt_in_dict(*xdata); +out: + return ret; +} + +int +client_post_opendir(xlator_t *this, gfs3_opendir_rsp *rsp, dict_t **xdata) +{ + int ret = 0; + + GF_PROTOCOL_DICT_UNSERIALIZE(this, *xdata, (rsp->xdata.xdata_val), + (rsp->xdata.xdata_len), ret, rsp->op_errno, + out); +out: + return ret; +} + +int +client_post_fsyncdir(xlator_t *this, gf_common_rsp *rsp, dict_t **xdata) +{ + int ret = 0; + + GF_PROTOCOL_DICT_UNSERIALIZE(this, *xdata, (rsp->xdata.xdata_val), + (rsp->xdata.xdata_len), ret, rsp->op_errno, + out); +out: + return ret; +} + +int +client_post_access(xlator_t *this, gf_common_rsp *rsp, dict_t **xdata) +{ + int ret = 0; + + GF_PROTOCOL_DICT_UNSERIALIZE(this, *xdata, (rsp->xdata.xdata_val), + (rsp->xdata.xdata_len), ret, rsp->op_errno, + out); +out: + return ret; +} + +int +client_post_create(xlator_t *this, gfs3_create_rsp *rsp, struct iatt *stbuf, + struct iatt *preparent, struct iatt *postparent, + clnt_local_t *local, dict_t **xdata) +{ + int ret = 0; + + if (-1 != rsp->op_ret) { + gf_stat_to_iatt(&rsp->stat, stbuf); + + gf_stat_to_iatt(&rsp->preparent, preparent); + gf_stat_to_iatt(&rsp->postparent, postparent); + gf_uuid_copy(local->loc.gfid, stbuf->ia_gfid); + } + GF_PROTOCOL_DICT_UNSERIALIZE(this, *xdata, (rsp->xdata.xdata_val), + (rsp->xdata.xdata_len), ret, rsp->op_errno, + out); +out: + return ret; +} + +int +client_post_ftruncate(xlator_t *this, gfs3_ftruncate_rsp *rsp, + struct iatt *prestat, struct iatt *poststat, + dict_t **xdata) +{ + int ret = 0; + + if (-1 != rsp->op_ret) { + gf_stat_to_iatt(&rsp->prestat, prestat); + gf_stat_to_iatt(&rsp->poststat, poststat); + } + GF_PROTOCOL_DICT_UNSERIALIZE(this, *xdata, (rsp->xdata.xdata_val), + (rsp->xdata.xdata_len), ret, rsp->op_errno, + out); +out: + return ret; +} + +int +client_post_fstat(xlator_t *this, gfs3_fstat_rsp *rsp, struct iatt *stat, + dict_t **xdata) +{ + int ret = 0; + + if (-1 != rsp->op_ret) { + gf_stat_to_iatt(&rsp->stat, stat); + } + GF_PROTOCOL_DICT_UNSERIALIZE(this, *xdata, (rsp->xdata.xdata_val), + (rsp->xdata.xdata_len), ret, rsp->op_errno, + out); +out: + return -ret; +} + +int +client_post_lk(xlator_t *this, gfs3_lk_rsp *rsp, struct gf_flock *lock, + dict_t **xdata) +{ + int ret = 0; + + if (rsp->op_ret >= 0) { + gf_proto_flock_to_flock(&rsp->flock, lock); + } + GF_PROTOCOL_DICT_UNSERIALIZE(this, *xdata, (rsp->xdata.xdata_val), + (rsp->xdata.xdata_len), ret, rsp->op_errno, + out); +out: + return ret; +} + +int +client_post_lookup(xlator_t *this, gfs3_lookup_rsp *rsp, struct iatt *stbuf, + struct iatt *postparent, dict_t **xdata) +{ + int ret = 0; + + if (-1 != rsp->op_ret) { + gf_stat_to_iatt(&rsp->postparent, postparent); + 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: + return ret; +} + +int +client_post_readdir(xlator_t *this, gfs3_readdir_rsp *rsp, gf_dirent_t *entries, + dict_t **xdata) +{ + int ret = 0; + + if (rsp->op_ret > 0) { + unserialize_rsp_dirent(this, rsp, entries); + } + GF_PROTOCOL_DICT_UNSERIALIZE(this, *xdata, (rsp->xdata.xdata_val), + (rsp->xdata.xdata_len), ret, rsp->op_errno, + out); + +out: + return ret; +} + +int +client_post_inodelk(xlator_t *this, gf_common_rsp *rsp, dict_t **xdata) +{ + int ret = 0; + + GF_PROTOCOL_DICT_UNSERIALIZE(this, *xdata, (rsp->xdata.xdata_val), + (rsp->xdata.xdata_len), ret, rsp->op_errno, + out); + +out: + return ret; +} + +int +client_post_finodelk(xlator_t *this, gf_common_rsp *rsp, dict_t **xdata) +{ + int ret = 0; + + GF_PROTOCOL_DICT_UNSERIALIZE(this, *xdata, (rsp->xdata.xdata_val), + (rsp->xdata.xdata_len), ret, rsp->op_errno, + out); + +out: + return ret; +} + +int +client_post_entrylk(xlator_t *this, gf_common_rsp *rsp, dict_t **xdata) +{ + int ret = 0; + + GF_PROTOCOL_DICT_UNSERIALIZE(this, *xdata, (rsp->xdata.xdata_val), + (rsp->xdata.xdata_len), ret, rsp->op_errno, + out); + +out: + return ret; +} + +int +client_post_fentrylk(xlator_t *this, gf_common_rsp *rsp, dict_t **xdata) +{ + int ret = 0; + + GF_PROTOCOL_DICT_UNSERIALIZE(this, *xdata, (rsp->xdata.xdata_val), + (rsp->xdata.xdata_len), ret, rsp->op_errno, + out); + +out: + return ret; +} + +int +client_post_xattrop(xlator_t *this, gfs3_xattrop_rsp *rsp, dict_t **dict, + dict_t **xdata) +{ + int op_errno = 0; + int ret = 0; + + if (-1 != rsp->op_ret) { + GF_PROTOCOL_DICT_UNSERIALIZE(this, *dict, (rsp->dict.dict_val), + (rsp->dict.dict_len), rsp->op_ret, + op_errno, out); + } + GF_PROTOCOL_DICT_UNSERIALIZE(this, *xdata, (rsp->xdata.xdata_val), + (rsp->xdata.xdata_len), ret, op_errno, out); + +out: + return -op_errno; +} + +int +client_post_fxattrop(xlator_t *this, gfs3_fxattrop_rsp *rsp, dict_t **dict, + dict_t **xdata) +{ + int op_errno = 0; + int ret = 0; + + if (-1 != rsp->op_ret) { + GF_PROTOCOL_DICT_UNSERIALIZE(this, *dict, (rsp->dict.dict_val), + (rsp->dict.dict_len), rsp->op_ret, + op_errno, out); + } + GF_PROTOCOL_DICT_UNSERIALIZE(this, *xdata, (rsp->xdata.xdata_val), + (rsp->xdata.xdata_len), ret, op_errno, out); + +out: + return -op_errno; +} + +int +client_post_fgetxattr(xlator_t *this, gfs3_fgetxattr_rsp *rsp, dict_t **dict, + dict_t **xdata) +{ + int op_errno = 0; + int ret = 0; + + if (-1 != rsp->op_ret) { + GF_PROTOCOL_DICT_UNSERIALIZE(this, *dict, (rsp->dict.dict_val), + (rsp->dict.dict_len), rsp->op_ret, + op_errno, out); + } + GF_PROTOCOL_DICT_UNSERIALIZE(this, *xdata, (rsp->xdata.xdata_val), + (rsp->xdata.xdata_len), ret, op_errno, out); + +out: + return -op_errno; +} + +int +client_post_fsetxattr(xlator_t *this, gf_common_rsp *rsp, dict_t **xdata) +{ + int ret = 0; + + GF_PROTOCOL_DICT_UNSERIALIZE(this, *xdata, (rsp->xdata.xdata_val), + (rsp->xdata.xdata_len), ret, rsp->op_errno, + out); + + ret = gf_replace_new_iatt_in_dict(*xdata); +out: + return ret; +} + +int +client_post_rchecksum(xlator_t *this, gfs3_rchecksum_rsp *rsp, dict_t **xdata) +{ + int ret = 0; + + GF_PROTOCOL_DICT_UNSERIALIZE(this, *xdata, (rsp->xdata.xdata_val), + (rsp->xdata.xdata_len), ret, rsp->op_errno, + out); +out: + return ret; +} + +int +client_post_setattr(xlator_t *this, gfs3_setattr_rsp *rsp, struct iatt *prestat, + struct iatt *poststat, dict_t **xdata) +{ + int ret = 0; + + if (-1 != rsp->op_ret) { + gf_stat_to_iatt(&rsp->statpre, prestat); + gf_stat_to_iatt(&rsp->statpost, poststat); + } + GF_PROTOCOL_DICT_UNSERIALIZE(this, *xdata, (rsp->xdata.xdata_val), + (rsp->xdata.xdata_len), ret, rsp->op_errno, + out); +out: + return ret; +} + +int +client_post_fsetattr(xlator_t *this, gfs3_fsetattr_rsp *rsp, + struct iatt *prestat, struct iatt *poststat, + dict_t **xdata) +{ + int ret = 0; + + if (-1 != rsp->op_ret) { + gf_stat_to_iatt(&rsp->statpre, prestat); + gf_stat_to_iatt(&rsp->statpost, poststat); + } + GF_PROTOCOL_DICT_UNSERIALIZE(this, *xdata, (rsp->xdata.xdata_val), + (rsp->xdata.xdata_len), ret, rsp->op_errno, + out); +out: + return ret; +} + +int +client_post_readdirp(xlator_t *this, gfs3_readdirp_rsp *rsp, fd_t *fd, + gf_dirent_t *entries, dict_t **xdata) +{ + int ret = 0; + + if (rsp->op_ret > 0) { + unserialize_rsp_direntp(this, fd, rsp, entries); + } + + GF_PROTOCOL_DICT_UNSERIALIZE(this, *xdata, (rsp->xdata.xdata_val), + (rsp->xdata.xdata_len), ret, rsp->op_errno, + out); +out: + return ret; +} + +int +client_post_fremovexattr(xlator_t *this, gf_common_rsp *rsp, dict_t **xdata) +{ + int ret = 0; + + GF_PROTOCOL_DICT_UNSERIALIZE(this, *xdata, (rsp->xdata.xdata_val), + (rsp->xdata.xdata_len), ret, rsp->op_errno, + out); + + ret = gf_replace_new_iatt_in_dict(*xdata); +out: + return ret; +} + +int +client_post_fallocate(xlator_t *this, gfs3_fallocate_rsp *rsp, + struct iatt *prestat, struct iatt *poststat, + dict_t **xdata) +{ + int ret = 0; + + if (-1 != rsp->op_ret) { + gf_stat_to_iatt(&rsp->statpre, prestat); + gf_stat_to_iatt(&rsp->statpost, poststat); + } + GF_PROTOCOL_DICT_UNSERIALIZE(this, *xdata, (rsp->xdata.xdata_val), + (rsp->xdata.xdata_len), ret, rsp->op_errno, + out); +out: + return ret; +} + +int +client_post_discard(xlator_t *this, gfs3_discard_rsp *rsp, struct iatt *prestat, + struct iatt *poststat, dict_t **xdata) +{ + int ret = 0; + + if (-1 != rsp->op_ret) { + gf_stat_to_iatt(&rsp->statpre, prestat); + gf_stat_to_iatt(&rsp->statpost, poststat); + } + GF_PROTOCOL_DICT_UNSERIALIZE(this, *xdata, (rsp->xdata.xdata_val), + (rsp->xdata.xdata_len), ret, rsp->op_errno, + out); +out: + return ret; +} + +int +client_post_zerofill(xlator_t *this, gfs3_zerofill_rsp *rsp, + struct iatt *prestat, struct iatt *poststat, + dict_t **xdata) +{ + int ret = 0; + + if (-1 != rsp->op_ret) { + gf_stat_to_iatt(&rsp->statpre, prestat); + gf_stat_to_iatt(&rsp->statpost, poststat); + } + GF_PROTOCOL_DICT_UNSERIALIZE(this, *xdata, (rsp->xdata.xdata_val), + (rsp->xdata.xdata_len), ret, rsp->op_errno, + out); +out: + return ret; +} + +int +client_post_ipc(xlator_t *this, gfs3_ipc_rsp *rsp, dict_t **xdata) +{ + int ret = 0; + + GF_PROTOCOL_DICT_UNSERIALIZE(this, *xdata, (rsp->xdata.xdata_val), + (rsp->xdata.xdata_len), ret, rsp->op_errno, + out); +out: + return ret; +} + +int +client_post_seek(xlator_t *this, gfs3_seek_rsp *rsp, dict_t **xdata) +{ + int ret = 0; + + GF_PROTOCOL_DICT_UNSERIALIZE(this, *xdata, (rsp->xdata.xdata_val), + (rsp->xdata.xdata_len), ret, rsp->op_errno, + out); +out: + return ret; +} + +int +client_post_lease(xlator_t *this, gfs3_lease_rsp *rsp, struct gf_lease *lease, + dict_t **xdata) +{ + int ret = 0; + + if (rsp->op_ret >= 0) { + gf_proto_lease_to_lease(&rsp->lease, lease); + } + + GF_PROTOCOL_DICT_UNSERIALIZE(this, *xdata, (rsp->xdata.xdata_val), + (rsp->xdata.xdata_len), ret, rsp->op_errno, + out); +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_copy_file_range_v2(xlator_t *this, gfx_copy_file_range_req *req, + fd_t *fd_in, off64_t off_in, fd_t *fd_out, + off64_t off_out, size_t size, int32_t flags, + dict_t **xdata) +{ + int64_t remote_fd_in = -1; + int64_t remote_fd_out = -1; + int op_errno = ESTALE; + + CLIENT_GET_REMOTE_FD(this, fd_in, FALLBACK_TO_ANON_FD, remote_fd_in, + op_errno, out); + + CLIENT_GET_REMOTE_FD(this, fd_out, FALLBACK_TO_ANON_FD, remote_fd_out, + op_errno, out); + req->size = size; + req->off_in = off_in; + req->off_out = off_out; + req->fd_in = remote_fd_in; + req->fd_out = remote_fd_out; + req->flag = flags; + + memcpy(req->gfid1, fd_in->inode->gfid, 16); + memcpy(req->gfid2, fd_out->inode->gfid, 16); + + 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, FALLBACK_TO_ANON_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_smsg(this->name, GF_LOG_WARNING, EINVAL, PC_MSG_UNKNOWN_CMD, + "gf_cmd=%d", gf_cmd, NULL); + 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_smsg(this->name, GF_LOG_WARNING, EINVAL, PC_MSG_UNKNOWN_CMD, + "gf_cmd=%d", gf_cmd, NULL); + 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_smsg(this->name, GF_LOG_WARNING, EINVAL, PC_MSG_UNKNOWN_CMD, + "gf_cmd=%d", gf_cmd, NULL); + 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_pre_put_v2(xlator_t *this, gfx_put_req *req, loc_t *loc, mode_t mode, + mode_t umask, int32_t flags, size_t size, off_t offset, + dict_t *xattr, 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; + req->flag = gf_flags_from_flags(flags); + req->size = size; + req->offset = offset; + + if (xattr) + dict_to_xdr(xattr, &req->xattr); + + dict_to_xdr(xdata, &req->xdata); + + return 0; +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 new file mode 100644 index 00000000000..a2043d8742a --- /dev/null +++ b/xlators/protocol/client/src/client-common.h @@ -0,0 +1,630 @@ +/* + Copyright (c); 2016 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. +*/ + +#ifndef __CLIENT_COMMON_H__ +#define __CLIENT_COMMON_H__ + +#include <glusterfs/dict.h> +#include <glusterfs/xlator.h> +#include "rpc-common-xdr.h" +#include "glusterfs3-xdr.h" +#include "glusterfs4-xdr.h" +#include "glusterfs3.h" +#include "client.h" + +int +client_pre_stat(xlator_t *this, gfs3_stat_req *req, loc_t *loc, dict_t *xdata); + +int +client_pre_readlink(xlator_t *this, gfs3_readlink_req *req, loc_t *loc, + size_t size, dict_t *xdata); + +int +client_pre_mknod(xlator_t *this, gfs3_mknod_req *req, loc_t *loc, mode_t mode, + dev_t rdev, mode_t umask, dict_t *xdata); + +int +client_pre_mkdir(xlator_t *this, gfs3_mkdir_req *req, loc_t *loc, mode_t mode, + mode_t umask, dict_t *xdata); + +int +client_pre_unlink(xlator_t *this, gfs3_unlink_req *req, loc_t *loc, + int32_t flags, dict_t *xdata); + +int +client_pre_rmdir(xlator_t *this, gfs3_rmdir_req *req, loc_t *loc, int32_t flags, + dict_t *xdata); + +int +client_pre_symlink(xlator_t *this, gfs3_symlink_req *req, loc_t *loc, + const char *linkname, mode_t umask, dict_t *xdata); + +int +client_pre_rename(xlator_t *this, gfs3_rename_req *req, loc_t *oldloc, + loc_t *newloc, dict_t *xdata); + +int +client_pre_link(xlator_t *this, gfs3_link_req *req, loc_t *oldloc, + loc_t *newloc, dict_t *xdata); + +int +client_pre_truncate(xlator_t *this, gfs3_truncate_req *req, loc_t *loc, + off_t offset, dict_t *xdata); + +int +client_pre_open(xlator_t *this, gfs3_open_req *req, loc_t *loc, fd_t *fd, + int32_t flags, dict_t *xdata); + +int +client_pre_readv(xlator_t *this, gfs3_read_req *req, fd_t *fd, size_t size, + off_t offset, int32_t flags, dict_t *xdata); + +int +client_pre_writev(xlator_t *this, gfs3_write_req *req, fd_t *fd, size_t size, + off_t offset, int32_t flags, dict_t **xdata); + +int +client_pre_statfs(xlator_t *this, gfs3_statfs_req *req, loc_t *loc, + dict_t *xdata); + +int +client_pre_flush(xlator_t *this, gfs3_flush_req *req, fd_t *fd, dict_t *xdata); + +int +client_pre_fsync(xlator_t *this, gfs3_fsync_req *req, fd_t *fd, int32_t flags, + dict_t *xdata); + +int +client_pre_setxattr(xlator_t *this, gfs3_setxattr_req *req, loc_t *loc, + dict_t *xattr, int32_t flags, dict_t *xdata); + +int +client_pre_getxattr(xlator_t *this, gfs3_getxattr_req *req, loc_t *loc, + const char *name, dict_t *xdata); + +int +client_pre_removexattr(xlator_t *this, gfs3_removexattr_req *req, loc_t *loc, + const char *name, dict_t *xdata); + +int +client_pre_opendir(xlator_t *this, gfs3_opendir_req *req, loc_t *loc, fd_t *fd, + dict_t *xdata); + +int +client_pre_fsyncdir(xlator_t *this, gfs3_fsyncdir_req *req, fd_t *fd, + int32_t flags, dict_t *xdata); + +int +client_pre_access(xlator_t *this, gfs3_access_req *req, loc_t *loc, + int32_t mask, dict_t *xdata); + +int +client_pre_create(xlator_t *this, gfs3_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(xlator_t *this, gfs3_ftruncate_req *req, fd_t *fd, + off_t offset, dict_t *xdata); + +int +client_pre_fstat(xlator_t *this, gfs3_fstat_req *req, fd_t *fd, dict_t *xdata); + +int +client_pre_lk(xlator_t *this, gfs3_lk_req *req, int32_t cmd, + struct gf_flock *flock, fd_t *fd, dict_t *xdata); + +int +client_pre_lookup(xlator_t *this, gfs3_lookup_req *req, loc_t *loc, + dict_t *xdata); + +int +client_pre_readdir(xlator_t *this, gfs3_readdir_req *req, fd_t *fd, size_t size, + off_t offset, dict_t *xdata); + +int +client_pre_inodelk(xlator_t *this, gfs3_inodelk_req *req, loc_t *loc, int cmd, + struct gf_flock *flock, const char *volume, dict_t *xdata); + +int +client_pre_finodelk(xlator_t *this, gfs3_finodelk_req *req, fd_t *fd, int cmd, + struct gf_flock *flock, const char *volume, dict_t *xdata); + +int +client_pre_entrylk(xlator_t *this, gfs3_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(xlator_t *this, gfs3_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(xlator_t *this, gfs3_xattrop_req *req, loc_t *loc, + dict_t *xattr, int32_t flags, dict_t *xdata); + +int +client_pre_fxattrop(xlator_t *this, gfs3_fxattrop_req *req, fd_t *fd, + dict_t *xattr, int32_t flags, dict_t *xdata); + +int +client_pre_fgetxattr(xlator_t *this, gfs3_fgetxattr_req *req, fd_t *fd, + const char *name, dict_t *xdata); + +int +client_pre_fsetxattr(xlator_t *this, gfs3_fsetxattr_req *req, fd_t *fd, + int32_t flags, dict_t *xattr, dict_t *xdata); +int +client_pre_seek(xlator_t *this, gfs3_seek_req *req, fd_t *fd, off_t offset, + gf_seek_what_t what, dict_t *xdata); + +int +client_pre_rchecksum(xlator_t *this, gfs3_rchecksum_req *req, fd_t *fd, + int32_t len, off_t offset, dict_t *xdata); + +int +client_pre_setattr(xlator_t *this, gfs3_setattr_req *req, loc_t *loc, + int32_t valid, struct iatt *stbuf, dict_t *xdata); +int +client_pre_fsetattr(xlator_t *this, gfs3_fsetattr_req *req, fd_t *fd, + int32_t valid, struct iatt *stbuf, dict_t *xdata); + +int +client_pre_readdirp(xlator_t *this, gfs3_readdirp_req *req, fd_t *fd, + size_t size, off_t offset, dict_t *xdata); + +int +client_pre_fremovexattr(xlator_t *this, gfs3_fremovexattr_req *req, fd_t *fd, + const char *name, dict_t *xdata); + +int +client_pre_fallocate(xlator_t *this, gfs3_fallocate_req *req, fd_t *fd, + int32_t flags, off_t offset, size_t size, dict_t *xdata); +int +client_pre_discard(xlator_t *this, gfs3_discard_req *req, fd_t *fd, + off_t offset, size_t size, dict_t *xdata); +int +client_pre_zerofill(xlator_t *this, gfs3_zerofill_req *req, fd_t *fd, + off_t offset, size_t size, dict_t *xdata); +int +client_pre_ipc(xlator_t *this, gfs3_ipc_req *req, int32_t cmd, dict_t *xdata); + +int +client_pre_lease(xlator_t *this, gfs3_lease_req *req, loc_t *loc, + struct gf_lease *lease, dict_t *xdata); + +int +client_post_stat(xlator_t *this, gfs3_stat_rsp *rsp, struct iatt *iatt, + dict_t **xdata); + +int +client_post_readlink(xlator_t *this, gfs3_readlink_rsp *rsp, struct iatt *iatt, + dict_t **xdata); + +int +client_post_mknod(xlator_t *this, gfs3_mknod_rsp *rsp, struct iatt *stbuf, + struct iatt *preparent, struct iatt *postparent, + dict_t **xdata); + +int +client_post_mkdir(xlator_t *this, gfs3_mkdir_rsp *rsp, struct iatt *stbuf, + struct iatt *preparent, struct iatt *postparent, + dict_t **xdata); + +int +client_post_unlink(xlator_t *this, gfs3_unlink_rsp *rsp, struct iatt *preparent, + struct iatt *postparent, dict_t **xdata); + +int +client_post_rmdir(xlator_t *this, gfs3_rmdir_rsp *rsp, struct iatt *preparent, + struct iatt *postparent, dict_t **xdata); + +int +client_post_symlink(xlator_t *this, gfs3_symlink_rsp *rsp, struct iatt *stbuf, + struct iatt *preparent, struct iatt *postparent, + dict_t **xdata); + +int +client_post_rename(xlator_t *this, gfs3_rename_rsp *rsp, struct iatt *stbuf, + struct iatt *preoldparent, struct iatt *postoldparent, + struct iatt *prenewparent, struct iatt *postnewparent, + dict_t **xdata); +int +client_post_link(xlator_t *this, gfs3_link_rsp *rsp, struct iatt *stbuf, + struct iatt *preparent, struct iatt *postparent, + dict_t **xdata); + +int +client_post_truncate(xlator_t *this, gfs3_truncate_rsp *rsp, + struct iatt *prestat, struct iatt *poststat, + dict_t **xdata); + +int +client_post_open(xlator_t *this, gfs3_open_rsp *rsp, dict_t **xdata); + +int +client_post_readv(xlator_t *this, gfs3_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_writev(xlator_t *this, gfs3_write_rsp *rsp, struct iatt *prestat, + struct iatt *poststat, dict_t **xdata); + +int +client_post_statfs(xlator_t *this, gfs3_statfs_rsp *rsp, struct statvfs *statfs, + dict_t **xdata); + +int +client_post_flush(xlator_t *this, gf_common_rsp *rsp, dict_t **xdata); + +int +client_post_fsync(xlator_t *this, gfs3_fsync_rsp *rsp, struct iatt *prestat, + struct iatt *poststat, dict_t **xdata); +int +client_post_setxattr(xlator_t *this, gf_common_rsp *rsp, dict_t **xdata); + +int +client_post_getxattr(xlator_t *this, gfs3_getxattr_rsp *rsp, dict_t **dict, + dict_t **xdata); + +int +client_post_removexattr(xlator_t *this, gf_common_rsp *rsp, dict_t **xdata); + +int +client_post_opendir(xlator_t *this, gfs3_opendir_rsp *rsp, dict_t **xdata); + +int +client_post_fsyncdir(xlator_t *this, gf_common_rsp *rsp, dict_t **xdata); + +int +client_post_access(xlator_t *this, gf_common_rsp *rsp, dict_t **xdata); + +int +client_post_create(xlator_t *this, gfs3_create_rsp *rsp, struct iatt *stbuf, + struct iatt *preparent, struct iatt *postparent, + clnt_local_t *local, dict_t **xdata); + +int +client_post_ftruncate(xlator_t *this, gfs3_ftruncate_rsp *rsp, + struct iatt *prestat, struct iatt *poststat, + dict_t **xdata); + +int +client_post_fstat(xlator_t *this, gfs3_fstat_rsp *rsp, struct iatt *stat, + dict_t **xdata); + +int +client_post_lk(xlator_t *this, gfs3_lk_rsp *rsp, struct gf_flock *lock, + dict_t **xdata); + +int +client_post_lookup(xlator_t *this, gfs3_lookup_rsp *rsp, struct iatt *stbuf, + struct iatt *postparent, dict_t **xdata); + +int +client_post_readdir(xlator_t *this, gfs3_readdir_rsp *rsp, gf_dirent_t *entries, + dict_t **xdata); + +int +client_post_inodelk(xlator_t *this, gf_common_rsp *rsp, dict_t **xdata); + +int +client_post_finodelk(xlator_t *this, gf_common_rsp *rsp, dict_t **xdata); + +int +client_post_entrylk(xlator_t *this, gf_common_rsp *rsp, dict_t **xdata); + +int +client_post_fentrylk(xlator_t *this, gf_common_rsp *rsp, dict_t **xdata); + +int +client_post_xattrop(xlator_t *this, gfs3_xattrop_rsp *rsp, dict_t **dict, + dict_t **xdata); + +int +client_post_fxattrop(xlator_t *this, gfs3_fxattrop_rsp *rsp, dict_t **dict, + dict_t **xdata); + +int +client_post_fgetxattr(xlator_t *this, gfs3_fgetxattr_rsp *rsp, dict_t **dict, + dict_t **xdata); + +int +client_post_fsetxattr(xlator_t *this, gf_common_rsp *rsp, dict_t **xdata); + +int +client_post_rchecksum(xlator_t *this, gfs3_rchecksum_rsp *rsp, dict_t **xdata); + +int +client_post_setattr(xlator_t *this, gfs3_setattr_rsp *rsp, struct iatt *prestat, + struct iatt *poststat, dict_t **xdata); + +int +client_post_fsetattr(xlator_t *this, gfs3_fsetattr_rsp *rsp, + struct iatt *prestat, struct iatt *poststat, + dict_t **xdata); + +int +client_post_readdirp(xlator_t *this, gfs3_readdirp_rsp *rsp, fd_t *fd, + gf_dirent_t *entries, dict_t **xdata); + +int +client_post_fremovexattr(xlator_t *this, gf_common_rsp *rsp, dict_t **xdata); + +int +client_post_fallocate(xlator_t *this, gfs3_fallocate_rsp *rsp, + struct iatt *prestat, struct iatt *poststat, + dict_t **xdata); + +int +client_post_discard(xlator_t *this, gfs3_discard_rsp *rsp, struct iatt *prestat, + struct iatt *poststat, dict_t **xdata); + +int +client_post_zerofill(xlator_t *this, gfs3_zerofill_rsp *rsp, + struct iatt *prestat, struct iatt *poststat, + dict_t **xdata); + +int +client_post_ipc(xlator_t *this, gfs3_ipc_rsp *rsp, dict_t **xdata); + +int +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_pre_put_v2(xlator_t *this, gfx_put_req *req, loc_t *loc, mode_t mode, + mode_t umask, int32_t flags, size_t size, off_t offset, + dict_t *xattr, 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); + +int +client_pre_copy_file_range_v2(xlator_t *this, gfx_copy_file_range_req *req, + fd_t *fd_in, off64_t off_in, fd_t *fd_out, + off64_t off_out, size_t size, int32_t flags, + dict_t **xdata); + +#endif /* __CLIENT_COMMON_H__ */ diff --git a/xlators/protocol/client/src/client-handshake.c b/xlators/protocol/client/src/client-handshake.c index 48f19861b0e..ea5ef5c1800 100644 --- a/xlators/protocol/client/src/client-handshake.c +++ b/xlators/protocol/client/src/client-handshake.c @@ -1,915 +1,1415 @@ /* - Copyright (c) 2010 Gluster, Inc. <http://www.gluster.com> + Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.com> This file is part of GlusterFS. - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. + 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. */ -#ifndef _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif - +#include <glusterfs/fd-lk.h> #include "client.h" -#include "xlator.h" -#include "defaults.h" -#include "glusterfs.h" -#include "statedump.h" -#include "compat-errno.h" +#include <glusterfs/xlator.h> +#include <glusterfs/defaults.h> +#include <glusterfs/glusterfs.h> +#include <glusterfs/statedump.h> +#include <glusterfs/compat-errno.h> #include "glusterfs3.h" -#include "portmap.h" - -extern rpc_clnt_prog_t clnt3_1_fop_prog; +#include "portmap-xdr.h" +#include "rpc-common-xdr.h" +#include "client-messages.h" +#include "xdr-rpc.h" + +#define CLIENT_REOPEN_MAX_ATTEMPTS 1024 +extern rpc_clnt_prog_t clnt3_3_fop_prog; +extern rpc_clnt_prog_t clnt4_0_fop_prog; extern rpc_clnt_prog_t clnt_pmap_prog; -int client_ping_cbk (struct rpc_req *req, struct iovec *iov, int count, - void *myframe); +int32_t +client3_getspec(call_frame_t *frame, xlator_t *this, void *data) +{ + CLIENT_STACK_UNWIND(getspec, frame, -1, ENOSYS, NULL); + return 0; +} + +static int +client_notify_parents_child_up(xlator_t *this) +{ + clnt_conf_t *conf = NULL; + int ret = 0; + + GF_VALIDATE_OR_GOTO("client", this, out); + conf = this->private; + GF_VALIDATE_OR_GOTO(this->name, conf, out); -/* Handshake */ + if (conf->child_up) { + ret = client_notify_dispatch_uniq(this, GF_EVENT_CHILD_UP, NULL); + if (ret) { + gf_smsg(this->name, GF_LOG_INFO, 0, PC_MSG_CHILD_UP_NOTIFY_FAILED, + NULL); + goto out; + } + } else { + gf_smsg(this->name, GF_LOG_INFO, 0, PC_MSG_CHILD_STATUS, NULL); + } + +out: + return 0; +} void -rpc_client_ping_timer_expired (void *data) +client_default_reopen_done(clnt_fd_ctx_t *fdctx, int64_t rfd, xlator_t *this) { - rpc_transport_t *trans = NULL; - rpc_clnt_connection_t *conn = NULL; - int disconnect = 0; - int transport_activity = 0; - struct timeval timeout = {0, }; - struct timeval current = {0, }; - struct rpc_clnt *clnt = NULL; - xlator_t *this = NULL; - clnt_conf_t *conf = NULL; - - if (!data) { - goto out; - } + gf_log_callingfn(this->name, GF_LOG_WARNING, + "This function should never be called"); +} - this = data; - conf = this->private; +static void +client_reopen_done(clnt_fd_ctx_t *fdctx, int64_t rfd, xlator_t *this) +{ + clnt_conf_t *conf = this->private; + gf_boolean_t destroy = _gf_false; + + pthread_spin_lock(&conf->fd_lock); + { + fdctx->remote_fd = rfd; + fdctx->reopen_attempts = 0; + fdctx->reopen_done = client_default_reopen_done; + if (!fdctx->released) + list_add_tail(&fdctx->sfd_pos, &conf->saved_fds); + else + destroy = _gf_true; + } + pthread_spin_unlock(&conf->fd_lock); + + if (destroy) + client_fdctx_destroy(this, fdctx); +} - conn = &conf->rpc->conn; - trans = conn->trans; +static void +client_child_up_reopen_done(clnt_fd_ctx_t *fdctx, int64_t rfd, xlator_t *this) +{ + clnt_conf_t *conf = this->private; + uint64_t fd_count = 0; + + LOCK(&conf->rec_lock); + { + fd_count = --(conf->reopen_fd_count); + } + UNLOCK(&conf->rec_lock); + + client_reopen_done(fdctx, rfd, this); + if (fd_count == 0) { + gf_smsg(this->name, GF_LOG_INFO, 0, PC_MSG_CHILD_UP_NOTIFY, NULL); + client_notify_parents_child_up(this); + } +} - if (!clnt || !trans) { - goto out; - } +int +client3_3_reopen_cbk(struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + int32_t ret = -1; + gfs3_open_rsp rsp = { + 0, + }; + call_frame_t *frame = myframe; + xlator_t *this = frame->this; + clnt_local_t *local = frame->local; + clnt_fd_ctx_t *fdctx = local->fdctx; + + if (-1 == req->rpc_status) { + gf_smsg(frame->this->name, GF_LOG_WARNING, ENOTCONN, + PC_MSG_RPC_STATUS_ERROR, NULL); + rsp.op_ret = -1; + rsp.op_errno = ENOTCONN; + goto out; + } + + ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gfs3_open_rsp); + if (ret < 0) { + gf_smsg(frame->this->name, GF_LOG_ERROR, EINVAL, + PC_MSG_XDR_DECODING_FAILED, NULL); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + if (rsp.op_ret < 0) { + gf_smsg(frame->this->name, GF_LOG_WARNING, rsp.op_errno, + PC_MSG_REOPEN_FAILED, "path=%s", local->loc.path); + } else { + gf_msg_debug(frame->this->name, 0, + "reopen on %s succeeded (remote-fd = %" PRId64 ")", + local->loc.path, rsp.fd); + } + + if (rsp.op_ret == -1) { + goto out; + } - pthread_mutex_lock (&conn->lock); - { - if (conn->ping_timer) - gf_timer_call_cancel (this->ctx, - conn->ping_timer); - gettimeofday (¤t, NULL); - - if (((current.tv_sec - conn->last_received.tv_sec) < - conf->opt.ping_timeout) - || ((current.tv_sec - conn->last_sent.tv_sec) < - conf->opt.ping_timeout)) { - transport_activity = 1; - } - - if (transport_activity) { - gf_log (trans->name, GF_LOG_TRACE, - "ping timer expired but transport activity " - "detected - not bailing transport"); - timeout.tv_sec = conf->opt.ping_timeout; - timeout.tv_usec = 0; - - conn->ping_timer = - gf_timer_call_after (this->ctx, timeout, - rpc_client_ping_timer_expired, - (void *) this); - if (conn->ping_timer == NULL) - gf_log (trans->name, GF_LOG_DEBUG, - "unable to setup timer"); - - } else { - conn->ping_started = 0; - conn->ping_timer = NULL; - disconnect = 1; - } - } - pthread_mutex_unlock (&conn->lock); +out: + fdctx->reopen_done(fdctx, (rsp.op_ret) ? -1 : rsp.fd, this); - if (disconnect) { - gf_log (trans->name, GF_LOG_ERROR, - "Server %s has not responded in the last %d " - "seconds, disconnecting.", - conn->trans->peerinfo.identifier, - conf->opt.ping_timeout); + frame->local = NULL; + STACK_DESTROY(frame->root); - rpc_transport_disconnect (conn->trans); - } + client_local_wipe(local); -out: - return; + return 0; } -void -client_start_ping (void *data) +int +client3_3_reopendir_cbk(struct rpc_req *req, struct iovec *iov, int count, + void *myframe) { - xlator_t *this = NULL; - clnt_conf_t *conf = NULL; - rpc_clnt_connection_t *conn = NULL; - int32_t ret = -1; - struct timeval timeout = {0, }; - call_frame_t *frame = NULL; - int frame_count = 0; + int32_t ret = -1; + gfs3_open_rsp rsp = { + 0, + }; + call_frame_t *frame = myframe; + clnt_local_t *local = frame->local; + clnt_fd_ctx_t *fdctx = local->fdctx; + + if (-1 == req->rpc_status) { + gf_smsg(frame->this->name, GF_LOG_WARNING, ENOTCONN, + PC_MSG_RPC_STATUS_ERROR, NULL); + rsp.op_ret = -1; + rsp.op_errno = ENOTCONN; + goto out; + } + + ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gfs3_opendir_rsp); + if (ret < 0) { + gf_smsg(frame->this->name, GF_LOG_ERROR, EINVAL, + PC_MSG_XDR_DECODING_FAILED, NULL); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + if (rsp.op_ret < 0) { + gf_smsg(frame->this->name, GF_LOG_WARNING, rsp.op_errno, + PC_MSG_REOPEN_FAILED, "path=%s", local->loc.path, NULL); + } else { + gf_smsg(frame->this->name, GF_LOG_INFO, 0, PC_MSG_DIR_OP_SUCCESS, + "path=%s", local->loc.path, "fd=%" PRId64, rsp.fd, NULL); + } + + if (-1 == rsp.op_ret) { + goto out; + } - this = data; - conf = this->private; +out: + fdctx->reopen_done(fdctx, (rsp.op_ret) ? -1 : rsp.fd, frame->this); - conn = &conf->rpc->conn; + frame->local = NULL; + STACK_DESTROY(frame->root); + client_local_wipe(local); - if (conf->opt.ping_timeout == 0) - return; + return 0; +} - pthread_mutex_lock (&conn->lock); +static int +protocol_client_reopendir(clnt_fd_ctx_t *fdctx, xlator_t *this) +{ + int ret = -1; + gfs3_opendir_req req = { { - if (conn->ping_timer) - gf_timer_call_cancel (this->ctx, conn->ping_timer); - - conn->ping_timer = NULL; - conn->ping_started = 0; - - if (conn->saved_frames) - /* treat the case where conn->saved_frames is NULL - as no pending frames */ - frame_count = conn->saved_frames->count; - - if ((frame_count == 0) || !conn->connected) { - /* using goto looked ugly here, - * hence getting out this way */ - /* unlock */ - pthread_mutex_unlock (&conn->lock); - return; - } - - if (frame_count < 0) { - gf_log (this->name, GF_LOG_DEBUG, - "saved_frames->count is %"PRId64, - conn->saved_frames->count); - conn->saved_frames->count = 0; - } - - timeout.tv_sec = conf->opt.ping_timeout; - timeout.tv_usec = 0; - - conn->ping_timer = - gf_timer_call_after (this->ctx, timeout, - rpc_client_ping_timer_expired, - (void *) this); - - if (conn->ping_timer == NULL) { - gf_log (this->name, GF_LOG_DEBUG, - "unable to setup timer"); - } else { - conn->ping_started = 1; - } - } - pthread_mutex_unlock (&conn->lock); + 0, + }, + }; + clnt_local_t *local = NULL; + call_frame_t *frame = NULL; + clnt_conf_t *conf = NULL; - frame = create_frame (this, this->ctx->pool); - if (!frame) - goto fail; + conf = this->private; - ret = client_submit_request (this, NULL, frame, conf->handshake, - GF_HNDSK_PING, client_ping_cbk, NULL, NULL, - NULL, 0, NULL, 0, NULL); - if (ret) - goto fail; - - return; -fail: + local = mem_get0(this->local_pool); + if (!local) { + goto out; + } + local->fdctx = fdctx; - if (frame) { - STACK_DESTROY (frame->root); - } + gf_uuid_copy(local->loc.gfid, fdctx->gfid); + ret = loc_path(&local->loc, NULL); + if (ret < 0) + goto out; - return; -} + frame = create_frame(this, this->ctx->pool); + if (!frame) { + goto out; + } + memcpy(req.gfid, fdctx->gfid, 16); -int -client_ping_cbk (struct rpc_req *req, struct iovec *iov, int count, - void *myframe) -{ - xlator_t *this = NULL; - rpc_clnt_connection_t *conn = NULL; - struct timeval timeout = {0, }; - call_frame_t *frame = NULL; - clnt_conf_t *conf = NULL; - - frame = myframe; - - this = frame->this; - conf = this->private; - conn = &conf->rpc->conn; - - if (req->rpc_status == -1) { - if (conn->ping_timer != NULL) { - gf_log (this->name, GF_LOG_DEBUG, "socket or ib" - " related error"); - gf_timer_call_cancel (this->ctx, conn->ping_timer); - conn->ping_timer = NULL; - } else { - /* timer expired and transport bailed out */ - gf_log (this->name, GF_LOG_DEBUG, "timer must have " - "expired"); - } - goto out; - } + gf_msg_debug(frame->this->name, 0, "attempting reopen on %s", + local->loc.path); - pthread_mutex_lock (&conn->lock); - { - timeout.tv_sec = conf->opt.ping_timeout; - timeout.tv_usec = 0; + frame->local = local; - gf_timer_call_cancel (this->ctx, - conn->ping_timer); + ret = client_submit_request(this, &req, frame, conf->fops, GFS3_OP_OPENDIR, + client3_3_reopendir_cbk, NULL, + (xdrproc_t)xdr_gfs3_opendir_req); + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, 0, PC_MSG_DIR_OP_FAILED, NULL); + } - conn->ping_timer = - gf_timer_call_after (this->ctx, timeout, - client_start_ping, (void *)this); + return 0; - if (conn->ping_timer == NULL) - gf_log (this->name, GF_LOG_DEBUG, - "gf_timer_call_after() returned NULL"); - } - pthread_mutex_unlock (&conn->lock); out: - STACK_DESTROY (frame->root); - return 0; -} + if (local) + client_local_wipe(local); + fdctx->reopen_done(fdctx, fdctx->remote_fd, this); -int -client3_getspec_cbk (struct rpc_req *req, struct iovec *iov, int count, - void *myframe) + return 0; +} + +static int +protocol_client_reopenfile(clnt_fd_ctx_t *fdctx, xlator_t *this) { - gf_getspec_rsp rsp = {0,}; - call_frame_t *frame = NULL; - int ret = 0; + int ret = -1; + gfs3_open_req req = { + { + 0, + }, + }; + clnt_local_t *local = NULL; + call_frame_t *frame = NULL; + clnt_conf_t *conf = NULL; - frame = myframe; + conf = this->private; - if (-1 == req->rpc_status) { - rsp.op_ret = -1; - rsp.op_errno = EINVAL; - goto out; - } + frame = create_frame(this, this->ctx->pool); + if (!frame) { + goto out; + } - ret = xdr_to_getspec_rsp (*iov, &rsp); - if (ret < 0) { - gf_log ("", GF_LOG_ERROR, "error"); - rsp.op_ret = -1; - rsp.op_errno = EINVAL; - goto out; - } + local = mem_get0(this->local_pool); + if (!local) { + goto out; + } - if (-1 == rsp.op_ret) { - gf_log (frame->this->name, GF_LOG_ERROR, - "failed to get the 'volume file' from server"); - goto out; - } + local->fdctx = fdctx; + gf_uuid_copy(local->loc.gfid, fdctx->gfid); + ret = loc_path(&local->loc, NULL); + if (ret < 0) + goto out; + + frame->local = local; + + memcpy(req.gfid, fdctx->gfid, 16); + req.flags = gf_flags_from_flags(fdctx->flags); + req.flags = req.flags & (~(O_TRUNC | O_CREAT | O_EXCL)); + + gf_msg_debug(frame->this->name, 0, "attempting reopen on %s", + local->loc.path); + + ret = client_submit_request(this, &req, frame, conf->fops, GFS3_OP_OPEN, + client3_3_reopen_cbk, NULL, + (xdrproc_t)xdr_gfs3_open_req); + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, 0, PC_MSG_DIR_OP_FAILED, NULL); + } + + return 0; out: - STACK_UNWIND_STRICT (getspec, frame, rsp.op_ret, rsp.op_errno, rsp.spec); + if (frame) { + frame->local = NULL; + STACK_DESTROY(frame->root); + } - /* Don't use 'GF_FREE', this is allocated by libc */ - if (rsp.spec) - free (rsp.spec); + if (local) + client_local_wipe(local); - return 0; + fdctx->reopen_done(fdctx, fdctx->remote_fd, this); + + return 0; } -int32_t client3_getspec (call_frame_t *frame, xlator_t *this, void *data) +static void +protocol_client_reopen(clnt_fd_ctx_t *fdctx, xlator_t *this) { - clnt_conf_t *conf = NULL; - clnt_args_t *args = NULL; - gf_getspec_req req = {0,}; - int op_errno = ESTALE; - int ret = 0; + if (fdctx->is_dir) + protocol_client_reopendir(fdctx, this); + else + protocol_client_reopenfile(fdctx, this); +} - if (!frame || !this || !data) - goto unwind; +/* v4.x + */ +int +client4_0_reopen_cbk(struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + int32_t ret = -1; + gfx_open_rsp rsp = { + 0, + }; + call_frame_t *frame = myframe; + xlator_t *this = frame->this; + clnt_local_t *local = frame->local; + clnt_fd_ctx_t *fdctx = local->fdctx; + + if (-1 == req->rpc_status) { + gf_smsg(frame->this->name, GF_LOG_WARNING, ENOTCONN, + PC_MSG_RPC_STATUS_ERROR, NULL); + 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_smsg(frame->this->name, GF_LOG_ERROR, EINVAL, + PC_MSG_XDR_DECODING_FAILED, NULL); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + if (rsp.op_ret < 0) { + gf_smsg(frame->this->name, GF_LOG_WARNING, rsp.op_errno, + PC_MSG_REOPEN_FAILED, "path=%s", local->loc.path, NULL); + } else { + gf_msg_debug(frame->this->name, 0, + "reopen on %s succeeded (remote-fd = %" PRId64 ")", + local->loc.path, rsp.fd); + } + + if (rsp.op_ret == -1) { + goto out; + } - args = data; - conf = this->private; - req.flags = args->flags; - req.key = (char *)args->name; +out: + fdctx->reopen_done(fdctx, (rsp.op_ret) ? -1 : rsp.fd, this); - ret = client_submit_request (this, &req, frame, conf->handshake, - GF_HNDSK_GETSPEC, client3_getspec_cbk, - NULL, xdr_from_getspec_req, NULL, 0, - NULL, 0, NULL); + frame->local = NULL; + STACK_DESTROY(frame->root); - if (ret) - goto unwind; - - return 0; -unwind: - STACK_UNWIND_STRICT (getspec, frame, -1, op_errno, NULL); - return 0; + client_local_wipe(local); + return 0; } int -client_post_handshake (call_frame_t *frame, xlator_t *this) +client4_0_reopendir_cbk(struct rpc_req *req, struct iovec *iov, int count, + void *myframe) { - clnt_conf_t *conf = NULL; - clnt_fd_ctx_t *tmp = NULL; - clnt_fd_ctx_t *fdctx = NULL; - xlator_list_t *parent = NULL; - struct list_head reopen_head; + int32_t ret = -1; + gfx_open_rsp rsp = { + 0, + }; + call_frame_t *frame = myframe; + clnt_local_t *local = frame->local; + clnt_fd_ctx_t *fdctx = local->fdctx; + + if (-1 == req->rpc_status) { + gf_smsg(frame->this->name, GF_LOG_WARNING, ENOTCONN, + PC_MSG_RPC_STATUS_ERROR, NULL); + 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_smsg(frame->this->name, GF_LOG_ERROR, EINVAL, + PC_MSG_XDR_DECODING_FAILED, NULL); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + if (rsp.op_ret < 0) { + gf_smsg(frame->this->name, GF_LOG_WARNING, rsp.op_errno, + PC_MSG_DIR_OP_FAILED, "dir-path=%s", local->loc.path, NULL); + } else { + gf_smsg(frame->this->name, GF_LOG_INFO, 0, PC_MSG_DIR_OP_SUCCESS, + "path=%s", local->loc.path, "fd=%" PRId64, rsp.fd, NULL); + } + + if (-1 == rsp.op_ret) { + goto out; + } - if (!this || !this->private) - goto out; +out: + fdctx->reopen_done(fdctx, (rsp.op_ret) ? -1 : rsp.fd, frame->this); - conf = this->private; - INIT_LIST_HEAD (&reopen_head); + frame->local = NULL; + STACK_DESTROY(frame->root); + client_local_wipe(local); - pthread_mutex_lock (&conf->lock); + return 0; +} + +static int +protocol_client_reopendir_v2(clnt_fd_ctx_t *fdctx, xlator_t *this) +{ + int ret = -1; + gfx_opendir_req req = { { - list_for_each_entry_safe (fdctx, tmp, &conf->saved_fds, - sfd_pos) { - if (fdctx->remote_fd != -1) - continue; - - list_del_init (&fdctx->sfd_pos); - list_add_tail (&fdctx->sfd_pos, &reopen_head); - } - } - pthread_mutex_unlock (&conf->lock); + 0, + }, + }; + call_frame_t *frame = NULL; + clnt_conf_t *conf = this->private; + clnt_local_t *local = mem_get0(this->local_pool); + + if (!local) { + ret = -1; + goto out; + } + local->fdctx = fdctx; + + gf_uuid_copy(local->loc.gfid, fdctx->gfid); + ret = loc_path(&local->loc, NULL); + if (ret < 0) + goto out; + + frame = create_frame(this, this->ctx->pool); + if (!frame) { + ret = -1; + goto out; + } + + memcpy(req.gfid, fdctx->gfid, 16); + + gf_msg_debug(frame->this->name, 0, "attempting reopen on %s", + local->loc.path); + + frame->local = local; + + ret = client_submit_request(this, &req, frame, conf->fops, GFS3_OP_OPENDIR, + client4_0_reopendir_cbk, NULL, + (xdrproc_t)xdr_gfx_opendir_req); + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, 0, PC_MSG_DIR_OP_FAILED, NULL); + } + + return 0; - list_for_each_entry_safe (fdctx, tmp, &reopen_head, sfd_pos) { - list_del_init (&fdctx->sfd_pos); +out: + if (local) + client_local_wipe(local); - if (fdctx->is_dir) - protocol_client_reopendir (this, fdctx); - else - protocol_client_reopen (this, fdctx); - } + fdctx->reopen_done(fdctx, fdctx->remote_fd, this); - /* As fuse is not 'parent' of any translator now, triggering its - CHILD_UP event is hacky in case client has only client protocol */ - if (!this->parents && this->ctx && this->ctx->master) { - /* send notify to 'ctx->master' if it exists */ - xlator_notify (this->ctx->master, GF_EVENT_CHILD_UP, - this->graph); - } + return 0; +} - parent = this->parents; - while (parent) { - xlator_notify (parent->xlator, GF_EVENT_CHILD_UP, - this); - parent = parent->next; - } +static int +protocol_client_reopenfile_v2(clnt_fd_ctx_t *fdctx, xlator_t *this) +{ + int ret = -1; + gfx_open_req req = { + { + 0, + }, + }; + clnt_local_t *local = NULL; + clnt_conf_t *conf = this->private; + call_frame_t *frame = create_frame(this, this->ctx->pool); + + if (!frame) { + ret = -1; + goto out; + } + + local = mem_get0(this->local_pool); + if (!local) { + ret = -1; + goto out; + } + + local->fdctx = fdctx; + gf_uuid_copy(local->loc.gfid, fdctx->gfid); + ret = loc_path(&local->loc, NULL); + if (ret < 0) + goto out; + + frame->local = local; + + memcpy(req.gfid, fdctx->gfid, 16); + req.flags = gf_flags_from_flags(fdctx->flags); + req.flags = req.flags & (~(O_TRUNC | O_CREAT | O_EXCL)); + + gf_msg_debug(frame->this->name, 0, "attempting reopen on %s", + local->loc.path); + + ret = client_submit_request(this, &req, frame, conf->fops, GFS3_OP_OPEN, + client4_0_reopen_cbk, NULL, + (xdrproc_t)xdr_gfx_open_req); + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, 0, PC_MSG_DIR_OP_FAILED, NULL); + } + + return 0; out: - return 0; -} + if (frame) { + frame->local = NULL; + STACK_DESTROY(frame->root); + } -int -client_setvolume_cbk (struct rpc_req *req, struct iovec *iov, int count, void *myframe) -{ - call_frame_t *frame = NULL; - clnt_conf_t *conf = NULL; - xlator_t *this = NULL; - dict_t *reply = NULL; - xlator_list_t *parent = NULL; - char *process_uuid = NULL; - char *remote_error = NULL; - char *remote_subvol = NULL; - gf_setvolume_rsp rsp = {0,}; - int ret = 0; - int32_t op_ret = 0; - int32_t op_errno = 0; - - frame = myframe; - this = frame->this; - conf = this->private; - - if (-1 == req->rpc_status) { - op_ret = -1; - goto out; - } + if (local) + client_local_wipe(local); - ret = xdr_to_setvolume_rsp (*iov, &rsp); - if (ret < 0) { - gf_log ("", GF_LOG_ERROR, "error"); - op_ret = -1; - goto out; - } - op_ret = rsp.op_ret; - op_errno = gf_error_to_errno (rsp.op_errno); - if (-1 == rsp.op_ret) { - gf_log (frame->this->name, GF_LOG_WARNING, - "failed to set the volume"); - } + fdctx->reopen_done(fdctx, fdctx->remote_fd, this); - reply = dict_new (); - if (!reply) - goto out; + return 0; +} - if (rsp.dict.dict_len) { - ret = dict_unserialize (rsp.dict.dict_val, - rsp.dict.dict_len, &reply); - if (ret < 0) { - gf_log (frame->this->name, GF_LOG_DEBUG, - "failed to unserialize buffer to dict"); - goto out; - } - } +static void +protocol_client_reopen_v2(clnt_fd_ctx_t *fdctx, xlator_t *this) +{ + if (fdctx->is_dir) + protocol_client_reopendir_v2(fdctx, this); + else + protocol_client_reopenfile_v2(fdctx, this); +} - ret = dict_get_str (reply, "ERROR", &remote_error); - if (ret < 0) { - gf_log (this->name, GF_LOG_DEBUG, - "failed to get ERROR string from reply dict"); - } +gf_boolean_t +__is_fd_reopen_in_progress(clnt_fd_ctx_t *fdctx) +{ + if (fdctx->reopen_done == client_default_reopen_done) + return _gf_false; + return _gf_true; +} - ret = dict_get_str (reply, "process-uuid", &process_uuid); - if (ret < 0) { - gf_log (this->name, GF_LOG_DEBUG, - "failed to get 'process-uuid' from reply dict"); +void +client_attempt_reopen(fd_t *fd, xlator_t *this) +{ + if (!fd || !this) + goto out; + + clnt_conf_t *conf = this->private; + clnt_fd_ctx_t *fdctx = NULL; + gf_boolean_t reopen = _gf_false; + + pthread_spin_lock(&conf->fd_lock); + { + fdctx = this_fd_get_ctx(fd, this); + if (!fdctx) { + pthread_spin_unlock(&conf->fd_lock); + goto out; } - if (op_ret < 0) { - gf_log (this->name, GF_LOG_ERROR, - "SETVOLUME on remote-host failed: %s", - remote_error ? remote_error : strerror (op_errno)); - errno = op_errno; - if (op_errno == ESTALE) { - parent = this->parents; - while (parent) { - xlator_notify (parent->xlator, - GF_EVENT_VOLFILE_MODIFIED, - this); - parent = parent->next; - } - } - goto out; + if (__is_fd_reopen_in_progress(fdctx)) + goto unlock; + if (fdctx->remote_fd != -1) + goto unlock; + + if (fdctx->reopen_attempts == CLIENT_REOPEN_MAX_ATTEMPTS) { + reopen = _gf_true; + fdctx->reopen_done = client_reopen_done; + list_del_init(&fdctx->sfd_pos); + } else { + fdctx->reopen_attempts++; } - ret = dict_get_str (this->options, "remote-subvolume", - &remote_subvol); - if (ret || !remote_subvol) - goto out; + } +unlock: + pthread_spin_unlock(&conf->fd_lock); + if (reopen) { + if (conf->fops->progver == GLUSTER_FOP_VERSION_v2) + protocol_client_reopen_v2(fdctx, this); + else + protocol_client_reopen(fdctx, this); + } +out: + return; +} - /* TODO: currently setpeer path is broken */ - /* - if (process_uuid && req->conn && - !strcmp (this->ctx->process_uuid, process_uuid)) { - rpc_transport_t *peer_trans = NULL; - uint64_t peertrans_int = 0; +static int +client_post_handshake(call_frame_t *frame, xlator_t *this) +{ + clnt_conf_t *conf = NULL; + clnt_fd_ctx_t *tmp = NULL; + clnt_fd_ctx_t *fdctx = NULL; + struct list_head reopen_head; - ret = dict_get_uint64 (reply, "transport-ptr", - &peertrans_int); - if (ret) - goto out; + int count = 0; - gf_log (this->name, GF_LOG_WARNING, - "attaching to the local volume '%s'", - remote_subvol); + if (!this || !this->private) + goto out; - peer_trans = (void *) (long) (peertrans_int); + conf = this->private; + INIT_LIST_HEAD(&reopen_head); - rpc_transport_setpeer (req->conn->trans, peer_trans); + pthread_spin_lock(&conf->fd_lock); + { + list_for_each_entry_safe(fdctx, tmp, &conf->saved_fds, sfd_pos) + { + if (fdctx->remote_fd != -1 || + (!list_empty(&fdctx->lock_list) && conf->strict_locks)) + continue; + + fdctx->reopen_done = client_child_up_reopen_done; + list_del_init(&fdctx->sfd_pos); + list_add_tail(&fdctx->sfd_pos, &reopen_head); + count++; } - */ - - gf_log (this->name, GF_LOG_NORMAL, - "Connected to %s, attached to remote volume '%s'.", - conf->rpc->conn.trans->peerinfo.identifier, - remote_subvol); + } + pthread_spin_unlock(&conf->fd_lock); - rpc_clnt_set_connected (&conf->rpc->conn); + /* Delay notifying CHILD_UP to parents + until all locks are recovered */ + if (count > 0) { + gf_smsg(this->name, GF_LOG_INFO, 0, PC_MSG_CHILD_UP_NOTIFY_DELAY, + "count=%d", count, NULL); + client_save_number_fds(conf, count); - op_ret = 0; - conf->connecting = 0; - conf->connected = 1; - - /* TODO: more to test */ - client_post_handshake (frame, frame->this); + list_for_each_entry_safe(fdctx, tmp, &reopen_head, sfd_pos) + { + list_del_init(&fdctx->sfd_pos); + if (conf->fops->progver == GLUSTER_FOP_VERSION_v2) + protocol_client_reopen_v2(fdctx, this); + else + protocol_client_reopen(fdctx, this); + } + } else { + gf_msg_debug(this->name, 0, + "No fds to open - notifying all parents child " + "up"); + client_notify_parents_child_up(this); + } out: + return 0; +} - if (-1 == op_ret) { - /* Let the connection/re-connection happen in - * background, for now, don't hang here, - * tell the parents that i am all ok.. - */ - parent = this->parents; - while (parent) { - xlator_notify (parent->xlator, - GF_EVENT_CHILD_CONNECTING, this); - parent = parent->next; - } - - conf->connecting= 1; +int +client_setvolume_cbk(struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = myframe; + xlator_t *this = frame->this; + clnt_conf_t *conf = this->private; + dict_t *reply = NULL; + char *process_uuid = NULL; + char *volume_id = NULL; + char *remote_error = NULL; + char *remote_subvol = NULL; + gf_setvolume_rsp rsp = { + 0, + }; + int ret = 0; + int32_t op_ret = 0; + int32_t op_errno = 0; + gf_boolean_t auth_fail = _gf_false; + glusterfs_ctx_t *ctx = NULL; + + GF_VALIDATE_OR_GOTO(this->name, conf, out); + ctx = this->ctx; + GF_VALIDATE_OR_GOTO(this->name, ctx, out); + + if (-1 == req->rpc_status) { + gf_smsg(frame->this->name, GF_LOG_WARNING, ENOTCONN, + PC_MSG_RPC_STATUS_ERROR, NULL); + op_ret = -1; + goto out; + } + + ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gf_setvolume_rsp); + if (ret < 0) { + gf_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + op_ret = -1; + goto out; + } + op_ret = rsp.op_ret; + op_errno = gf_error_to_errno(rsp.op_errno); + if (-1 == rsp.op_ret) { + gf_smsg(frame->this->name, GF_LOG_WARNING, op_errno, + PC_MSG_VOL_SET_FAIL, NULL); + } + + reply = dict_new(); + if (!reply) + goto out; + + if (rsp.dict.dict_len) { + ret = dict_unserialize(rsp.dict.dict_val, rsp.dict.dict_len, &reply); + if (ret < 0) { + gf_smsg(frame->this->name, GF_LOG_WARNING, 0, + PC_MSG_DICT_UNSERIALIZE_FAIL, NULL); + goto out; + } + } + + ret = dict_get_str_sizen(reply, "ERROR", &remote_error); + if (ret < 0) { + gf_smsg(this->name, GF_LOG_WARNING, EINVAL, PC_MSG_DICT_GET_FAILED, + "ERROR string", NULL); + } + + ret = dict_get_str_sizen(reply, "process-uuid", &process_uuid); + if (ret < 0) { + gf_smsg(this->name, GF_LOG_WARNING, EINVAL, PC_MSG_DICT_GET_FAILED, + "process-uuid", NULL); + } + + if (op_ret < 0) { + gf_smsg(this->name, GF_LOG_ERROR, op_errno, PC_MSG_SETVOLUME_FAIL, + "remote-error=%s", remote_error, NULL); + + errno = op_errno; + if (remote_error && (op_errno == EACCES)) { + auth_fail = _gf_true; + op_ret = 0; + } + if ((op_errno == ENOENT) && this->ctx->cmd_args.subdir_mount && + (ctx->graph_id <= 1)) { + /* A case of subdir not being present at the moment, + ride on auth_fail framework to notify the error */ + /* Make sure this case is handled only in the new + graph, so mount may fail in this case. In case + of 'add-brick' etc, we need to continue retry */ + auth_fail = _gf_true; + op_ret = 0; + } + if (op_errno == ESTALE) { + ret = client_notify_dispatch(this, GF_EVENT_VOLFILE_MODIFIED, NULL); + if (ret) + gf_smsg(this->name, GF_LOG_INFO, 0, + PC_MSG_VOLFILE_NOTIFY_FAILED, NULL); + } + goto out; + } + + ret = dict_get_str_sizen(this->options, "remote-subvolume", &remote_subvol); + if (ret || !remote_subvol) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FIND_KEY_FAILED, + "remote-subvolume", NULL); + goto out; + } + + ret = dict_get_str_sizen(reply, "volume-id", &volume_id); + if (ret < 0) { + /* this can happen if the server is of old version, so treat it as + just debug message */ + gf_msg_debug(this->name, EINVAL, + "failed to get 'volume-id' from reply dict"); + } else if (ctx->master && strncmp("snapd", remote_subvol, 5)) { + /* TODO: if it is a fuse mount or a snapshot enabled client, don't + bother */ + /* If any value is set, the first element will be non-0. + It would be '0', but not '\0' :-) */ + if (ctx->volume_id[0]) { + if (strcmp(ctx->volume_id, volume_id)) { + /* Ideally it shouldn't even come here, as server itself + should fail the handshake in that case */ + gf_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_VOL_ID_CHANGED, + "vol-id=%s", volume_id, "ctx->vol-id=%s", + ctx->volume_id, NULL); + op_ret = -1; + goto out; + } + } else { + strncpy(ctx->volume_id, volume_id, GF_UUID_BUF_SIZE); } + } + + uint32_t child_up_int; + ret = dict_get_uint32(reply, "child_up", &child_up_int); + if (ret) { + /* + * This would happen in cases where the server trying to * + * connect to this client is running an older version. Hence * + * setting the child_up to _gf_true in this case. * + */ + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FIND_KEY_FAILED, + "child_up", NULL); + conf->child_up = _gf_true; + } else { + conf->child_up = (child_up_int != 0); + } + + /* TODO: currently setpeer path is broken */ + /* + if (process_uuid && req->conn && + !strcmp (this->ctx->process_uuid, process_uuid)) { + rpc_transport_t *peer_trans = NULL; + uint64_t peertrans_int = 0; + + ret = dict_get_uint64 (reply, "transport-ptr", + &peertrans_int); + if (ret) + goto out; + + gf_log (this->name, GF_LOG_WARNING, + "attaching to the local volume '%s'", + remote_subvol); + + peer_trans = (void *) (long) (peertrans_int); + + rpc_transport_setpeer (req->conn->trans, peer_trans); + } + */ + + conf->client_id = glusterfs_leaf_position(this); + + gf_smsg(this->name, GF_LOG_INFO, 0, PC_MSG_REMOTE_VOL_CONNECTED, + "conn-name=%s", conf->rpc->conn.name, "remote_subvol=%s", + remote_subvol, NULL); + + op_ret = 0; + conf->connected = 1; + + client_post_handshake(frame, frame->this); +out: + if (auth_fail) { + gf_smsg(this->name, GF_LOG_INFO, 0, PC_MSG_AUTH_FAILED, NULL); + ret = client_notify_dispatch(this, GF_EVENT_AUTH_FAILED, NULL); + if (ret) + gf_smsg(this->name, GF_LOG_INFO, 0, + PC_MSG_AUTH_FAILED_NOTIFY_FAILED, NULL); + conf->connected = 0; + ret = -1; + } + if (-1 == op_ret) { + /* Let the connection/re-connection happen in + * background, for now, don't hang here, + * tell the parents that i am all ok.. + */ + gf_smsg(this->name, GF_LOG_INFO, 0, PC_MSG_CHILD_CONNECTING_EVENT, + NULL); + ret = client_notify_dispatch(this, GF_EVENT_CHILD_CONNECTING, NULL); + if (ret) + gf_smsg(this->name, GF_LOG_INFO, 0, + PC_MSG_CHILD_CONNECTING_NOTIFY_FAILED, NULL); + /* + * The reconnection *won't* happen in the background (see + * previous comment) unless we kill the current connection. + */ + rpc_transport_disconnect(conf->rpc->conn.trans, _gf_false); + ret = 0; + } - if (rsp.dict.dict_val) - free (rsp.dict.dict_val); + free(rsp.dict.dict_val); - STACK_DESTROY (frame->root); + STACK_DESTROY(frame->root); - if (reply) - dict_unref (reply); + if (reply) + dict_unref(reply); - return 0; + return ret; } int -client_setvolume (xlator_t *this, struct rpc_clnt *rpc) +client_setvolume(xlator_t *this, struct rpc_clnt *rpc) { - int ret = 0; - gf_setvolume_req req = {0,}; - call_frame_t *fr = NULL; - char *process_uuid_xl = NULL; - clnt_conf_t *conf = NULL; - dict_t *options = NULL; - - struct rpc_clnt_config config = {0, }; - - - options = this->options; - conf = this->private; - - if (conf->fops) { - ret = dict_set_int32 (options, "fops-version", - conf->fops->prognum); - if (ret < 0) { - gf_log (this->name, GF_LOG_ERROR, - "failed to set version-fops(%d) in handshake msg", - conf->fops->prognum); - goto fail; - } - } - - if (conf->mgmt) { - ret = dict_set_int32 (options, "mgmt-version", conf->mgmt->prognum); - if (ret < 0) { - gf_log (this->name, GF_LOG_ERROR, - "failed to set version-mgmt(%d) in handshake msg", - conf->mgmt->prognum); - goto fail; - } + int ret = 0; + gf_setvolume_req req = { + { + 0, + }, + }; + call_frame_t *fr = NULL; + char *process_uuid_xl = NULL; + char *remote_subvol = NULL; + clnt_conf_t *conf = this->private; + dict_t *options = this->options; + char counter_str[32] = {0}; + char hostname[256] = { + 0, + }; + + if (conf->fops) { + ret = dict_set_int32_sizen(options, "fops-version", + conf->fops->prognum); + if (ret < 0) { + gf_smsg(this->name, GF_LOG_ERROR, 0, PC_MSG_DICT_SET_FAILED, + "version-fops=%d", conf->fops->prognum, NULL); + goto fail; } + } - ret = gf_asprintf (&process_uuid_xl, "%s-%s", this->ctx->process_uuid, - this->name); - if (-1 == ret) { - gf_log (this->name, GF_LOG_ERROR, - "asprintf failed while setting process_uuid"); - goto fail; + if (conf->mgmt) { + ret = dict_set_int32_sizen(options, "mgmt-version", + conf->mgmt->prognum); + if (ret < 0) { + gf_smsg(this->name, GF_LOG_ERROR, 0, PC_MSG_DICT_SET_FAILED, + "version-mgmt=%d", conf->mgmt->prognum, NULL); + goto fail; } - ret = dict_set_dynstr (options, "process-uuid", process_uuid_xl); + } + + /* + * Connection-id should always be unique so that server never gets to + * reuse the previous connection resources so it cleans up the resources + * on every disconnect. Otherwise it may lead to stale resources, i.e. + * leaked file descriptors, inode/entry locks + */ + + snprintf(counter_str, sizeof(counter_str), "-%" PRIu64, conf->setvol_count); + conf->setvol_count++; + + if (gethostname(hostname, 256) == -1) { + gf_smsg(this->name, GF_LOG_ERROR, errno, PC_MSG_GETHOSTNAME_FAILED, + NULL); + + goto fail; + } + + ret = gf_asprintf(&process_uuid_xl, GLUSTER_PROCESS_UUID_FMT, + this->ctx->process_uuid, this->graph->id, getpid(), + hostname, this->name, counter_str); + if (-1 == ret) { + gf_smsg(this->name, GF_LOG_ERROR, 0, PC_MSG_PROCESS_UUID_SET_FAIL, + NULL); + goto fail; + } + + ret = dict_set_dynstr_sizen(options, "process-uuid", process_uuid_xl); + if (ret < 0) { + gf_smsg(this->name, GF_LOG_ERROR, 0, PC_MSG_DICT_SET_FAILED, + "process-uuid=%s", process_uuid_xl, NULL); + goto fail; + } + + if (this->ctx->cmd_args.process_name) { + ret = dict_set_str_sizen(options, "process-name", + this->ctx->cmd_args.process_name); if (ret < 0) { - gf_log (this->name, GF_LOG_ERROR, - "failed to set process-uuid(%s) in handshake msg", - process_uuid_xl); - goto fail; + gf_smsg(this->name, GF_LOG_INFO, 0, PC_MSG_DICT_SET_FAILED, + "process-name", NULL); } - - if (this->ctx->cmd_args.volfile_server) { - if (this->ctx->cmd_args.volfile_id) { - ret = dict_set_str (options, "volfile-key", - this->ctx->cmd_args.volfile_id); - if (ret) - gf_log (this->name, GF_LOG_ERROR, - "failed to set 'volfile-key'"); - } - ret = dict_set_uint32 (options, "volfile-checksum", - this->graph->volfile_checksum); - if (ret) - gf_log (this->name, GF_LOG_ERROR, - "failed to set 'volfile-checksum'"); + } + + ret = dict_set_str_sizen(options, "client-version", PACKAGE_VERSION); + if (ret < 0) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_DICT_SET_FAILED, + "client-version=%s", PACKAGE_VERSION, NULL); + } + + ret = dict_get_str_sizen(this->options, "remote-subvolume", &remote_subvol); + if (ret || !remote_subvol) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FIND_KEY_FAILED, + "remote-subvolume", NULL); + goto fail; + } + + /* volume-id to be sent only for regular volume, not snap volume */ + if (strncmp("snapd", remote_subvol, 5)) { + /* If any value is set, the first element will be non-0. + It would be '0', but not '\0' :-) */ + if (!this->ctx->volume_id[0]) { + strncpy(this->ctx->volume_id, this->graph->volume_id, + GF_UUID_BUF_SIZE); } - - req.dict.dict_len = dict_serialized_length (options); - if (req.dict.dict_len < 0) { - gf_log (this->name, GF_LOG_ERROR, - "failed to get serialized length of dict"); - ret = -1; - goto fail; + if (this->ctx->volume_id[0]) { + ret = dict_set_str(options, "volume-id", this->ctx->volume_id); + if (ret < 0) { + gf_smsg(this->name, GF_LOG_INFO, 0, PC_MSG_DICT_SET_FAILED, + "volume-id", NULL); + } } - req.dict.dict_val = GF_CALLOC (1, req.dict.dict_len, - gf_client_mt_clnt_req_buf_t); - ret = dict_serialize (options, req.dict.dict_val); - if (ret < 0) { - gf_log (this->name, GF_LOG_ERROR, - "failed to serialize dictionary"); - goto fail; + } + + if (this->ctx->cmd_args.volfile_server) { + if (this->ctx->cmd_args.volfile_id) { + ret = dict_set_str_sizen(options, "volfile-key", + this->ctx->cmd_args.volfile_id); + if (ret) + gf_smsg(this->name, GF_LOG_ERROR, 0, + PC_MSG_VOLFILE_KEY_SET_FAILED, NULL); } + ret = dict_set_uint32(options, "volfile-checksum", + this->graph->volfile_checksum); + if (ret) + gf_smsg(this->name, GF_LOG_ERROR, 0, PC_MSG_VOLFILE_CHECKSUM_FAILED, + NULL); + } - fr = create_frame (this, this->ctx->pool); - if (!fr) - goto fail; - - ret = client_submit_request (this, &req, fr, conf->handshake, - GF_HNDSK_SETVOLUME, client_setvolume_cbk, - NULL, xdr_from_setvolume_req, NULL, 0, - NULL, 0, NULL); - -fail: + if (this->ctx->cmd_args.subdir_mount) { + ret = dict_set_str_sizen(options, "subdir-mount", + this->ctx->cmd_args.subdir_mount); if (ret) { - config.remote_port = -1; - rpc_clnt_reconfig (conf->rpc, &config); + gf_log(THIS->name, GF_LOG_ERROR, "Failed to set subdir_mount"); + /* It makes sense to fail, as per the CLI, we + should be doing a subdir_mount */ + goto fail; } + } + + /* Insert a dummy key value pair to avoid failure at server side for + * clnt-lk-version with new clients. + */ + ret = dict_set_uint32(options, "clnt-lk-version", 1); + if (ret < 0) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_DICT_SET_FAILED, + "clnt-lk-version(1)", NULL); + } + + ret = dict_set_int32_sizen(options, "opversion", GD_OP_VERSION_MAX); + if (ret < 0) { + gf_smsg(this->name, GF_LOG_ERROR, 0, PC_MSG_DICT_SET_FAILED, + "client opversion", NULL); + } + + ret = dict_allocate_and_serialize(options, (char **)&req.dict.dict_val, + &req.dict.dict_len); + if (ret != 0) { + ret = -1; + gf_smsg(this->name, GF_LOG_ERROR, 0, PC_MSG_DICT_SERIALIZE_FAIL, NULL); + goto fail; + } + + fr = create_frame(this, this->ctx->pool); + if (!fr) + goto fail; + + ret = client_submit_request(this, &req, fr, conf->handshake, + GF_HNDSK_SETVOLUME, client_setvolume_cbk, NULL, + (xdrproc_t)xdr_gf_setvolume_req); - if (req.dict.dict_val) - GF_FREE (req.dict.dict_val); +fail: + GF_FREE(req.dict.dict_val); - return ret; + return ret; } -int -select_server_supported_programs (xlator_t *this, gf_prog_detail *prog) +static int +select_server_supported_programs(xlator_t *this, gf_prog_detail *prog) { - gf_prog_detail *trav = NULL; - clnt_conf_t *conf = NULL; - int ret = -1; - - if (!this || !prog) - goto out; + gf_prog_detail *trav = NULL; + clnt_conf_t *conf = NULL; + int ret = -1; + + if (!this || !prog) { + gf_smsg(THIS->name, GF_LOG_WARNING, 0, PC_MSG_PGM_NOT_FOUND, NULL); + goto out; + } + + conf = this->private; + trav = prog; + + while (trav) { + /* Select 'programs' */ + if ((clnt3_3_fop_prog.prognum == trav->prognum) && + (clnt3_3_fop_prog.progver == trav->progver)) { + conf->fops = &clnt3_3_fop_prog; + if (conf->rpc) + conf->rpc->auth_value = AUTH_GLUSTERFS_v2; + ret = 0; + /* In normal flow, we don't want to use old protocol type. + but if it is for testing, lets use it */ + if (conf->old_protocol) + goto done; + } - conf = this->private; - trav = prog; + if ((clnt4_0_fop_prog.prognum == trav->prognum) && + (clnt4_0_fop_prog.progver == trav->progver)) { + conf->fops = &clnt4_0_fop_prog; + if (conf->rpc) + conf->rpc->auth_value = AUTH_GLUSTERFS_v3; + ret = 0; + /* this is latest program, lets use this program only */ + /* if we are testing for old-protocol, lets not break this */ + if (!conf->old_protocol) + goto done; + } - while (trav) { - /* Select 'programs' */ - if ((clnt3_1_fop_prog.prognum == trav->prognum) && - (clnt3_1_fop_prog.progver == trav->progver)) { - conf->fops = &clnt3_1_fop_prog; - gf_log (this->name, GF_LOG_INFO, - "Using Program %s, Num (%"PRId64"), " - "Version (%"PRId64")", - trav->progname, trav->prognum, trav->progver); - ret = 0; - } - if (ret) { - gf_log (this->name, GF_LOG_TRACE, - "%s (%"PRId64") not supported", trav->progname, - trav->progver); - } - trav = trav->next; + if (ret) { + gf_msg_debug(this->name, 0, "%s (%" PRId64 ") not supported", + trav->progname, trav->progver); } + trav = trav->next; + } + +done: + if (!ret) + gf_smsg(this->name, GF_LOG_INFO, 0, PC_MSG_VERSION_INFO, + "Program-name=%s", conf->fops->progname, "Num=%d", + conf->fops->prognum, "Version=%d", conf->fops->progver, NULL); out: - return ret; + return ret; } - int -server_has_portmap (xlator_t *this, gf_prog_detail *prog) +server_has_portmap(xlator_t *this, gf_prog_detail *prog) { - gf_prog_detail *trav = NULL; - int ret = -1; - - if (!this || !prog) - goto out; - - trav = prog; - - while (trav) { - if ((trav->prognum == GLUSTER_PMAP_PROGRAM) && - (trav->progver == GLUSTER_PMAP_VERSION)) { - gf_log (this->name, GF_LOG_DEBUG, - "detected portmapper on server"); - ret = 0; - break; - } - trav = trav->next; + gf_prog_detail *trav = NULL; + int ret = -1; + + if (!this || !prog) { + gf_smsg(THIS->name, GF_LOG_WARNING, 0, PC_MSG_PGM_NOT_FOUND, NULL); + goto out; + } + + trav = prog; + + while (trav) { + if ((trav->prognum == GLUSTER_PMAP_PROGRAM) && + (trav->progver == GLUSTER_PMAP_VERSION)) { + gf_msg_debug(this->name, 0, "detected portmapper on server"); + ret = 0; + break; } + trav = trav->next; + } out: - return ret; + return ret; } - int -client_query_portmap_cbk (struct rpc_req *req, struct iovec *iov, int count, void *myframe) +client_query_portmap_cbk(struct rpc_req *req, struct iovec *iov, int count, + void *myframe) { - struct pmap_port_by_brick_rsp rsp = {0,}; - call_frame_t *frame = NULL; - clnt_conf_t *conf = NULL; - int ret = -1; - struct rpc_clnt_config config = {0, }; - - - frame = myframe; - conf = frame->this->private; - - if (-1 == req->rpc_status) { - gf_log ("", 1, "some error, retry again later"); - goto out; + struct pmap_port_by_brick_rsp rsp = { + 0, + }; + call_frame_t *frame = NULL; + clnt_conf_t *conf = NULL; + int ret = -1; + struct rpc_clnt_config config = { + 0, + }; + xlator_t *this = NULL; + + frame = myframe; + if (!frame || !frame->this || !frame->this->private) { + gf_smsg(THIS->name, GF_LOG_WARNING, EINVAL, PC_MSG_FRAME_NOT_FOUND, + NULL); + goto out; + } + this = frame->this; + conf = frame->this->private; + + if (-1 == req->rpc_status) { + gf_smsg(this->name, GF_LOG_WARNING, ENOTCONN, PC_MSG_RPC_STATUS_ERROR, + NULL); + goto out; + } + + ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_pmap_port_by_brick_rsp); + if (ret < 0) { + gf_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + goto out; + } + + if (-1 == rsp.op_ret) { + ret = -1; + if (!conf->portmap_err_logged) { + gf_smsg(this->name, GF_LOG_ERROR, 0, PC_MSG_PORT_NUM_ERROR, NULL); + } else { + gf_msg_debug(this->name, 0, + "failed to get the port number for " + "remote subvolume. Please run 'gluster " + "volume status' on server to see " + "if brick process is running."); } + conf->portmap_err_logged = 1; + goto out; + } - ret = xdr_to_pmap_port_by_brick_rsp (*iov, &rsp); - if (ret < 0) { - gf_log ("", GF_LOG_ERROR, "error"); - goto out; - } - - if (-1 == rsp.op_ret) { - ret = -1; - gf_log (frame->this->name, GF_LOG_ERROR, - "failed to get the port number for remote subvolume"); - goto out; - } + conf->portmap_err_logged = 0; + conf->disconnect_err_logged = 0; + config.remote_port = rsp.port; + rpc_clnt_reconfig(conf->rpc, &config); - config.remote_port = rsp.port; - rpc_clnt_reconfig (conf->rpc, &config); + conf->skip_notify = 1; + conf->quick_reconnect = 1; out: - STACK_DESTROY (frame->root); + if (frame) + STACK_DESTROY(frame->root); - rpc_transport_disconnect (conf->rpc->conn.trans); + if (conf) { + /* Need this to connect the same transport on different port */ + /* ie, glusterd to glusterfsd */ + rpc_transport_disconnect(conf->rpc->conn.trans, _gf_false); + } - rpc_clnt_reconnect (conf->rpc->conn.trans); - - return ret; + return ret; } - int -client_query_portmap (xlator_t *this, struct rpc_clnt *rpc) +client_query_portmap(xlator_t *this, struct rpc_clnt *rpc) { - int ret = -1; - pmap_port_by_brick_req req = {0,}; - call_frame_t *fr = NULL; - clnt_conf_t *conf = NULL; - dict_t *options = NULL; - char *remote_subvol = NULL; - - options = this->options; - conf = this->private; - - ret = dict_get_str (options, "remote-subvolume", &remote_subvol); - if (ret < 0) { - gf_log (this->name, GF_LOG_ERROR, - "remote-subvolume not set in volfile"); - goto fail; + int ret = -1; + pmap_port_by_brick_req req = { + 0, + }; + call_frame_t *fr = NULL; + dict_t *options = NULL; + char *remote_subvol = NULL; + char *xprt = NULL; + char brick_name[PATH_MAX] = { + 0, + }; + + options = this->options; + + ret = dict_get_str_sizen(options, "remote-subvolume", &remote_subvol); + if (ret < 0) { + gf_smsg(this->name, GF_LOG_ERROR, 0, PC_MSG_REMOTE_SUBVOL_SET_FAIL, + NULL); + goto fail; + } + + req.brick = remote_subvol; + + if (!dict_get_str_sizen(options, "transport-type", &xprt)) { + if (!strcmp(xprt, "rdma")) { + snprintf(brick_name, sizeof(brick_name), "%s.rdma", remote_subvol); + req.brick = brick_name; } + } - req.brick = remote_subvol; - - fr = create_frame (this, this->ctx->pool); - if (!fr) { - ret = -1; - goto fail; - } + fr = create_frame(this, this->ctx->pool); + if (!fr) { + ret = -1; + goto fail; + } - ret = client_submit_request (this, &req, fr, &clnt_pmap_prog, - GF_PMAP_PORTBYBRICK, - client_query_portmap_cbk, - NULL, xdr_from_pmap_port_by_brick_req, - NULL, 0, NULL, 0, NULL); + ret = client_submit_request(this, &req, fr, &clnt_pmap_prog, + GF_PMAP_PORTBYBRICK, client_query_portmap_cbk, + NULL, (xdrproc_t)xdr_pmap_port_by_brick_req); fail: - return ret; + return ret; } - -int -client_dump_version_cbk (struct rpc_req *req, struct iovec *iov, int count, - void *myframe) +static int +client_dump_version_cbk(struct rpc_req *req, struct iovec *iov, int count, + void *myframe) { - gf_dump_rsp rsp = {0,}; - gf_prog_detail *trav = NULL; - gf_prog_detail *next = NULL; - call_frame_t *frame = NULL; - clnt_conf_t *conf = NULL; - int ret = 0; - - frame = myframe; - conf = frame->this->private; - - if (-1 == req->rpc_status) { - gf_log ("", 1, "some error, retry again later"); - goto out; - } - - ret = xdr_to_dump_rsp (*iov, &rsp); - if (ret < 0) { - gf_log ("", GF_LOG_ERROR, "error"); - goto out; - } - if (-1 == rsp.op_ret) { - gf_log (frame->this->name, GF_LOG_ERROR, - "failed to get the 'versions' from server"); - goto out; - } - - if (server_has_portmap (frame->this, rsp.prog) == 0) { - ret = client_query_portmap (frame->this, conf->rpc); - goto out; - } - - /* Check for the proper version string */ - /* Reply in "Name:Program-Number:Program-Version,..." format */ - ret = select_server_supported_programs (frame->this, rsp.prog); - if (ret) { - gf_log (frame->this->name, GF_LOG_ERROR, - "Server versions are not present in this " - "release"); - goto out; - } - - client_setvolume (frame->this, conf->rpc); + gf_dump_rsp rsp = { + 0, + }; + gf_prog_detail *trav = NULL; + gf_prog_detail *next = NULL; + call_frame_t *frame = NULL; + clnt_conf_t *conf = NULL; + int ret = 0; + + frame = myframe; + conf = frame->this->private; + + if (-1 == req->rpc_status) { + gf_smsg(frame->this->name, GF_LOG_WARNING, ENOTCONN, + PC_MSG_RPC_STATUS_ERROR, NULL); + goto out; + } + + ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gf_dump_rsp); + if (ret < 0) { + gf_smsg(frame->this->name, GF_LOG_ERROR, EINVAL, + PC_MSG_XDR_DECODING_FAILED, NULL); + goto out; + } + if (-1 == rsp.op_ret) { + gf_smsg(frame->this->name, GF_LOG_WARNING, 0, PC_MSG_VERSION_ERROR, + NULL); + goto out; + } + + if (server_has_portmap(frame->this, rsp.prog) == 0) { + ret = client_query_portmap(frame->this, conf->rpc); + goto out; + } + + /* Check for the proper version string */ + /* Reply in "Name:Program-Number:Program-Version,..." format */ + ret = select_server_supported_programs(frame->this, rsp.prog); + if (ret) { + gf_smsg(frame->this->name, GF_LOG_ERROR, 0, PC_MSG_VERSION_ERROR, NULL); + goto out; + } + + client_setvolume(frame->this, conf->rpc); out: - /* don't use GF_FREE, buffer was allocated by libc */ - if (rsp.prog) { - trav = rsp.prog; - while (trav) { - next = trav->next; - free (trav->progname); - free (trav); - trav = next; - } + /* don't use GF_FREE, buffer was allocated by libc */ + if (rsp.prog) { + trav = rsp.prog; + while (trav) { + next = trav->next; + free(trav->progname); + free(trav); + trav = next; } + } - STACK_DESTROY (frame->root); + STACK_DESTROY(frame->root); - if (ret != 0) - rpc_transport_disconnect (conf->rpc->conn.trans); + if (ret != 0) + rpc_transport_disconnect(conf->rpc->conn.trans, _gf_false); - return ret; + return ret; } int -client_handshake (xlator_t *this, struct rpc_clnt *rpc) +client_handshake(xlator_t *this, struct rpc_clnt *rpc) { - call_frame_t *frame = NULL; - clnt_conf_t *conf = NULL; - gf_dump_req req = {0,}; - int ret = 0; - - conf = this->private; - if (!conf->handshake) - goto out; - - frame = create_frame (this, this->ctx->pool); - if (!frame) - goto out; - - req.gfs_id = 0xbabe; - ret = client_submit_request (this, &req, frame, conf->dump, - GF_DUMP_DUMP, client_dump_version_cbk, - NULL, xdr_from_dump_req, NULL, 0, NULL, 0, - NULL); + call_frame_t *frame = NULL; + clnt_conf_t *conf = NULL; + gf_dump_req req = { + 0, + }; + int ret = 0; + + conf = this->private; + if (!conf->handshake) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_HANDSHAKE_PGM_NOT_FOUND, + NULL); + goto out; + } + + frame = create_frame(this, this->ctx->pool); + if (!frame) + goto out; + + req.gfs_id = 0xbabe; + ret = client_submit_request(this, &req, frame, conf->dump, GF_DUMP_DUMP, + client_dump_version_cbk, NULL, + (xdrproc_t)xdr_gf_dump_req); out: - return ret; + return ret; } char *clnt_handshake_procs[GF_HNDSK_MAXVALUE] = { - [GF_HNDSK_NULL] = "NULL", - [GF_HNDSK_SETVOLUME] = "SETVOLUME", - [GF_HNDSK_GETSPEC] = "GETSPEC", - [GF_HNDSK_PING] = "PING", + [GF_HNDSK_NULL] = "NULL", + [GF_HNDSK_SETVOLUME] = "SETVOLUME", + [GF_HNDSK_GETSPEC] = "GETSPEC", + [GF_HNDSK_PING] = "PING", }; rpc_clnt_prog_t clnt_handshake_prog = { - .progname = "GlusterFS Handshake", - .prognum = GLUSTER_HNDSK_PROGRAM, - .progver = GLUSTER_HNDSK_VERSION, - .procnames = clnt_handshake_procs, + .progname = "GlusterFS Handshake", + .prognum = GLUSTER_HNDSK_PROGRAM, + .progver = GLUSTER_HNDSK_VERSION, + .procnames = clnt_handshake_procs, }; char *clnt_dump_proc[GF_DUMP_MAXVALUE] = { - [GF_DUMP_NULL] = "NULL", - [GF_DUMP_DUMP] = "DUMP", + [GF_DUMP_NULL] = "NULL", + [GF_DUMP_DUMP] = "DUMP", }; rpc_clnt_prog_t clnt_dump_prog = { - .progname = "GF-DUMP", - .prognum = GLUSTER_DUMP_PROGRAM, - .progver = GLUSTER_DUMP_VERSION, - .procnames = clnt_dump_proc, + .progname = "GF-DUMP", + .prognum = GLUSTER_DUMP_PROGRAM, + .progver = GLUSTER_DUMP_VERSION, + .procnames = clnt_dump_proc, }; char *clnt_pmap_procs[GF_PMAP_MAXVALUE] = { - [GF_PMAP_PORTBYBRICK] = "PORTBYBRICK", + [GF_PMAP_PORTBYBRICK] = "PORTBYBRICK", }; rpc_clnt_prog_t clnt_pmap_prog = { - .progname = "PORTMAP", - .prognum = GLUSTER_PMAP_PROGRAM, - .progver = GLUSTER_PMAP_VERSION, - .procnames = clnt_pmap_procs, + .progname = "PORTMAP", + .prognum = GLUSTER_PMAP_PROGRAM, + .progver = GLUSTER_PMAP_VERSION, + .procnames = clnt_pmap_procs, }; diff --git a/xlators/protocol/client/src/client-helpers.c b/xlators/protocol/client/src/client-helpers.c index d8da60aa1ae..189dfddd021 100644 --- a/xlators/protocol/client/src/client-helpers.c +++ b/xlators/protocol/client/src/client-helpers.c @@ -1,218 +1,899 @@ /* - Copyright (c) 2010 Gluster, Inc. <http://www.gluster.com> + Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.com> This file is part of GlusterFS. - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. + 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. */ -#ifndef _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif - #include "client.h" -#include "fd.h" +#include <glusterfs/fd.h> +#include "client-messages.h" +#include "client-common.h" +#include <glusterfs/compat-errno.h> +#include <glusterfs/common-utils.h> + +int +client_fd_lk_list_empty(fd_lk_ctx_t *lk_ctx, gf_boolean_t try_lock) +{ + int ret = 1; + + if (!lk_ctx) { + ret = -1; + goto out; + } + + if (try_lock) { + ret = TRY_LOCK(&lk_ctx->lock); + if (ret != 0) { + ret = -1; + goto out; + } + } else { + LOCK(&lk_ctx->lock); + } + + ret = list_empty(&lk_ctx->lk_list); + UNLOCK(&lk_ctx->lock); +out: + return ret; +} clnt_fd_ctx_t * -this_fd_del_ctx (fd_t *file, xlator_t *this) +this_fd_del_ctx(fd_t *file, xlator_t *this) { - int dict_ret = -1; - uint64_t ctxaddr = 0; + int dict_ret = -1; + uint64_t ctxaddr = 0; - GF_VALIDATE_OR_GOTO ("client", this, out); - GF_VALIDATE_OR_GOTO (this->name, file, out); + GF_VALIDATE_OR_GOTO("client", this, out); + GF_VALIDATE_OR_GOTO(this->name, file, out); - dict_ret = fd_ctx_del (file, this, &ctxaddr); + dict_ret = fd_ctx_del(file, this, &ctxaddr); - if (dict_ret < 0) { - ctxaddr = 0; - } + if (dict_ret < 0) { + ctxaddr = 0; + } out: - return (clnt_fd_ctx_t *)(unsigned long)ctxaddr; + return (clnt_fd_ctx_t *)(unsigned long)ctxaddr; } - clnt_fd_ctx_t * -this_fd_get_ctx (fd_t *file, xlator_t *this) +this_fd_get_ctx(fd_t *file, xlator_t *this) { - int dict_ret = -1; - uint64_t ctxaddr = 0; + int dict_ret = -1; + uint64_t ctxaddr = 0; - GF_VALIDATE_OR_GOTO ("client", this, out); - GF_VALIDATE_OR_GOTO (this->name, file, out); + GF_VALIDATE_OR_GOTO("client", this, out); + GF_VALIDATE_OR_GOTO(this->name, file, out); - dict_ret = fd_ctx_get (file, this, &ctxaddr); + dict_ret = fd_ctx_get(file, this, &ctxaddr); - if (dict_ret < 0) { - ctxaddr = 0; - } + if (dict_ret < 0) { + ctxaddr = 0; + } out: - return (clnt_fd_ctx_t *)(unsigned long)ctxaddr; + return (clnt_fd_ctx_t *)(unsigned long)ctxaddr; } - void -this_fd_set_ctx (fd_t *file, xlator_t *this, loc_t *loc, clnt_fd_ctx_t *ctx) +this_fd_set_ctx(fd_t *file, xlator_t *this, loc_t *loc, clnt_fd_ctx_t *ctx) { - uint64_t oldaddr = 0; - int32_t ret = -1; + uint64_t oldaddr = 0; + int32_t ret = -1; + + GF_VALIDATE_OR_GOTO("client", this, out); + GF_VALIDATE_OR_GOTO(this->name, file, out); + + ret = fd_ctx_get(file, this, &oldaddr); + if (ret >= 0) { + if (loc) + gf_smsg(this->name, GF_LOG_INFO, 0, PC_MSG_FD_DUPLICATE_TRY, + "path=%s", loc->path, "gfid=%s", + uuid_utoa(loc->inode->gfid), NULL); + else + gf_smsg(this->name, GF_LOG_INFO, 0, PC_MSG_FD_DUPLICATE_TRY, + "file=%p", file, NULL); + } + + ret = fd_ctx_set(file, this, (uint64_t)(unsigned long)ctx); + if (ret < 0) { + if (loc) + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FD_SET_FAIL, + "path=%s", loc->path, "gfid=%s", + uuid_utoa(loc->inode->gfid), NULL); + else + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FD_SET_FAIL, + "file=%p", file, NULL); + } +out: + return; +} - GF_VALIDATE_OR_GOTO ("client", this, out); - GF_VALIDATE_OR_GOTO (this->name, file, out); +int +client_local_wipe(clnt_local_t *local) +{ + if (local) { + loc_wipe(&local->loc); + loc_wipe(&local->loc2); - ret = fd_ctx_get (file, this, &oldaddr); - if (ret >= 0) { - gf_log (this->name, GF_LOG_DEBUG, - "%s (%"PRId64"): trying duplicate remote fd set. ", - loc->path, loc->inode->ino); + if (local->fd) { + fd_unref(local->fd); } - ret = fd_ctx_set (file, this, (uint64_t)(unsigned long)ctx); - if (ret < 0) { - gf_log (this->name, GF_LOG_DEBUG, - "%s (%"PRId64"): failed to set remote fd", - loc->path, loc->inode->ino); + if (local->iobref) { + iobref_unref(local->iobref); } + + GF_FREE(local->name); + mem_put(local); + } + + return 0; +} +int +unserialize_rsp_dirent(xlator_t *this, struct gfs3_readdir_rsp *rsp, + gf_dirent_t *entries) +{ + struct gfs3_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; + return ret; } +int +unserialize_rsp_direntp(xlator_t *this, fd_t *fd, struct gfs3_readdirp_rsp *rsp, + gf_dirent_t *entries) +{ + struct gfs3_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; + + gf_stat_to_iatt(&trav->stat, &entry->d_stat); + + strcpy(entry->d_name, trav->name); + + if (trav->dict.dict_val) { + entry->dict = dict_new(); + if (!entry->dict) + goto out; + + ret = dict_unserialize(trav->dict.dict_val, trav->dict.dict_len, + &entry->dict); + if (ret < 0) { + gf_smsg(THIS->name, GF_LOG_WARNING, EINVAL, + PC_MSG_DICT_UNSERIALIZE_FAIL, "xattr", NULL); + goto out; + } + } + + 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; + entry = NULL; + } + + ret = 0; +out: + if (entry) + gf_dirent_entry_free(entry); + return ret; +} int -client_local_wipe (clnt_local_t *local) +clnt_readdirp_rsp_cleanup(gfs3_readdirp_rsp *rsp) { - if (local) { - loc_wipe (&local->loc); + gfs3_dirplist *prev = NULL; + gfs3_dirplist *trav = NULL; + + trav = rsp->reply; + prev = trav; + while (trav) { + trav = trav->nextentry; + /* on client, the rpc lib allocates this */ + free(prev->dict.dict_val); + free(prev->name); + free(prev); + prev = trav; + } - if (local->fd) { - fd_unref (local->fd); - } + return 0; +} - if (local->iobref) { - iobref_unref (local->iobref); - } +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; - GF_FREE (local); - } + 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; - return 0; + 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_dirent (struct gfs3_readdir_rsp *rsp, gf_dirent_t *entries) +unserialize_rsp_direntp_v2(xlator_t *this, fd_t *fd, + struct gfx_readdirp_rsp *rsp, gf_dirent_t *entries) { - struct gfs3_dirlist *trav = NULL; - gf_dirent_t *entry = NULL; - int entry_len = 0; - int ret = -1; + 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; - 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; + trav = rsp->reply; - entry->d_ino = trav->d_ino; - entry->d_off = trav->d_off; - entry->d_len = trav->d_len; - entry->d_type = trav->d_type; + if (fd) + itable = fd->inode->table; - strcpy (entry->d_name, trav->name); + conf = this->private; + if (!conf) + goto out; - list_add_tail (&entry->list, &entries->list); + 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; +} - trav = trav->nextentry; +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; + gfs3_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 +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; + clnt_conf_t *conf = NULL; + gf_boolean_t locks_held = _gf_false; + + GF_VALIDATE_OR_GOTO(this->name, fd, out); + GF_VALIDATE_OR_GOTO(this->name, remote_fd, out); + + conf = this->private; + pthread_spin_lock(&conf->fd_lock); + { + fdctx = this_fd_get_ctx(fd, this); + if (!fdctx) { + if (fd->anonymous) { + *remote_fd = GF_ANON_FD_NO; + } else { + *remote_fd = -1; + gf_msg_debug(this->name, EBADF, "not a valid fd for gfid: %s", + uuid_utoa(fd->inode->gfid)); + } + } else { + if (__is_fd_reopen_in_progress(fdctx)) + *remote_fd = -1; + else + *remote_fd = fdctx->remote_fd; + + locks_held = !list_empty(&fdctx->lock_list); } + } + pthread_spin_unlock(&conf->fd_lock); + + if ((flags & FALLBACK_TO_ANON_FD) && (*remote_fd == -1) && (!locks_held)) + *remote_fd = GF_ANON_FD_NO; + + return 0; +out: + return -1; +} + +gf_boolean_t +client_is_reopen_needed(fd_t *fd, xlator_t *this, int64_t remote_fd) +{ + clnt_conf_t *conf = NULL; + clnt_fd_ctx_t *fdctx = NULL; + gf_boolean_t res = _gf_false; + + conf = this->private; + pthread_spin_lock(&conf->fd_lock); + { + fdctx = this_fd_get_ctx(fd, this); + if (fdctx && (fdctx->remote_fd == -1) && (remote_fd == GF_ANON_FD_NO)) + res = _gf_true; + } + pthread_spin_unlock(&conf->fd_lock); + + return res; +} + +int +client_fd_fop_prepare_local(call_frame_t *frame, fd_t *fd, int64_t remote_fd) +{ + xlator_t *this = NULL; + clnt_local_t *local = NULL; + int ret = 0; + + if (!frame || !fd) { + ret = -EINVAL; + goto out; + } + + this = frame->this; + + frame->local = mem_get0(this->local_pool); + if (frame->local == NULL) { + ret = -ENOMEM; + goto out; + } + + local = frame->local; + local->fd = fd_ref(fd); + local->attempt_reopen = client_is_reopen_needed(fd, this, remote_fd); - ret = 0; + return 0; out: - return ret; + return ret; +} + +void +clnt_getactivelk_rsp_cleanup(gfs3_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; + } } +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 -unserialize_rsp_direntp (struct gfs3_readdirp_rsp *rsp, gf_dirent_t *entries) +clnt_unserialize_rsp_locklist(xlator_t *this, struct gfs3_getactivelk_rsp *rsp, + lock_migration_info_t *lmi) { - struct gfs3_dirplist *trav = NULL; - gf_dirent_t *entry = NULL; - int entry_len = 0; - int ret = -1; + 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_smsg(this->name, GF_LOG_ERROR, 0, PC_MSG_NO_MEM, NULL); + goto out; + } - trav = rsp->reply; + INIT_LIST_HEAD(&temp->list); - 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; + gf_proto_flock_to_flock(&trav->flock, &temp->flock); - entry->d_ino = trav->d_ino; - entry->d_off = trav->d_off; - entry->d_len = trav->d_len; - entry->d_type = trav->d_type; + temp->lk_flags = trav->lk_flags; - gf_stat_to_iatt (&trav->stat, &entry->d_stat); + temp->client_uid = gf_strdup(trav->client_uid); - strcpy (entry->d_name, trav->name); + list_add_tail(&temp->list, &lmi->list); - list_add_tail (&entry->list, &entries->list); + trav = trav->nextentry; + } - trav = trav->nextentry; + ret = 0; +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_smsg(this->name, GF_LOG_ERROR, 0, PC_MSG_NO_MEM, NULL); + goto out; } - ret = 0; + 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; + return ret; +} + +void +clnt_setactivelk_req_cleanup(gfs3_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; + } +} + +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 -clnt_readdirp_rsp_cleanup (gfs3_readdirp_rsp *rsp) +serialize_req_locklist(lock_migration_info_t *locklist, + gfs3_setactivelk_req *req) { - gfs3_dirplist *prev = NULL; - gfs3_dirplist *trav = NULL; + 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_smsg(THIS->name, GF_LOG_ERROR, 0, PC_MSG_UNKNOWN_LOCK_TYPE, + "type=%" PRId32, tmp->flock.l_type, NULL); + break; + } - trav = rsp->reply; - prev = trav; - while (trav) { - trav = trav->nextentry; - /* on client, the rpc lib allocates this */ - free (prev->name); - free (prev); - prev = trav; + 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_smsg(THIS->name, GF_LOG_ERROR, 0, PC_MSG_CLIENT_UID_ALLOC_FAILED, + NULL); + ret = -1; + goto out; } - return 0; + if (prev) + prev->nextentry = trav; + else + req->request = trav; + + prev = trav; + trav = NULL; + } + + ret = 0; +out: + GF_FREE(trav); + + return ret; } int -clnt_readdir_rsp_cleanup (gfs3_readdir_rsp *rsp) +serialize_req_locklist_v2(lock_migration_info_t *locklist, + gfx_setactivelk_req *req) { - gfs3_dirlist *prev = NULL; - gfs3_dirlist *trav = NULL; + 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_smsg(THIS->name, GF_LOG_ERROR, 0, PC_MSG_UNKNOWN_LOCK_TYPE, + "type=%" PRId32, tmp->flock.l_type, NULL); + break; + } - trav = rsp->reply; - prev = trav; - while (trav) { - trav = trav->nextentry; - /* on client, the rpc lib allocates this */ - free (prev->name); - free (prev); - prev = trav; + 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_smsg(THIS->name, GF_LOG_ERROR, 0, PC_MSG_CLIENT_UID_ALLOC_FAILED, + NULL); + ret = -1; + goto out; } - return 0; + if (prev) + prev->nextentry = trav; + else + req->request = trav; + + prev = trav; + trav = NULL; + } + + ret = 0; +out: + GF_FREE(trav); + + return ret; +} + +extern int +client3_3_releasedir_cbk(struct rpc_req *req, struct iovec *iov, int count, + void *myframe); +extern int +client3_3_release_cbk(struct rpc_req *req, struct iovec *iov, int count, + void *myframe); +extern int +client4_0_releasedir_cbk(struct rpc_req *req, struct iovec *iov, int count, + void *myframe); +extern int +client4_0_release_cbk(struct rpc_req *req, struct iovec *iov, int count, + void *myframe); + +static int +send_release4_0_over_wire(xlator_t *this, clnt_fd_ctx_t *fdctx, + call_frame_t *fr) +{ + clnt_conf_t *conf = NULL; + conf = (clnt_conf_t *)this->private; + if (fdctx->is_dir) { + gfx_releasedir_req req = { + { + 0, + }, + }; + memcpy(req.gfid, fdctx->gfid, 16); + req.fd = fdctx->remote_fd; + + gf_msg_trace(this->name, 0, "sending releasedir on fd"); + (void)client_submit_request( + this, &req, fr, conf->fops, GFS3_OP_RELEASEDIR, + client4_0_releasedir_cbk, NULL, (xdrproc_t)xdr_gfx_releasedir_req); + } else { + gfx_release_req req = { + { + 0, + }, + }; + memcpy(req.gfid, fdctx->gfid, 16); + req.fd = fdctx->remote_fd; + gf_msg_trace(this->name, 0, "sending release on fd"); + (void)client_submit_request(this, &req, fr, conf->fops, GFS3_OP_RELEASE, + client4_0_release_cbk, NULL, + (xdrproc_t)xdr_gfx_release_req); + } + + return 0; +} + +static int +send_release3_3_over_wire(xlator_t *this, clnt_fd_ctx_t *fdctx, + call_frame_t *fr) +{ + clnt_conf_t *conf = NULL; + conf = (clnt_conf_t *)this->private; + if (fdctx->is_dir) { + gfs3_releasedir_req req = { + { + 0, + }, + }; + memcpy(req.gfid, fdctx->gfid, 16); + req.fd = fdctx->remote_fd; + gf_msg_trace(this->name, 0, "sending releasedir on fd"); + (void)client_submit_request( + this, &req, fr, conf->fops, GFS3_OP_RELEASEDIR, + client3_3_releasedir_cbk, NULL, (xdrproc_t)xdr_gfs3_releasedir_req); + } else { + gfs3_release_req req = { + { + 0, + }, + }; + memcpy(req.gfid, fdctx->gfid, 16); + req.fd = fdctx->remote_fd; + gf_msg_trace(this->name, 0, "sending release on fd"); + (void)client_submit_request(this, &req, fr, conf->fops, GFS3_OP_RELEASE, + client3_3_release_cbk, NULL, + (xdrproc_t)xdr_gfs3_release_req); + } + + return 0; +} + +int +client_fdctx_destroy(xlator_t *this, clnt_fd_ctx_t *fdctx) +{ + clnt_conf_t *conf = NULL; + call_frame_t *fr = NULL; + int32_t ret = -1; + char parent_down = 0; + fd_lk_ctx_t *lk_ctx = NULL; + + GF_VALIDATE_OR_GOTO("client", this, out); + GF_VALIDATE_OR_GOTO(this->name, fdctx, out); + + conf = (clnt_conf_t *)this->private; + + if (fdctx->remote_fd == -1) { + gf_msg_debug(this->name, 0, "not a valid fd"); + goto out; + } + + pthread_mutex_lock(&conf->lock); + { + parent_down = conf->parent_down; + } + pthread_mutex_unlock(&conf->lock); + lk_ctx = fdctx->lk_ctx; + fdctx->lk_ctx = NULL; + + if (lk_ctx) + fd_lk_ctx_unref(lk_ctx); + + if (!parent_down) + rpc_clnt_ref(conf->rpc); + else + goto out; + + fr = create_frame(this, this->ctx->pool); + if (fr == NULL) { + goto out; + } + + ret = 0; + + if (conf->fops->progver == GLUSTER_FOP_VERSION) + send_release3_3_over_wire(this, fdctx, fr); + else + send_release4_0_over_wire(this, fdctx, fr); + + rpc_clnt_unref(conf->rpc); +out: + if (fdctx) { + fdctx->remote_fd = -1; + GF_FREE(fdctx); + } + + return ret; } diff --git a/xlators/protocol/client/src/client-lk.c b/xlators/protocol/client/src/client-lk.c new file mode 100644 index 00000000000..795839734c5 --- /dev/null +++ b/xlators/protocol/client/src/client-lk.c @@ -0,0 +1,515 @@ +/* + 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 <glusterfs/common-utils.h> +#include <glusterfs/xlator.h> +#include "client.h" +#include <glusterfs/lkowner.h> +#include "client-messages.h" + +static void +__insert_and_merge(clnt_fd_ctx_t *fdctx, client_posix_lock_t *lock); + +static void +__dump_client_lock(client_posix_lock_t *lock) +{ + xlator_t *this = NULL; + + this = THIS; + + gf_smsg( + this->name, GF_LOG_INFO, 0, PC_MSG_CLIENT_LOCK_INFO, "fd=%p", lock->fd, + "fl_type=%s", lock->fl_type == F_WRLCK ? "Write-Lock" : "Read-Lock", + "lk-owner=%s", lkowner_utoa(&lock->owner), "l_start=%" PRId64, + lock->user_flock.l_start, "l_len=%" PRId64, lock->user_flock.l_len, + "start=%" PRId64, lock->fl_start, "end=%" PRId64, lock->fl_end, NULL); +} + +static int +dump_client_locks_fd(clnt_fd_ctx_t *fdctx) +{ + client_posix_lock_t *lock = NULL; + int count = 0; + + list_for_each_entry(lock, &fdctx->lock_list, list) + { + __dump_client_lock(lock); + count++; + } + + return count; +} + +int +dump_client_locks(inode_t *inode) +{ + fd_t *fd = NULL; + xlator_t *this = NULL; + clnt_fd_ctx_t *fdctx = NULL; + clnt_conf_t *conf = NULL; + + int total_count = 0; + int locks_fd_count = 0; + + this = THIS; + conf = this->private; + + LOCK(&inode->lock); + { + list_for_each_entry(fd, &inode->fd_list, inode_list) + { + locks_fd_count = 0; + + pthread_spin_lock(&conf->fd_lock); + fdctx = this_fd_get_ctx(fd, this); + if (fdctx) + locks_fd_count = dump_client_locks_fd(fdctx); + pthread_spin_unlock(&conf->fd_lock); + + total_count += locks_fd_count; + } + } + UNLOCK(&inode->lock); + + return total_count; +} + +static off_t +__get_lock_length(off_t start, off_t end) +{ + if (end == LLONG_MAX) + return 0; + else + return (end - start + 1); +} + +/* Add two locks */ +static client_posix_lock_t * +add_locks(client_posix_lock_t *l1, client_posix_lock_t *l2) +{ + client_posix_lock_t *sum = NULL; + + sum = GF_CALLOC(1, sizeof(*sum), gf_client_mt_clnt_lock_t); + if (!sum) + return NULL; + + sum->fl_start = min(l1->fl_start, l2->fl_start); + sum->fl_end = max(l1->fl_end, l2->fl_end); + + sum->user_flock.l_start = sum->fl_start; + sum->user_flock.l_len = __get_lock_length(sum->fl_start, sum->fl_end); + + return sum; +} + +/* Return true if the locks overlap, false otherwise */ +static int +locks_overlap(client_posix_lock_t *l1, client_posix_lock_t *l2) +{ + /* + Note: + FUSE always gives us absolute offsets, so no need to worry + about SEEK_CUR or SEEK_END + */ + + return ((l1->fl_end >= l2->fl_start) && (l2->fl_end >= l1->fl_start)); +} + +static void +__delete_client_lock(client_posix_lock_t *lock) +{ + list_del_init(&lock->list); +} + +/* Destroy a posix_lock */ +static void +__destroy_client_lock(client_posix_lock_t *lock) +{ + GF_FREE(lock); +} + +/* Subtract two locks */ +struct _values { + client_posix_lock_t *locks[3]; +}; + +/* {big} must always be contained inside {small} */ +static struct _values +subtract_locks(client_posix_lock_t *big, client_posix_lock_t *small) +{ + struct _values v = {.locks = {0, 0, 0}}; + + if ((big->fl_start == small->fl_start) && (big->fl_end == small->fl_end)) { + /* both edges coincide with big */ + v.locks[0] = GF_MALLOC(sizeof(client_posix_lock_t), + gf_client_mt_clnt_lock_t); + GF_ASSERT(v.locks[0]); + memcpy(v.locks[0], big, sizeof(client_posix_lock_t)); + v.locks[0]->fl_type = small->fl_type; + } else if ((small->fl_start > big->fl_start) && + (small->fl_end < big->fl_end)) { + /* both edges lie inside big */ + v.locks[0] = GF_MALLOC(sizeof(client_posix_lock_t), + gf_client_mt_clnt_lock_t); + GF_ASSERT(v.locks[0]); + memcpy(v.locks[0], big, sizeof(client_posix_lock_t)); + v.locks[0]->fl_end = small->fl_start - 1; + v.locks[0]->user_flock.l_len = __get_lock_length(v.locks[0]->fl_start, + v.locks[0]->fl_end); + v.locks[1] = GF_MALLOC(sizeof(client_posix_lock_t), + gf_client_mt_clnt_lock_t); + GF_ASSERT(v.locks[1]); + memcpy(v.locks[1], small, sizeof(client_posix_lock_t)); + v.locks[2] = GF_MALLOC(sizeof(client_posix_lock_t), + gf_client_mt_clnt_lock_t); + GF_ASSERT(v.locks[2]); + memcpy(v.locks[2], big, sizeof(client_posix_lock_t)); + v.locks[2]->fl_start = small->fl_end + 1; + v.locks[2]->user_flock.l_start = small->fl_end + 1; + } + /* one edge coincides with big */ + else if (small->fl_start == big->fl_start) { + v.locks[0] = GF_MALLOC(sizeof(client_posix_lock_t), + gf_client_mt_clnt_lock_t); + GF_ASSERT(v.locks[0]); + memcpy(v.locks[0], big, sizeof(client_posix_lock_t)); + v.locks[0]->fl_start = small->fl_end + 1; + v.locks[0]->user_flock.l_start = small->fl_end + 1; + v.locks[1] = GF_MALLOC(sizeof(client_posix_lock_t), + gf_client_mt_clnt_lock_t); + GF_ASSERT(v.locks[1]); + memcpy(v.locks[1], small, sizeof(client_posix_lock_t)); + } else if (small->fl_end == big->fl_end) { + v.locks[0] = GF_MALLOC(sizeof(client_posix_lock_t), + gf_client_mt_clnt_lock_t); + GF_ASSERT(v.locks[0]); + memcpy(v.locks[0], big, sizeof(client_posix_lock_t)); + v.locks[0]->fl_end = small->fl_start - 1; + v.locks[0]->user_flock.l_len = __get_lock_length(v.locks[0]->fl_start, + v.locks[0]->fl_end); + + v.locks[1] = GF_MALLOC(sizeof(client_posix_lock_t), + gf_client_mt_clnt_lock_t); + GF_ASSERT(v.locks[1]); + memcpy(v.locks[1], small, sizeof(client_posix_lock_t)); + } else { + /* LOG-TODO : decide what more info is required here*/ + gf_smsg("client-protocol", GF_LOG_CRITICAL, 0, PC_MSG_LOCK_ERROR, NULL); + } + + return v; +} + +static void +__delete_unlck_locks(clnt_fd_ctx_t *fdctx) +{ + client_posix_lock_t *l = NULL; + client_posix_lock_t *tmp = NULL; + + list_for_each_entry_safe(l, tmp, &fdctx->lock_list, list) + { + if (l->fl_type == F_UNLCK) { + __delete_client_lock(l); + __destroy_client_lock(l); + } + } +} + +static void +__insert_lock(clnt_fd_ctx_t *fdctx, client_posix_lock_t *lock) +{ + list_add_tail(&lock->list, &fdctx->lock_list); + + return; +} + +static void +__insert_and_merge(clnt_fd_ctx_t *fdctx, client_posix_lock_t *lock) +{ + client_posix_lock_t *conf = NULL; + client_posix_lock_t *t = NULL; + client_posix_lock_t *sum = NULL; + int i = 0; + struct _values v = {.locks = {0, 0, 0}}; + + list_for_each_entry_safe(conf, t, &fdctx->lock_list, list) + { + if (!locks_overlap(conf, lock)) + continue; + + if (is_same_lkowner(&conf->owner, &lock->owner)) { + if (conf->fl_type == lock->fl_type) { + sum = add_locks(lock, conf); + + sum->fd = lock->fd; + + __delete_client_lock(conf); + __destroy_client_lock(conf); + + __destroy_client_lock(lock); + __insert_and_merge(fdctx, sum); + + return; + } else { + sum = add_locks(lock, conf); + + sum->fd = conf->fd; + sum->owner = conf->owner; + + v = subtract_locks(sum, lock); + + __delete_client_lock(conf); + __destroy_client_lock(conf); + + __delete_client_lock(lock); + __destroy_client_lock(lock); + + __destroy_client_lock(sum); + + for (i = 0; i < 3; i++) { + if (!v.locks[i]) + continue; + + INIT_LIST_HEAD(&v.locks[i]->list); + __insert_and_merge(fdctx, v.locks[i]); + } + + __delete_unlck_locks(fdctx); + return; + } + } + + if (lock->fl_type == F_UNLCK) { + continue; + } + + if ((conf->fl_type == F_RDLCK) && (lock->fl_type == F_RDLCK)) { + __insert_lock(fdctx, lock); + return; + } + } + + /* no conflicts, so just insert */ + if (lock->fl_type != F_UNLCK) { + __insert_lock(fdctx, lock); + } else { + __destroy_client_lock(lock); + } +} + +static void +client_setlk(clnt_fd_ctx_t *fdctx, client_posix_lock_t *lock) +{ + __insert_and_merge(fdctx, lock); +} + +static void +destroy_client_lock(client_posix_lock_t *lock) +{ + GF_FREE(lock); +} + +int32_t +delete_granted_locks_owner(fd_t *fd, gf_lkowner_t *owner) +{ + clnt_fd_ctx_t *fdctx = NULL; + client_posix_lock_t *lock = NULL; + client_posix_lock_t *tmp = NULL; + xlator_t *this = NULL; + clnt_conf_t *conf = NULL; + + struct list_head delete_list; + int ret = 0; + int count = 0; + + INIT_LIST_HEAD(&delete_list); + this = THIS; + conf = this->private; + + pthread_spin_lock(&conf->fd_lock); + + fdctx = this_fd_get_ctx(fd, this); + if (!fdctx) { + pthread_spin_unlock(&conf->fd_lock); + + gf_smsg(this->name, GF_LOG_WARNING, EINVAL, PC_MSG_FD_CTX_INVALID, + NULL); + ret = -1; + goto out; + } + + list_for_each_entry_safe(lock, tmp, &fdctx->lock_list, list) + { + if (is_same_lkowner(&lock->owner, owner)) { + list_del_init(&lock->list); + list_add_tail(&lock->list, &delete_list); + count++; + } + } + + pthread_spin_unlock(&conf->fd_lock); + + if (!list_empty(&delete_list)) { + list_for_each_entry_safe(lock, tmp, &delete_list, list) + { + list_del_init(&lock->list); + destroy_client_lock(lock); + } + } + + /* FIXME: Need to actually print the locks instead of count */ + gf_msg_trace(this->name, 0, "Number of locks cleared=%d", count); + +out: + return ret; +} + +int32_t +client_cmd_to_gf_cmd(int32_t cmd, int32_t *gf_cmd) +{ + int ret = 0; + + 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 if (cmd == F_RESLK_LCK) + *gf_cmd = GF_LK_RESLK_LCK; + else if (cmd == F_RESLK_LCKW) + *gf_cmd = GF_LK_RESLK_LCKW; + else if (cmd == F_RESLK_UNLCK) + *gf_cmd = GF_LK_RESLK_UNLCK; + else if (cmd == F_GETLK_FD) + *gf_cmd = GF_LK_GETLK_FD; + else + ret = -1; + + return ret; +} + +static client_posix_lock_t * +new_client_lock(struct gf_flock *flock, gf_lkowner_t *owner, int32_t cmd, + fd_t *fd) +{ + client_posix_lock_t *new_lock = NULL; + + new_lock = GF_CALLOC(1, sizeof(*new_lock), gf_client_mt_clnt_lock_t); + if (!new_lock) { + goto out; + } + + INIT_LIST_HEAD(&new_lock->list); + new_lock->fd = fd; + memcpy(&new_lock->user_flock, flock, sizeof(struct gf_flock)); + + new_lock->fl_type = flock->l_type; + new_lock->fl_start = flock->l_start; + + if (flock->l_len == 0) + new_lock->fl_end = LLONG_MAX; + else + new_lock->fl_end = flock->l_start + flock->l_len - 1; + + new_lock->owner = *owner; + + new_lock->cmd = cmd; /* Not really useful */ + +out: + return new_lock; +} + +void +client_save_number_fds(clnt_conf_t *conf, int count) +{ + LOCK(&conf->rec_lock); + { + conf->reopen_fd_count = count; + } + UNLOCK(&conf->rec_lock); +} + +int +client_add_lock_for_recovery(fd_t *fd, struct gf_flock *flock, + gf_lkowner_t *owner, int32_t cmd) +{ + clnt_fd_ctx_t *fdctx = NULL; + xlator_t *this = NULL; + client_posix_lock_t *lock = NULL; + clnt_conf_t *conf = NULL; + + int ret = 0; + + this = THIS; + conf = this->private; + + pthread_spin_lock(&conf->fd_lock); + + fdctx = this_fd_get_ctx(fd, this); + if (!fdctx) { + pthread_spin_unlock(&conf->fd_lock); + + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FD_GET_FAIL, NULL); + ret = -EBADFD; + goto out; + } + + lock = new_client_lock(flock, owner, cmd, fd); + if (!lock) { + pthread_spin_unlock(&conf->fd_lock); + + ret = -ENOMEM; + goto out; + } + + client_setlk(fdctx, lock); + + pthread_spin_unlock(&conf->fd_lock); + +out: + return ret; +} + +int32_t +client_dump_locks(char *name, inode_t *inode, dict_t *dict) +{ + int ret = 0; + dict_t *new_dict = NULL; + char dict_string[256]; + + GF_ASSERT(dict); + new_dict = dict; + + ret = dump_client_locks(inode); + snprintf(dict_string, 256, "%d locks dumped in log file", ret); + + ret = dict_set_dynstr(new_dict, CLIENT_DUMP_LOCKS, dict_string); + if (ret) { + gf_smsg(THIS->name, GF_LOG_WARNING, 0, PC_MSG_DICT_SET_FAIL, "lock=%s", + CLIENT_DUMP_LOCKS, NULL); + goto out; + } + +out: + + return ret; +} + +int32_t +is_client_dump_locks_cmd(char *name) +{ + int ret = 0; + + if (strcmp(name, CLIENT_DUMP_LOCKS) == 0) + ret = 1; + + return ret; +} diff --git a/xlators/protocol/client/src/client-mem-types.h b/xlators/protocol/client/src/client-mem-types.h index 638e537d116..f61fa0c1828 100644 --- a/xlators/protocol/client/src/client-mem-types.h +++ b/xlators/protocol/client/src/client-mem-types.h @@ -1,33 +1,26 @@ /* - Copyright (c) 2010 Gluster, Inc. <http://www.gluster.com> - This file is part of GlusterFS. + Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.com> + This file is part of GlusterFS. - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. + 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. */ - #ifndef __CLIENT_MEM_TYPES_H__ #define __CLIENT_MEM_TYPES_H__ -#include "mem-types.h" +#include <glusterfs/mem-types.h> enum gf_client_mem_types_ { - gf_client_mt_clnt_conf_t = gf_common_mt_end + 1, - gf_client_mt_clnt_local_t, - gf_client_mt_clnt_req_buf_t, - gf_client_mt_clnt_fdctx_t, - gf_client_mt_end, + gf_client_mt_clnt_conf_t = gf_common_mt_end + 1, + gf_client_mt_clnt_req_buf_t, + gf_client_mt_clnt_fdctx_t, + gf_client_mt_clnt_lock_t, + gf_client_mt_clnt_fd_lk_local_t, + gf_client_mt_compound_req_t, + gf_client_mt_clnt_lock_request_t, + gf_client_mt_end, }; #endif /* __CLIENT_MEM_TYPES_H__ */ diff --git a/xlators/protocol/client/src/client-messages.h b/xlators/protocol/client/src/client-messages.h new file mode 100644 index 00000000000..25a851d80b9 --- /dev/null +++ b/xlators/protocol/client/src/client-messages.h @@ -0,0 +1,174 @@ +/* + Copyright (c) 2015 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. +*/ + +#ifndef _PC_MESSAGES_H__ +#define _PC_MESSAGES_H__ + +#include <glusterfs/glfs-message-id.h> + +/* To add new message IDs, append new identifiers at the end of the list. + * + * Never remove a message ID. If it's not used anymore, you can rename it or + * leave it as it is, but not delete it. This is to prevent reutilization of + * IDs by other messages. + * + * The component name must match one of the entries defined in + * glfs-message-id.h. + */ + +GLFS_MSGID( + PC, PC_MSG_TIMER_EXPIRED, PC_MSG_DIR_OP_FAILED, PC_MSG_FILE_OP_FAILED, + PC_MSG_TIMER_REG, PC_MSG_GRACE_TIMER_CANCELLED, PC_MSG_DICT_SET_FAILED, + PC_MSG_DICT_GET_FAILED, PC_MSG_NO_MEMORY, PC_MSG_RPC_CBK_FAILED, + PC_MSG_FUNCTION_CALL_ERROR, PC_MSG_RPC_INITED_ALREADY, PC_MSG_RPC_INIT, + PC_MSG_RPC_DESTROY, PC_MSG_RPC_INVALID_CALL, PC_MSG_INVALID_ENTRY, + PC_MSG_HANDSHAKE_RETURN, PC_MSG_CHILD_UP_NOTIFY_FAILED, + PC_MSG_CLIENT_DISCONNECTED, PC_MSG_CHILD_DOWN_NOTIFY_FAILED, + PC_MSG_PARENT_UP, PC_MSG_PARENT_DOWN, PC_MSG_RPC_INIT_FAILED, + PC_MSG_RPC_NOTIFY_FAILED, PC_MSG_FD_DUPLICATE_TRY, PC_MSG_FD_SET_FAIL, + PC_MSG_DICT_UNSERIALIZE_FAIL, PC_MSG_FD_GET_FAIL, PC_MSG_FD_CTX_INVALID, + PC_MSG_FOP_SEND_FAILED, PC_MSG_XDR_DECODING_FAILED, PC_MSG_REMOTE_OP_FAILED, + PC_MSG_RPC_STATUS_ERROR, PC_MSG_VOL_FILE_NOT_FOUND, PC_MSG_SEND_REQ_FAIL, + PC_MSG_LOCK_VERSION_SERVER, PC_MSG_SET_LK_VERSION_ERROR, + PC_MSG_LOCK_REQ_FAIL, PC_MSG_CLIENT_REQ_FAIL, PC_MSG_LOCK_ERROR, + PC_MSG_LOCK_REACQUIRE, PC_MSG_CHILD_UP_NOTIFY, PC_MSG_CHILD_UP_NOTIFY_DELAY, + PC_MSG_VOL_SET_FAIL, PC_MSG_SETVOLUME_FAIL, PC_MSG_VOLFILE_NOTIFY_FAILED, + PC_MSG_REMOTE_VOL_CONNECTED, PC_MSG_LOCK_MISMATCH, PC_MSG_LOCK_MATCH, + PC_MSG_AUTH_FAILED, PC_MSG_AUTH_FAILED_NOTIFY_FAILED, + PC_MSG_CHILD_CONNECTING_EVENT, PC_MSG_CHILD_CONNECTING_NOTIFY_FAILED, + PC_MSG_PROCESS_UUID_SET_FAIL, PC_MSG_DICT_ERROR, PC_MSG_DICT_SERIALIZE_FAIL, + PC_MSG_PGM_NOT_FOUND, PC_MSG_VERSION_INFO, PC_MSG_PORT_NUM_ERROR, + PC_MSG_VERSION_ERROR, PC_MSG_DIR_OP_SUCCESS, PC_MSG_BAD_FD, + PC_MSG_CLIENT_LOCK_INFO, PC_MSG_CACHE_INVALIDATION_FAIL, + PC_MSG_CHILD_STATUS, PC_MSG_GFID_NULL, PC_MSG_RECALL_LEASE_FAIL, + PC_MSG_INODELK_CONTENTION_FAIL, PC_MSG_ENTRYLK_CONTENTION_FAIL, + PC_MSG_BIGGER_SIZE, PC_MSG_CLIENT_DUMP_LOCKS_FAILED, PC_MSG_UNKNOWN_CMD, + PC_MSG_REOPEN_FAILED, PC_MSG_FIND_KEY_FAILED, PC_MSG_VOL_ID_CHANGED, + PC_MSG_GETHOSTNAME_FAILED, PC_MSG_VOLFILE_KEY_SET_FAILED, + PC_MSG_VOLFILE_CHECKSUM_FAILED, PC_MSG_FRAME_NOT_FOUND, + PC_MSG_REMOTE_SUBVOL_SET_FAIL, PC_MSG_HANDSHAKE_PGM_NOT_FOUND, + PC_MSG_MERGE_IOBREF_FAILED, PC_MSG_ADD_IOBUF_FAILED, + PC_MSG_RELEASE_DIR_OP_FAILED, PC_MSG_REMOTE_HOST_SET_FAILED, + PC_MSG_REMOTE_PORT_SET_FAILED, PC_MSG_REMOTE_HOST_NOT_SET, + PC_MSG_NOREMOTE_HOST, PC_MSG_REMOTE_SUBVOL_NOT_GIVEN, + PC_MSG_FATAL_CLIENT_PROTOCOL, PC_MSG_VOL_DANGLING, + PC_MSG_CREATE_MEM_POOL_FAILED, PC_MSG_PVT_XLATOR_NULL, PC_MSG_XLATOR_NULL, + PC_MSG_LEASE_FOP_FAILED, PC_MSG_DICT_SET_FAIL, PC_MSG_NO_MEM, + PC_MSG_UNKNOWN_LOCK_TYPE, PC_MSG_CLIENT_UID_ALLOC_FAILED); + +#define PC_MSG_REMOTE_OP_FAILED_STR "remote operation failed." +#define PC_MSG_XDR_DECODING_FAILED_STR "XDR decoding failed" +#define PC_MSG_FOP_SEND_FAILED_STR "failed to send the fop" +#define PC_MSG_BIGGER_SIZE_STR "read-size is bigger than iobuf isze" +#define PC_MSG_CLIENT_DUMP_LOCKS_FAILED_STR "client dump locks failed" +#define PC_MSG_UNKNOWN_CMD_STR "Unknown cmd" +#define PC_MSG_CHILD_UP_NOTIFY_FAILED_STR "notify of CHILD_UP failed" +#define PC_MSG_CHILD_STATUS_STR \ + "Defering sending CHILD_UP message as the client translators are not yet " \ + "ready to serve" +#define PC_MSG_CHILD_UP_NOTIFY_STR "last fd open'd - notifying CHILD_UP" +#define PC_MSG_RPC_STATUS_ERROR_STR \ + "received RPC status error, returning ENOTCONN" +#define PC_MSG_REOPEN_FAILED_STR "reopen failed" +#define PC_MSG_DIR_OP_SUCCESS_STR "reopen dir succeeded" +#define PC_MSG_DIR_OP_FAILED_STR "failed to send the re-opendir request" +#define PC_MSG_CHILD_UP_NOTIFY_DELAY_STR \ + "fds open - Delaying child_up until they are re-opened" +#define PC_MSG_VOL_SET_FAIL_STR "failed to set the volume" +#define PC_MSG_DICT_UNSERIALIZE_FAIL_STR "failed to unserialize buffer to dict" +#define PC_MSG_DICT_GET_FAILED_STR "failed to get from reply dict" +#define PC_MSG_SETVOLUME_FAIL_STR "SETVOLUME on remote-host failed" +#define PC_MSG_VOLFILE_NOTIFY_FAILED_STR "notify of VOLFILE_MODIFIED failed" +#define PC_MSG_FIND_KEY_FAILED_STR "failed to find key in the options" +#define PC_MSG_VOL_ID_CHANGED_STR \ + "volume-id changed, can't connect to server. Needs remount" +#define PC_MSG_REMOTE_VOL_CONNECTED_STR "Connected, attached to remote volume" +#define PC_MSG_AUTH_FAILED_STR "sending AUTH_FAILED event" +#define PC_MSG_AUTH_FAILED_NOTIFY_FAILED_STR "notify of AUTH_FAILED failed" +#define PC_MSG_CHILD_CONNECTING_EVENT_STR "sending CHILD_CONNECTING event" +#define PC_MSG_CHILD_CONNECTING_NOTIFY_FAILED_STR \ + "notify of CHILD_CONNECTING failed" +#define PC_MSG_DICT_SET_FAILED_STR "failed to set in handshake msg" +#define PC_MSG_GETHOSTNAME_FAILED_STR "gethostname: failed" +#define PC_MSG_PROCESS_UUID_SET_FAIL_STR \ + "asprintf failed while setting process_uuid" +#define PC_MSG_VOLFILE_KEY_SET_FAILED_STR "failed to set volfile-key" +#define PC_MSG_VOLFILE_CHECKSUM_FAILED_STR "failed to set volfile-checksum" +#define PC_MSG_DICT_SERIALIZE_FAIL_STR "failed to serialize dictionary" +#define PC_MSG_PGM_NOT_FOUND_STR "xlator not found OR RPC program not found" +#define PC_MSG_VERSION_INFO_STR "Using Program" +#define PC_MSG_FRAME_NOT_FOUND_STR "frame not found with rpc request" +#define PC_MSG_PORT_NUM_ERROR_STR \ + "failed to get the port number for remote subvolume. Please run gluster " \ + "volume status on server to see if brick process is running" +#define PC_MSG_REMOTE_SUBVOL_SET_FAIL_STR "remote-subvolume not set in volfile" +#define PC_MSG_VERSION_ERROR_STR "failed to get the version from server" +#define PC_MSG_NO_VERSION_SUPPORT_STR "server doesn't support the version" +#define PC_MSG_HANDSHAKE_PGM_NOT_FOUND_STR "handshake program not found" +#define PC_MSG_MERGE_IOBREF_FAILED_STR \ + "cannot merge iobref passed from caller into new_iobref" +#define PC_MSG_ADD_IOBUF_FAILED_STR "cannot add iobuf into iobref" +#define PC_MSG_RELEASE_DIR_OP_FAILED_STR "release dir op failed" +#define PC_MSG_FILE_OP_FAILED_STR "release fop failed" +#define PC_MSG_REMOTE_HOST_SET_FAILED_STR "failed to set remote-host" +#define PC_MSG_REMOTE_PORT_SET_FAILED_STR "failed to set remote-port" +#define PC_MSG_RPC_INIT_STR "client rpc init command" +#define PC_MSG_RPC_DESTROY_STR "client rpc destroy command" +#define PC_MSG_HANDSHAKE_RETURN_STR "handshake msg returned" +#define PC_MSG_CLIENT_DISCONNECTED_STR \ + "disconnected from client, process will keep trying to connect glusterd " \ + "until brick's port is available" +#define PC_MSG_CHILD_DOWN_NOTIFY_FAILED_STR "CHILD_DOWN notify failed" +#define PC_MSG_PARENT_UP_STR \ + "parent translators are ready, attempting connect on transport" +#define PC_MSG_PARENT_DOWN_STR \ + "current graph is no longer active, destroying rpc_client" +#define PC_MSG_REMOTE_HOST_NOT_SET_STR \ + "Remote host is not set. Assuming the volfile server as remote host" +#define PC_MSG_NOREMOTE_HOST_STR "No remote host to connect" +#define PC_MSG_REMOTE_SUBVOL_NOT_GIVEN_STR "option 'remote-subvolume' not given" +#define PC_MSG_NO_MEMORY_STR "Memory accounting init failed" +#define PC_MSG_RPC_INVALID_CALL_STR \ + "RPC destroy called on already destroyed connection" +#define PC_MSG_RPC_INITED_ALREADY_STR "client rpc already init'ed" +#define PC_MSG_RPC_INIT_FAILED_STR "failed to initialize RPC" +#define PC_MSG_RPC_NOTIFY_FAILED_STR "failed to register notify" +#define PC_MSG_RPC_CBK_FAILED_STR "failed to reister callback program" +#define PC_MSG_FATAL_CLIENT_PROTOCOL_STR \ + "FATAL: client protocol, translator cannot have any subvolumes" +#define PC_MSG_VOL_DANGLING_STR "Volume is dangling" +#define PC_MSG_CREATE_MEM_POOL_FAILED_STR \ + "failed to create local_t's memory pool" +#define PC_MSG_XLATOR_NULL_STR "xlator is NULL" +#define PC_MSG_PVT_XLATOR_NULL_STR "private structure of the xlator is NULL" +#define PC_MSG_LEASE_FOP_FAILED_STR "Lease fop failed" +#define PC_MSG_LOCK_ERROR_STR \ + "Unexpected case in subtract_locks. Please send a bug report to " \ + "gluster-devel@gluster.org" +#define PC_MSG_FD_CTX_INVALID_STR "fdctx not valid" +#define PC_MSG_FD_GET_FAIL_STR "failed to get fd context. sending EBADFD" +#define PC_MSG_DICT_SET_FAIL_STR "could not set dict" +#define PC_MSG_CLIENT_LOCK_INFO_STR "client lock info" +#define PC_MSG_BAD_FD_STR "remote_fd is -1. EBADFD" +#define PC_MSG_FUNCTION_CALL_ERROR_STR "this function should not be called" +#define PC_MSG_RECALL_LEASE_FAIL_STR "XDR decode of recall lease failed" +#define PC_MSG_CACHE_INVALIDATION_FAIL_STR \ + "XDR decode of cache_invalidation failed" +#define PC_MSG_INODELK_CONTENTION_FAIL_STR \ + "XDR decode of inodelk contention failed" +#define PC_MSG_ENTRYLK_CONTENTION_FAIL_STR \ + "XDR decode of entrylk contention failed" +#define PC_MSG_FD_DUPLICATE_TRY_STR "trying duplicate remote fd set" +#define PC_MSG_FD_SET_FAIL_STR "failed to set remote-fd" +#define PC_MSG_NO_MEM_STR "No memory" +#define PC_MSG_UNKNOWN_LOCK_TYPE_STR "Unknown lock type" +#define PC_MSG_CLIENT_UID_ALLOC_FAILED_STR "client-uid could not be allocated" + +#endif /* !_PC_MESSAGES_H__ */ diff --git a/xlators/protocol/client/src/client-rpc-fops.c b/xlators/protocol/client/src/client-rpc-fops.c new file mode 100644 index 00000000000..f402121c15b --- /dev/null +++ b/xlators/protocol/client/src/client-rpc-fops.c @@ -0,0 +1,6079 @@ +/* + 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 "glusterfs3-xdr.h" +#include "glusterfs3.h" +#include <glusterfs/compat-errno.h> +#include "client-messages.h" +#include <glusterfs/defaults.h> +#include "client-common.h" + +int32_t +client3_getspec(call_frame_t *frame, xlator_t *this, void *data); +rpc_clnt_prog_t clnt3_3_fop_prog; + +int +client_is_setlk(int32_t cmd) +{ + if ((cmd == F_SETLK) || (cmd == F_SETLK64) || (cmd == F_SETLKW) || + (cmd == F_SETLKW64)) { + return 1; + } + + return 0; +} + +/* CBK */ +int +client3_3_symlink_cbk(struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + gfs3_symlink_rsp rsp = { + 0, + }; + struct iatt stbuf = { + 0, + }; + struct iatt preparent = { + 0, + }; + struct iatt postparent = { + 0, + }; + int ret = 0; + clnt_local_t *local = NULL; + inode_t *inode = NULL; + xlator_t *this = NULL; + dict_t *xdata = NULL; + + this = THIS; + + frame = myframe; + + local = frame->local; + inode = local->loc.inode; + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + rsp.op_errno = ENOTCONN; + goto out; + } + ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gfs3_symlink_rsp); + if (ret < 0) { + gf_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + ret = client_post_symlink(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_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, "loc1=%s", local->loc.path, + "loc2=%s", local->loc2.path, NULL); + } + } + + CLIENT_STACK_UNWIND(symlink, frame, rsp.op_ret, + gf_error_to_errno(rsp.op_errno), inode, &stbuf, + &preparent, &postparent, xdata); + + free(rsp.xdata.xdata_val); + + if (xdata) + dict_unref(xdata); + + return 0; +} + +int +client3_3_mknod_cbk(struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + gfs3_mknod_rsp rsp = { + 0, + }; + struct iatt stbuf = { + 0, + }; + struct iatt preparent = { + 0, + }; + struct iatt postparent = { + 0, + }; + int ret = 0; + clnt_local_t *local = NULL; + inode_t *inode = NULL; + xlator_t *this = NULL; + dict_t *xdata = NULL; + + this = THIS; + + frame = myframe; + + local = frame->local; + + inode = local->loc.inode; + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + rsp.op_errno = ENOTCONN; + goto out; + } + ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gfs3_mknod_rsp); + if (ret < 0) { + gf_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + ret = client_post_mknod(this, &rsp, &stbuf, &preparent, &postparent, + &xdata); + +out: + if (rsp.op_ret == -1 && + GF_IGNORE_IF_GSYNCD_SAFE_ERROR(frame, rsp.op_errno)) { + gf_smsg(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, + "path=%s", local->loc.path, NULL); + } + + CLIENT_STACK_UNWIND(mknod, frame, rsp.op_ret, + gf_error_to_errno(rsp.op_errno), inode, &stbuf, + &preparent, &postparent, xdata); + + free(rsp.xdata.xdata_val); + + if (xdata) + dict_unref(xdata); + + return 0; +} + +int +client3_3_mkdir_cbk(struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + gfs3_mkdir_rsp rsp = { + 0, + }; + struct iatt stbuf = { + 0, + }; + struct iatt preparent = { + 0, + }; + struct iatt postparent = { + 0, + }; + int ret = 0; + clnt_local_t *local = NULL; + inode_t *inode = NULL; + xlator_t *this = NULL; + dict_t *xdata = NULL; + + this = THIS; + + frame = myframe; + + local = frame->local; + inode = local->loc.inode; + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + rsp.op_errno = ENOTCONN; + goto out; + } + ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gfs3_mkdir_rsp); + if (ret < 0) { + gf_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + ret = client_post_mkdir(this, &rsp, &stbuf, &preparent, &postparent, + &xdata); + +out: + if (rsp.op_ret == -1 && + GF_IGNORE_IF_GSYNCD_SAFE_ERROR(frame, rsp.op_errno)) { + gf_smsg(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, + "Path=%s", local->loc.path, NULL); + } + + CLIENT_STACK_UNWIND(mkdir, frame, rsp.op_ret, + gf_error_to_errno(rsp.op_errno), inode, &stbuf, + &preparent, &postparent, xdata); + + free(rsp.xdata.xdata_val); + + if (xdata) + dict_unref(xdata); + + return 0; +} + +int +_copy_gfid_from_inode_holders(uuid_t gfid, loc_t *loc, fd_t *fd) +{ + int ret = 0; + + if (fd && fd->inode && !gf_uuid_is_null(fd->inode->gfid)) { + gf_uuid_copy(gfid, fd->inode->gfid); + goto out; + } + + if (!loc) { + GF_ASSERT(0); + ret = -1; + goto out; + } + + if (loc->inode && !gf_uuid_is_null(loc->inode->gfid)) { + gf_uuid_copy(gfid, loc->inode->gfid); + } else if (!gf_uuid_is_null(loc->gfid)) { + gf_uuid_copy(gfid, loc->gfid); + } else { + GF_ASSERT(0); + ret = -1; + } +out: + return ret; +} + +int +client_add_fd_to_saved_fds(xlator_t *this, fd_t *fd, loc_t *loc, int32_t flags, + int64_t remote_fd, int is_dir) +{ + int ret = 0; + uuid_t gfid = {0}; + clnt_conf_t *conf = NULL; + clnt_fd_ctx_t *fdctx = NULL; + + conf = this->private; + ret = _copy_gfid_from_inode_holders(gfid, loc, fd); + if (ret) { + ret = -EINVAL; + goto out; + } + + fdctx = GF_CALLOC(1, sizeof(*fdctx), gf_client_mt_clnt_fdctx_t); + if (!fdctx) { + ret = -ENOMEM; + goto out; + } + + gf_uuid_copy(fdctx->gfid, gfid); + fdctx->is_dir = is_dir; + fdctx->remote_fd = remote_fd; + fdctx->flags = flags; + fdctx->lk_ctx = fd_lk_ctx_ref(fd->lk_ctx); + fdctx->reopen_done = client_default_reopen_done; + + INIT_LIST_HEAD(&fdctx->sfd_pos); + INIT_LIST_HEAD(&fdctx->lock_list); + + pthread_spin_lock(&conf->fd_lock); + { + this_fd_set_ctx(fd, this, loc, fdctx); + + list_add_tail(&fdctx->sfd_pos, &conf->saved_fds); + } + pthread_spin_unlock(&conf->fd_lock); +out: + return ret; +} + +int +client3_3_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; + gfs3_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_gfs3_open_rsp); + if (ret < 0) { + gf_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + 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 = client_post_open(this, &rsp, &xdata); +out: + if (rsp.op_ret == -1) { + gf_smsg(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, + "Path=%s", local->loc.path, "gfid=%s", + loc_gfid_utoa(&local->loc), NULL); + } + + CLIENT_STACK_UNWIND(open, frame, rsp.op_ret, + gf_error_to_errno(rsp.op_errno), fd, xdata); + + free(rsp.xdata.xdata_val); + + if (xdata) + dict_unref(xdata); + + return 0; +} + +int +client3_3_stat_cbk(struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + gfs3_stat_rsp rsp = { + 0, + }; + call_frame_t *frame = NULL; + struct iatt iatt = { + 0, + }; + int ret = 0; + xlator_t *this = NULL; + dict_t *xdata = NULL; + + this = THIS; + + frame = myframe; + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + rsp.op_errno = ENOTCONN; + goto out; + } + ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gfs3_stat_rsp); + if (ret < 0) { + gf_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + ret = client_post_stat(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_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, NULL); + } + } + + CLIENT_STACK_UNWIND(stat, frame, rsp.op_ret, + gf_error_to_errno(rsp.op_errno), &iatt, xdata); + + free(rsp.xdata.xdata_val); + + if (xdata) + dict_unref(xdata); + + return 0; +} + +int +client3_3_readlink_cbk(struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + gfs3_readlink_rsp rsp = { + 0, + }; + call_frame_t *frame = NULL; + struct iatt iatt = { + 0, + }; + int ret = 0; + xlator_t *this = NULL; + dict_t *xdata = NULL; + + this = THIS; + + frame = myframe; + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + rsp.op_errno = ENOTCONN; + goto out; + } + ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gfs3_readlink_rsp); + if (ret < 0) { + gf_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + ret = client_post_readlink(this, &rsp, &iatt, &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_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, NULL); + } + } + + 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); + + free(rsp.xdata.xdata_val); + + if (xdata) + dict_unref(xdata); + + return 0; +} + +int +client3_3_unlink_cbk(struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + gfs3_unlink_rsp rsp = { + 0, + }; + struct iatt preparent = { + 0, + }; + struct iatt postparent = { + 0, + }; + int ret = 0; + xlator_t *this = NULL; + dict_t *xdata = NULL; + + this = THIS; + + frame = myframe; + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + rsp.op_errno = ENOTCONN; + goto out; + } + ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gfs3_unlink_rsp); + if (ret < 0) { + gf_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + ret = client_post_unlink(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_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, NULL); + } + } + + CLIENT_STACK_UNWIND(unlink, frame, rsp.op_ret, + gf_error_to_errno(rsp.op_errno), &preparent, + &postparent, xdata); + + free(rsp.xdata.xdata_val); + + if (xdata) + dict_unref(xdata); + + return 0; +} + +int +client3_3_rmdir_cbk(struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + gfs3_rmdir_rsp rsp = { + 0, + }; + call_frame_t *frame = NULL; + struct iatt preparent = { + 0, + }; + struct iatt postparent = { + 0, + }; + int ret = 0; + xlator_t *this = NULL; + dict_t *xdata = NULL; + + this = THIS; + + frame = myframe; + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + rsp.op_errno = ENOTCONN; + goto out; + } + ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gfs3_rmdir_rsp); + if (ret < 0) { + gf_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + ret = client_post_rmdir(this, &rsp, &preparent, &postparent, &xdata); + +out: + if (rsp.op_ret == -1) { + if (GF_IGNORE_IF_GSYNCD_SAFE_ERROR(frame, rsp.op_errno)) { + gf_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, NULL); + } + } + CLIENT_STACK_UNWIND(rmdir, frame, rsp.op_ret, + gf_error_to_errno(rsp.op_errno), &preparent, + &postparent, xdata); + + free(rsp.xdata.xdata_val); + + if (xdata) + dict_unref(xdata); + + return 0; +} + +int +client3_3_truncate_cbk(struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + gfs3_truncate_rsp rsp = { + 0, + }; + call_frame_t *frame = NULL; + struct iatt prestat = { + 0, + }; + struct iatt poststat = { + 0, + }; + int ret = 0; + xlator_t *this = NULL; + dict_t *xdata = NULL; + + this = THIS; + + frame = myframe; + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + rsp.op_errno = ENOTCONN; + goto out; + } + ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gfs3_truncate_rsp); + if (ret < 0) { + gf_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + ret = client_post_truncate(this, &rsp, &prestat, &poststat, &xdata); + +out: + if (rsp.op_ret == -1) { + gf_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, NULL); + } + CLIENT_STACK_UNWIND(truncate, frame, rsp.op_ret, + gf_error_to_errno(rsp.op_errno), &prestat, &poststat, + xdata); + + free(rsp.xdata.xdata_val); + + if (xdata) + dict_unref(xdata); + + return 0; +} + +int +client3_3_statfs_cbk(struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + gfs3_statfs_rsp rsp = { + 0, + }; + call_frame_t *frame = NULL; + struct statvfs statfs = { + 0, + }; + int ret = 0; + xlator_t *this = NULL; + dict_t *xdata = NULL; + + this = THIS; + + frame = myframe; + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + rsp.op_errno = ENOTCONN; + goto out; + } + ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gfs3_statfs_rsp); + if (ret < 0) { + gf_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + ret = client_post_statfs(this, &rsp, &statfs, &xdata); + +out: + if (rsp.op_ret == -1) { + gf_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, NULL); + } + CLIENT_STACK_UNWIND(statfs, frame, rsp.op_ret, + gf_error_to_errno(rsp.op_errno), &statfs, xdata); + + free(rsp.xdata.xdata_val); + + if (xdata) + dict_unref(xdata); + + return 0; +} + +int +client3_3_writev_cbk(struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + gfs3_write_rsp rsp = { + 0, + }; + call_frame_t *frame = NULL; + struct iatt prestat = { + 0, + }; + struct iatt poststat = { + 0, + }; + int ret = 0; + xlator_t *this = NULL; + dict_t *xdata = NULL; + 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_gfs3_write_rsp); + if (ret < 0) { + gf_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + ret = client_post_writev(this, &rsp, &prestat, &poststat, &xdata); + if (ret < 0) + goto out; +out: + if (rsp.op_ret == -1) { + gf_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, NULL); + } 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); + + free(rsp.xdata.xdata_val); + + if (xdata) + dict_unref(xdata); + + return 0; +} + +int +client3_3_flush_cbk(struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + clnt_local_t *local = NULL; + xlator_t *this = NULL; + dict_t *xdata = NULL; + + gf_common_rsp rsp = { + 0, + }; + int ret = 0; + + frame = myframe; + this = THIS; + local = frame->local; + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + rsp.op_errno = ENOTCONN; + goto out; + } + ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gf_common_rsp); + if (ret < 0) { + gf_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + if ((rsp.op_ret >= 0 || (rsp.op_errno == ENOTCONN)) && + !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); + } + + ret = client_post_flush(this, &rsp, &xdata); + +out: + if (rsp.op_ret == -1) { + gf_smsg(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, NULL); + } + CLIENT_STACK_UNWIND(flush, frame, rsp.op_ret, + gf_error_to_errno(rsp.op_errno), xdata); + + free(rsp.xdata.xdata_val); + + if (xdata) + dict_unref(xdata); + + return 0; +} + +int +client3_3_fsync_cbk(struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + gfs3_fsync_rsp rsp = { + 0, + }; + call_frame_t *frame = NULL; + struct iatt prestat = { + 0, + }; + struct iatt poststat = { + 0, + }; + int ret = 0; + xlator_t *this = NULL; + dict_t *xdata = NULL; + + this = THIS; + + frame = myframe; + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + rsp.op_errno = ENOTCONN; + goto out; + } + + ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gfs3_fsync_rsp); + if (ret < 0) { + gf_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + ret = client_post_fsync(this, &rsp, &prestat, &poststat, &xdata); + if (ret < 0) + goto out; + +out: + if (rsp.op_ret == -1) { + gf_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, NULL); + } + CLIENT_STACK_UNWIND(fsync, frame, rsp.op_ret, + gf_error_to_errno(rsp.op_errno), &prestat, &poststat, + xdata); + + free(rsp.xdata.xdata_val); + + if (xdata) + dict_unref(xdata); + + return 0; +} + +int +client3_3_setxattr_cbk(struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + gf_common_rsp rsp = { + 0, + }; + int ret = 0; + xlator_t *this = NULL; + dict_t *xdata = NULL; + 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_gf_common_rsp); + if (ret < 0) { + gf_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + ret = client_post_setxattr(this, &rsp, &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_smsg(this->name, GF_LOG_WARNING, op_errno, + PC_MSG_REMOTE_OP_FAILED, NULL); + } + } + + CLIENT_STACK_UNWIND(setxattr, frame, rsp.op_ret, op_errno, xdata); + + free(rsp.xdata.xdata_val); + + if (xdata) + dict_unref(xdata); + + return 0; +} + +int +client3_3_getxattr_cbk(struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + dict_t *dict = NULL; + int op_errno = EINVAL; + gfs3_getxattr_rsp rsp = { + 0, + }; + int ret = 0; + clnt_local_t *local = NULL; + xlator_t *this = NULL; + dict_t *xdata = NULL; + + this = THIS; + + frame = myframe; + local = frame->local; + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + op_errno = ENOTCONN; + goto out; + } + + ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gfs3_getxattr_rsp); + if (ret < 0) { + gf_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + rsp.op_ret = -1; + op_errno = EINVAL; + goto out; + } + + op_errno = gf_error_to_errno(rsp.op_errno); + ret = client_post_getxattr(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_smsg(this->name, GF_LOG_WARNING, op_errno, + PC_MSG_REMOTE_OP_FAILED, "Path=%s", local->loc.path, + "gfid=%s", loc_gfid_utoa(&local->loc), "Key=%s", + (local->name) ? local->name : "(null)", NULL); + } + } + + CLIENT_STACK_UNWIND(getxattr, frame, rsp.op_ret, op_errno, dict, xdata); + + /* don't use GF_FREE, this memory was allocated by libc */ + free(rsp.dict.dict_val); + + free(rsp.xdata.xdata_val); + + if (xdata) + dict_unref(xdata); + + if (dict) + dict_unref(dict); + + return 0; +} + +int +client3_3_fgetxattr_cbk(struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + dict_t *dict = NULL; + gfs3_fgetxattr_rsp rsp = { + 0, + }; + int ret = 0; + int op_errno = EINVAL; + 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_gfs3_fgetxattr_rsp); + if (ret < 0) { + gf_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + rsp.op_ret = -1; + op_errno = EINVAL; + goto out; + } + + op_errno = gf_error_to_errno(rsp.op_errno); + ret = client_post_fgetxattr(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_smsg(this->name, GF_LOG_WARNING, op_errno, + PC_MSG_REMOTE_OP_FAILED, NULL); + } + } + + CLIENT_STACK_UNWIND(fgetxattr, frame, rsp.op_ret, op_errno, dict, xdata); + + free(rsp.dict.dict_val); + + free(rsp.xdata.xdata_val); + + if (xdata) + dict_unref(xdata); + + if (dict) + dict_unref(dict); + + return 0; +} + +int +client3_3_removexattr_cbk(struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + gf_common_rsp rsp = { + 0, + }; + int ret = 0; + xlator_t *this = NULL; + dict_t *xdata = NULL; + 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_gf_common_rsp); + if (ret < 0) { + gf_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + ret = client_post_removexattr(this, &rsp, &xdata); +out: + if (rsp.op_ret == -1) { + /* EPERM/EACCESS is returned some times in case of selinux + attributes, or other system attributes which may not be + possible to remove from an user process is encountered. + we can't treat it as an error */ + if ((ENODATA == rsp.op_errno) || (ENOATTR == rsp.op_errno) || + (EPERM == rsp.op_errno) || (EACCES == rsp.op_errno)) + loglevel = GF_LOG_DEBUG; + else + loglevel = GF_LOG_WARNING; + + gf_smsg(this->name, loglevel, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, NULL); + } + + CLIENT_STACK_UNWIND(removexattr, frame, rsp.op_ret, + gf_error_to_errno(rsp.op_errno), xdata); + + free(rsp.xdata.xdata_val); + + if (xdata) + dict_unref(xdata); + + return 0; +} + +int +client3_3_fremovexattr_cbk(struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + gf_common_rsp rsp = { + 0, + }; + int ret = 0; + xlator_t *this = NULL; + dict_t *xdata = NULL; + + this = THIS; + + frame = myframe; + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + rsp.op_errno = ENOTCONN; + goto out; + } + + ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gf_common_rsp); + if (ret < 0) { + gf_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + ret = client_post_fremovexattr(this, &rsp, &xdata); +out: + if (rsp.op_ret == -1) { + gf_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, NULL); + } + CLIENT_STACK_UNWIND(fremovexattr, frame, rsp.op_ret, + gf_error_to_errno(rsp.op_errno), xdata); + + free(rsp.xdata.xdata_val); + + if (xdata) + dict_unref(xdata); + + return 0; +} + +int +client3_3_fsyncdir_cbk(struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + gf_common_rsp rsp = { + 0, + }; + int ret = 0; + xlator_t *this = NULL; + dict_t *xdata = NULL; + + this = THIS; + + frame = myframe; + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + rsp.op_errno = ENOTCONN; + goto out; + } + ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gf_common_rsp); + if (ret < 0) { + gf_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + ret = client_post_fsyncdir(this, &rsp, &xdata); + +out: + if (rsp.op_ret == -1) { + gf_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, NULL); + } + CLIENT_STACK_UNWIND(fsyncdir, frame, rsp.op_ret, + gf_error_to_errno(rsp.op_errno), xdata); + + free(rsp.xdata.xdata_val); + + if (xdata) + dict_unref(xdata); + + return 0; +} + +int +client3_3_access_cbk(struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + gf_common_rsp rsp = { + 0, + }; + int ret = 0; + xlator_t *this = NULL; + dict_t *xdata = NULL; + + this = THIS; + + frame = myframe; + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + rsp.op_errno = ENOTCONN; + goto out; + } + ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gf_common_rsp); + if (ret < 0) { + gf_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + ret = client_post_access(this, &rsp, &xdata); + +out: + if (rsp.op_ret == -1) { + gf_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, NULL); + } + CLIENT_STACK_UNWIND(access, frame, rsp.op_ret, + gf_error_to_errno(rsp.op_errno), xdata); + + free(rsp.xdata.xdata_val); + + if (xdata) + dict_unref(xdata); + + return 0; +} + +int +client3_3_ftruncate_cbk(struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + gfs3_ftruncate_rsp rsp = { + 0, + }; + call_frame_t *frame = NULL; + struct iatt prestat = { + 0, + }; + struct iatt poststat = { + 0, + }; + int ret = 0; + xlator_t *this = NULL; + dict_t *xdata = NULL; + + this = THIS; + + frame = myframe; + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + rsp.op_errno = ENOTCONN; + goto out; + } + ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gfs3_ftruncate_rsp); + if (ret < 0) { + gf_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + ret = client_post_ftruncate(this, &rsp, &prestat, &poststat, &xdata); + +out: + if (rsp.op_ret == -1) { + gf_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, NULL); + } + CLIENT_STACK_UNWIND(ftruncate, frame, rsp.op_ret, + gf_error_to_errno(rsp.op_errno), &prestat, &poststat, + xdata); + + free(rsp.xdata.xdata_val); + + if (xdata) + dict_unref(xdata); + + return 0; +} + +int +client3_3_fstat_cbk(struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + gfs3_fstat_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_gfs3_fstat_rsp); + if (ret < 0) { + gf_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + ret = client_post_fstat(this, &rsp, &stat, &xdata); + +out: + if (rsp.op_ret == -1) { + gf_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, NULL); + } + CLIENT_STACK_UNWIND(fstat, frame, rsp.op_ret, + gf_error_to_errno(rsp.op_errno), &stat, xdata); + + free(rsp.xdata.xdata_val); + + if (xdata) + dict_unref(xdata); + + return 0; +} + +int +client3_3_inodelk_cbk(struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + gf_common_rsp rsp = { + 0, + }; + int ret = 0; + xlator_t *this = NULL; + dict_t *xdata = NULL; + + this = THIS; + + frame = myframe; + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + rsp.op_errno = ENOTCONN; + goto out; + } + ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gf_common_rsp); + if (ret < 0) { + gf_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + ret = client_post_inodelk(this, &rsp, &xdata); +out: + if (rsp.op_ret == -1) { + gf_smsg(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, NULL); + } + CLIENT_STACK_UNWIND(inodelk, frame, rsp.op_ret, + gf_error_to_errno(rsp.op_errno), xdata); + + free(rsp.xdata.xdata_val); + + if (xdata) + dict_unref(xdata); + + return 0; +} + +int +client3_3_finodelk_cbk(struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + gf_common_rsp rsp = { + 0, + }; + int ret = 0; + xlator_t *this = NULL; + dict_t *xdata = NULL; + 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_gf_common_rsp); + if (ret < 0) { + gf_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + ret = client_post_finodelk(this, &rsp, &xdata); +out: + if (rsp.op_ret == -1) { + gf_smsg(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, NULL); + } 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); + + free(rsp.xdata.xdata_val); + + if (xdata) + dict_unref(xdata); + + return 0; +} + +int +client3_3_entrylk_cbk(struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + gf_common_rsp rsp = { + 0, + }; + int ret = 0; + xlator_t *this = NULL; + dict_t *xdata = NULL; + + this = THIS; + + frame = myframe; + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + rsp.op_errno = ENOTCONN; + goto out; + } + ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gf_common_rsp); + if (ret < 0) { + gf_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + ret = client_post_entrylk(this, &rsp, &xdata); +out: + if (rsp.op_ret == -1) { + gf_smsg(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, NULL); + } + + CLIENT_STACK_UNWIND(entrylk, frame, rsp.op_ret, + gf_error_to_errno(rsp.op_errno), xdata); + + free(rsp.xdata.xdata_val); + + if (xdata) + dict_unref(xdata); + + return 0; +} + +int +client3_3_fentrylk_cbk(struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + gf_common_rsp rsp = { + 0, + }; + int ret = 0; + xlator_t *this = NULL; + dict_t *xdata = NULL; + + this = THIS; + + frame = myframe; + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + rsp.op_errno = ENOTCONN; + goto out; + } + ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gf_common_rsp); + if (ret < 0) { + gf_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + ret = client_post_fentrylk(this, &rsp, &xdata); + +out: + if ((rsp.op_ret == -1) && (EAGAIN != gf_error_to_errno(rsp.op_errno))) { + gf_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, NULL); + } + + CLIENT_STACK_UNWIND(fentrylk, frame, rsp.op_ret, + gf_error_to_errno(rsp.op_errno), xdata); + + free(rsp.xdata.xdata_val); + + if (xdata) + dict_unref(xdata); + + return 0; +} + +int +client3_3_xattrop_cbk(struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + dict_t *dict = NULL; + gfs3_xattrop_rsp rsp = { + 0, + }; + int ret = 0; + int op_errno = EINVAL; + clnt_local_t *local = NULL; + xlator_t *this = NULL; + dict_t *xdata = NULL; + + this = THIS; + + frame = myframe; + local = frame->local; + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + op_errno = ENOTCONN; + goto out; + } + ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gfs3_xattrop_rsp); + if (ret < 0) { + gf_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + rsp.op_ret = -1; + op_errno = EINVAL; + goto out; + } + + op_errno = rsp.op_errno; + ret = client_post_xattrop(this, &rsp, &dict, &xdata); + if (ret) { + op_errno = -ret; + goto out; + } +out: + if (rsp.op_ret == -1) { + gf_smsg(this->name, fop_log_level(GF_FOP_XATTROP, op_errno), + gf_error_to_errno(rsp.op_errno), PC_MSG_REMOTE_OP_FAILED, + "Path=%s", local->loc.path, "gfid=%s", + loc_gfid_utoa(&local->loc), NULL); + } + + CLIENT_STACK_UNWIND(xattrop, frame, rsp.op_ret, gf_error_to_errno(op_errno), + dict, xdata); + + free(rsp.dict.dict_val); + + free(rsp.xdata.xdata_val); + + if (xdata) + dict_unref(xdata); + + if (dict) + dict_unref(dict); + + return 0; +} + +int +client3_3_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; + gfs3_fxattrop_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_gfs3_fxattrop_rsp); + if (ret < 0) { + rsp.op_ret = -1; + op_errno = EINVAL; + gf_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + goto out; + } + op_errno = rsp.op_errno; + ret = client_post_fxattrop(this, &rsp, &dict, &xdata); + if (ret) { + rsp.op_ret = -1; + op_errno = -ret; + goto out; + } +out: + + if (rsp.op_ret == -1) { + gf_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, NULL); + } 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); + + free(rsp.dict.dict_val); + + free(rsp.xdata.xdata_val); + + if (xdata) + dict_unref(xdata); + + if (dict) + dict_unref(dict); + + return 0; +} + +int +client3_3_fsetxattr_cbk(struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + gf_common_rsp rsp = { + 0, + }; + int ret = 0; + xlator_t *this = NULL; + dict_t *xdata = NULL; + 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_gf_common_rsp); + if (ret < 0) { + gf_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + ret = client_post_setxattr(this, &rsp, &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_smsg(this->name, GF_LOG_WARNING, rsp.op_errno, + PC_MSG_REMOTE_OP_FAILED, NULL); + } + } + + CLIENT_STACK_UNWIND(fsetxattr, frame, rsp.op_ret, op_errno, xdata); + + free(rsp.xdata.xdata_val); + + if (xdata) + dict_unref(xdata); + + return 0; +} + +int +client3_3_fsetattr_cbk(struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + gfs3_fsetattr_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_gfs3_fsetattr_rsp); + if (ret < 0) { + gf_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + ret = client_post_fsetattr(this, &rsp, &prestat, &poststat, &xdata); +out: + if (rsp.op_ret == -1) { + gf_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, NULL); + } + CLIENT_STACK_UNWIND(fsetattr, frame, rsp.op_ret, + gf_error_to_errno(rsp.op_errno), &prestat, &poststat, + xdata); + + free(rsp.xdata.xdata_val); + + if (xdata) + dict_unref(xdata); + + return 0; +} + +int +client3_3_fallocate_cbk(struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + gfs3_fallocate_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_gfs3_fallocate_rsp); + if (ret < 0) { + gf_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + ret = client_post_fallocate(this, &rsp, &prestat, &poststat, &xdata); + if (ret < 0) + goto out; + + GF_PROTOCOL_DICT_UNSERIALIZE(this, xdata, (rsp.xdata.xdata_val), + (rsp.xdata.xdata_len), ret, rsp.op_errno, out); + +out: + if (rsp.op_ret == -1) { + gf_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, NULL); + } + CLIENT_STACK_UNWIND(fallocate, frame, rsp.op_ret, + gf_error_to_errno(rsp.op_errno), &prestat, &poststat, + xdata); + + free(rsp.xdata.xdata_val); + + if (xdata) + dict_unref(xdata); + + return 0; +} + +int +client3_3_discard_cbk(struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + gfs3_discard_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_gfs3_discard_rsp); + if (ret < 0) { + gf_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + ret = client_post_discard(this, &rsp, &prestat, &poststat, &xdata); + +out: + if (rsp.op_ret == -1) { + gf_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, NULL); + } + CLIENT_STACK_UNWIND(discard, frame, rsp.op_ret, + gf_error_to_errno(rsp.op_errno), &prestat, &poststat, + xdata); + + free(rsp.xdata.xdata_val); + + if (xdata) + dict_unref(xdata); + + return 0; +} + +int +client3_3_zerofill_cbk(struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + gfs3_zerofill_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_gfs3_zerofill_rsp); + if (ret < 0) { + gf_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + ret = client_post_zerofill(this, &rsp, &prestat, &poststat, &xdata); +out: + if (rsp.op_ret == -1) { + gf_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, NULL); + } + CLIENT_STACK_UNWIND(zerofill, frame, rsp.op_ret, + gf_error_to_errno(rsp.op_errno), &prestat, &poststat, + xdata); + + free(rsp.xdata.xdata_val); + + if (xdata) + dict_unref(xdata); + + return 0; +} + +int +client3_3_ipc_cbk(struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + gfs3_ipc_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_gfs3_ipc_rsp); + if (ret < 0) { + gf_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + ret = client_post_ipc(this, &rsp, &xdata); +out: + if (rsp.op_ret == -1) { + gf_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, NULL); + } + CLIENT_STACK_UNWIND(ipc, frame, rsp.op_ret, gf_error_to_errno(rsp.op_errno), + xdata); + + free(rsp.xdata.xdata_val); + + if (xdata) + dict_unref(xdata); + + return 0; +} + +int +client3_3_seek_cbk(struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + struct gfs3_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_gfs3_seek_rsp); + if (ret < 0) { + gf_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + ret = client_post_seek(this, &rsp, &xdata); + +out: + if (rsp.op_ret == -1) { + gf_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, NULL); + } + CLIENT_STACK_UNWIND(seek, frame, rsp.op_ret, + gf_error_to_errno(rsp.op_errno), rsp.offset, xdata); + + free(rsp.xdata.xdata_val); + + if (xdata) + dict_unref(xdata); + + return 0; +} + +int +client3_3_setattr_cbk(struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + gfs3_setattr_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_gfs3_setattr_rsp); + if (ret < 0) { + gf_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + ret = client_post_setattr(this, &rsp, &prestat, &poststat, &xdata); + +out: + if (rsp.op_ret == -1) { + gf_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, NULL); + } + CLIENT_STACK_UNWIND(setattr, frame, rsp.op_ret, + gf_error_to_errno(rsp.op_errno), &prestat, &poststat, + xdata); + + free(rsp.xdata.xdata_val); + + if (xdata) + dict_unref(xdata); + + return 0; +} + +int +client3_3_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; + gfs3_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_gfs3_create_rsp); + if (ret < 0) { + gf_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + if (-1 != rsp.op_ret) { + ret = client_post_create(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_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, "Path=%s", local->loc.path, NULL); + } + + CLIENT_STACK_UNWIND(create, frame, rsp.op_ret, + gf_error_to_errno(rsp.op_errno), fd, inode, &stbuf, + &preparent, &postparent, xdata); + + free(rsp.xdata.xdata_val); + + if (xdata) + dict_unref(xdata); + + return 0; +} + +int +client3_3_rchecksum_cbk(struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + gfs3_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_gfs3_rchecksum_rsp); + if (ret < 0) { + gf_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + ret = client_post_rchecksum(this, &rsp, &xdata); + +out: + if (rsp.op_ret == -1) { + gf_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, NULL); + } + 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); + } + + free(rsp.xdata.xdata_val); + + if (xdata) + dict_unref(xdata); + + return 0; +} + +int +client3_3_lease_cbk(struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + struct gf_lease lease = { + 0, + }; + gfs3_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_smsg(this->name, GF_LOG_ERROR, ENOTCONN, PC_MSG_LEASE_FOP_FAILED, + NULL); + rsp.op_ret = -1; + rsp.op_errno = ENOTCONN; + goto out; + } + + ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gfs3_lease_rsp); + if (ret < 0) { + gf_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + ret = client_post_lease(this, &rsp, &lease, &xdata); + +out: + if (rsp.op_ret == -1) { + gf_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, NULL); + } + + CLIENT_STACK_UNWIND(lease, frame, rsp.op_ret, + gf_error_to_errno(rsp.op_errno), &lease, xdata); + + free(rsp.xdata.xdata_val); + + if (xdata) + dict_unref(xdata); + + return 0; +} + +int +client3_3_lk_cbk(struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + struct gf_flock lock = { + 0, + }; + gfs3_lk_rsp rsp = { + 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_gfs3_lk_rsp); + if (ret < 0) { + gf_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + if (rsp.op_ret >= 0) { + ret = client_post_lk(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.*/ + + if (client_is_setlk(local->cmd)) { + 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_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, NULL); + } + + CLIENT_STACK_UNWIND(lk, frame, rsp.op_ret, gf_error_to_errno(rsp.op_errno), + &lock, xdata); + + free(rsp.xdata.xdata_val); + + free(rsp.flock.lk_owner.lk_owner_val); + + if (xdata) + dict_unref(xdata); + + return 0; +} + +int +client3_3_readdir_cbk(struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + gfs3_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_gfs3_readdir_rsp); + if (ret < 0) { + gf_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + ret = client_post_readdir(this, &rsp, &entries, &xdata); + +out: + if (rsp.op_ret == -1) { + gf_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, "remote_fd=%d", local->cmd, NULL); + } + 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); + } + + free(rsp.xdata.xdata_val); + + if (xdata) + dict_unref(xdata); + + clnt_readdir_rsp_cleanup(&rsp); + + return 0; +} + +int +client3_3_readdirp_cbk(struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + gfs3_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_gfs3_readdirp_rsp); + if (ret < 0) { + gf_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + ret = client_post_readdirp(this, &rsp, local->fd, &entries, &xdata); +out: + if (rsp.op_ret == -1) { + gf_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, NULL); + } + 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); + } + free(rsp.xdata.xdata_val); + + if (xdata) + dict_unref(xdata); + + clnt_readdirp_rsp_cleanup(&rsp); + + return 0; +} + +int +client3_3_rename_cbk(struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + gfs3_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_gfs3_rename_rsp); + if (ret < 0) { + gf_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + ret = client_post_rename(this, &rsp, &stbuf, &preoldparent, &postoldparent, + &prenewparent, &postnewparent, &xdata); + +out: + if (rsp.op_ret == -1) { + gf_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, NULL); + } + CLIENT_STACK_UNWIND(rename, frame, rsp.op_ret, + gf_error_to_errno(rsp.op_errno), &stbuf, &preoldparent, + &postoldparent, &prenewparent, &postnewparent, xdata); + + free(rsp.xdata.xdata_val); + + if (xdata) + dict_unref(xdata); + + return 0; +} + +int +client3_3_link_cbk(struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + gfs3_link_rsp rsp = { + 0, + }; + struct iatt stbuf = { + 0, + }; + struct iatt preparent = { + 0, + }; + struct iatt postparent = { + 0, + }; + int ret = 0; + clnt_local_t *local = NULL; + inode_t *inode = NULL; + xlator_t *this = NULL; + dict_t *xdata = NULL; + + this = THIS; + + frame = myframe; + + local = frame->local; + inode = local->loc.inode; + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + rsp.op_errno = ENOTCONN; + goto out; + } + + ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gfs3_link_rsp); + if (ret < 0) { + gf_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + ret = client_post_link(this, &rsp, &stbuf, &preparent, &postparent, &xdata); +out: + if (rsp.op_ret == -1) { + if (GF_IGNORE_IF_GSYNCD_SAFE_ERROR(frame, rsp.op_errno)) { + gf_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, "loc1=%s", local->loc.path, + "loc2=%s", local->loc2.path, NULL); + } + } + + CLIENT_STACK_UNWIND(link, frame, rsp.op_ret, + gf_error_to_errno(rsp.op_errno), inode, &stbuf, + &preparent, &postparent, xdata); + + free(rsp.xdata.xdata_val); + + if (xdata) + dict_unref(xdata); + + return 0; +} + +int +client3_3_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; + gfs3_opendir_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_gfs3_opendir_rsp); + if (ret < 0) { + gf_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + 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 = client_post_opendir(this, &rsp, &xdata); +out: + if (rsp.op_ret == -1) { + gf_smsg(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, + "Path=%s", local->loc.path, "gfid=%s", + loc_gfid_utoa(&local->loc), NULL); + } + CLIENT_STACK_UNWIND(opendir, frame, rsp.op_ret, + gf_error_to_errno(rsp.op_errno), fd, xdata); + + free(rsp.xdata.xdata_val); + + if (xdata) + dict_unref(xdata); + + return 0; +} + +int +client3_3_lookup_cbk(struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + clnt_local_t *local = NULL; + call_frame_t *frame = NULL; + int ret = 0; + gfs3_lookup_rsp rsp = { + 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_gfs3_lookup_rsp); + if (ret < 0) { + gf_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + 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_lookup(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_smsg(this->name, GF_LOG_WARNING, rsp.op_errno, + PC_MSG_REMOTE_OP_FAILED, "Path=%s", local->loc.path, + "gfid=%s", loc_gfid_utoa(&local->loc), NULL); + 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); + + free(rsp.xdata.xdata_val); + + return 0; +} + +int +client3_3_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, + }; + gfs3_read_rsp rsp = { + 0, + }; + int ret = 0, rspcount = 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; + rsp.op_errno = ENOTCONN; + goto out; + } + + ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gfs3_read_rsp); + if (ret < 0) { + gf_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + memset(vector, 0, sizeof(vector)); + + ret = client_post_readv(this, &rsp, &iobref, req->rsp_iobref, &stat, vector, + &req->rsp[1], &rspcount, &xdata); +out: + if (rsp.op_ret == -1) { + gf_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, NULL); + } 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); + + free(rsp.xdata.xdata_val); + + if (xdata) + dict_unref(xdata); + + return 0; +} + +int +client3_3_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 +client3_3_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; +} + +static int +client3_3_getactivelk_cbk(struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + gfs3_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_gfs3_getactivelk_rsp); + if (ret < 0) { + gf_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + INIT_LIST_HEAD(&locklist.list); + + if (rsp.op_ret > 0) { + clnt_unserialize_rsp_locklist(this, &rsp, &locklist); + } + + GF_PROTOCOL_DICT_UNSERIALIZE(this, xdata, (rsp.xdata.xdata_val), + (rsp.xdata.xdata_len), ret, rsp.op_errno, out); + +out: + if (rsp.op_ret == -1) { + gf_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, NULL); + } + + CLIENT_STACK_UNWIND(getactivelk, frame, rsp.op_ret, + gf_error_to_errno(rsp.op_errno), &locklist, xdata); + + free(rsp.xdata.xdata_val); + + if (xdata) + dict_unref(xdata); + + clnt_getactivelk_rsp_cleanup(&rsp); + + return 0; +} + +static int +client3_3_setactivelk_cbk(struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + gfs3_getactivelk_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_gfs3_setactivelk_rsp); + if (ret < 0) { + gf_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + GF_PROTOCOL_DICT_UNSERIALIZE(this, xdata, (rsp.xdata.xdata_val), + (rsp.xdata.xdata_len), ret, rsp.op_errno, out); + +out: + if (rsp.op_ret == -1) { + gf_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, NULL); + } + + CLIENT_STACK_UNWIND(setactivelk, frame, rsp.op_ret, + gf_error_to_errno(rsp.op_errno), xdata); + + free(rsp.xdata.xdata_val); + + if (xdata) + dict_unref(xdata); + + return 0; +} + +int32_t +client3_3_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_spin_lock(&conf->fd_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_spin_unlock(&conf->fd_lock); + + if (destroy) + client_fdctx_destroy(this, fdctx); + +out: + + return 0; +} + +int32_t +client3_3_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; + gf_boolean_t destroy = _gf_false; + + if (!this || !data) + goto out; + + args = data; + conf = this->private; + + pthread_spin_lock(&conf->fd_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_spin_unlock(&conf->fd_lock); + + if (destroy) + client_fdctx_destroy(this, fdctx); +out: + return 0; +} + +int32_t +client3_3_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; + gfs3_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; + client_payload_t cp; + + if (!frame || !this || !data) + goto unwind; + + 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_sizen(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); + memset(vector, 0, sizeof(vector)); + 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(this, &req, args->loc, args->xdata); + if (ret) { + op_errno = -ret; + goto unwind; + } + + memset(&cp, 0, sizeof(client_payload_t)); + cp.rsphdr = rsphdr; + cp.rsphdr_cnt = count; + cp.rsp_iobref = local->iobref; + ret = client_submit_request(this, &req, frame, conf->fops, GFS3_OP_LOOKUP, + client3_3_lookup_cbk, &cp, + (xdrproc_t)xdr_gfs3_lookup_req); + + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + GF_FREE(req.xdata.xdata_val); + + return 0; + +unwind: + CLIENT_STACK_UNWIND(lookup, frame, -1, op_errno, NULL, NULL, NULL, NULL); + + GF_FREE(req.xdata.xdata_val); + + if (rsp_iobref) + iobref_unref(rsp_iobref); + + return 0; +} + +int32_t +client3_3_stat(call_frame_t *frame, xlator_t *this, void *data) +{ + clnt_conf_t *conf = NULL; + clnt_args_t *args = NULL; + gfs3_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(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, + client3_3_stat_cbk, NULL, + (xdrproc_t)xdr_gfs3_stat_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + GF_FREE(req.xdata.xdata_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND(stat, frame, -1, op_errno, NULL, NULL); + + GF_FREE(req.xdata.xdata_val); + + return 0; +} + +int32_t +client3_3_truncate(call_frame_t *frame, xlator_t *this, void *data) +{ + clnt_conf_t *conf = NULL; + clnt_args_t *args = NULL; + gfs3_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(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, + client3_3_truncate_cbk, NULL, + (xdrproc_t)xdr_gfs3_truncate_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + GF_FREE(req.xdata.xdata_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND(truncate, frame, -1, op_errno, NULL, NULL, NULL); + GF_FREE(req.xdata.xdata_val); + + return 0; +} + +int32_t +client3_3_ftruncate(call_frame_t *frame, xlator_t *this, void *data) +{ + clnt_args_t *args = NULL; + clnt_conf_t *conf = NULL; + gfs3_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(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, client3_3_ftruncate_cbk, + NULL, (xdrproc_t)xdr_gfs3_ftruncate_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + GF_FREE(req.xdata.xdata_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND(ftruncate, frame, -1, op_errno, NULL, NULL, NULL); + GF_FREE(req.xdata.xdata_val); + + return 0; +} + +int32_t +client3_3_access(call_frame_t *frame, xlator_t *this, void *data) +{ + clnt_conf_t *conf = NULL; + clnt_args_t *args = NULL; + gfs3_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(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, + client3_3_access_cbk, NULL, + (xdrproc_t)xdr_gfs3_access_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + GF_FREE(req.xdata.xdata_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND(access, frame, -1, op_errno, NULL); + GF_FREE(req.xdata.xdata_val); + + return 0; +} + +int32_t +client3_3_readlink(call_frame_t *frame, xlator_t *this, void *data) +{ + clnt_conf_t *conf = NULL; + clnt_args_t *args = NULL; + gfs3_readlink_req req = { + { + 0, + }, + }; + int ret = 0; + int op_errno = ESTALE; + clnt_local_t *local = NULL; + struct iobuf *rsp_iobuf = NULL; + struct iobref *rsp_iobref = NULL; + struct iovec *rsphdr = NULL; + int count = 0; + struct iovec vector[MAX_IOVEC] = { + {0}, + }; + client_payload_t cp; + + 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(this, &req, args->loc, args->size, args->xdata); + if (ret) { + op_errno = -ret; + goto unwind; + } + + rsp_iobref = iobref_new(); + if (rsp_iobref == NULL) { + goto unwind; + } + + rsp_iobuf = iobuf_get(this->ctx->iobuf_pool); + if (rsp_iobuf == NULL) { + goto unwind; + } + + rsphdr = &vector[0]; + rsphdr->iov_base = iobuf_ptr(rsp_iobuf); + rsphdr->iov_len = iobuf_pagesize(rsp_iobuf); + count = 1; + local->iobref = rsp_iobref; + iobref_add(rsp_iobref, rsp_iobuf); + iobuf_unref(rsp_iobuf); + rsp_iobuf = NULL; + rsp_iobref = NULL; + + memset(&cp, 0, sizeof(client_payload_t)); + cp.rsphdr = rsphdr; + cp.rsphdr_cnt = count; + cp.rsp_iobref = local->iobref; + ret = client_submit_request(this, &req, frame, conf->fops, GFS3_OP_READLINK, + client3_3_readlink_cbk, &cp, + (xdrproc_t)xdr_gfs3_readlink_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + GF_FREE(req.xdata.xdata_val); + + return 0; +unwind: + if (rsp_iobref != NULL) { + iobref_unref(rsp_iobref); + } + + CLIENT_STACK_UNWIND(readlink, frame, -1, op_errno, NULL, NULL, NULL); + GF_FREE(req.xdata.xdata_val); + + return 0; +} + +int32_t +client3_3_unlink(call_frame_t *frame, xlator_t *this, void *data) +{ + clnt_conf_t *conf = NULL; + clnt_args_t *args = NULL; + gfs3_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(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, + client3_3_unlink_cbk, NULL, + (xdrproc_t)xdr_gfs3_unlink_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + GF_FREE(req.xdata.xdata_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND(unlink, frame, -1, op_errno, NULL, NULL, NULL); + GF_FREE(req.xdata.xdata_val); + + return 0; +} + +int32_t +client3_3_rmdir(call_frame_t *frame, xlator_t *this, void *data) +{ + clnt_conf_t *conf = NULL; + clnt_args_t *args = NULL; + gfs3_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(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, + client3_3_rmdir_cbk, NULL, + (xdrproc_t)xdr_gfs3_rmdir_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + GF_FREE(req.xdata.xdata_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND(rmdir, frame, -1, op_errno, NULL, NULL, NULL); + GF_FREE(req.xdata.xdata_val); + + return 0; +} + +int32_t +client3_3_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; + gfs3_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(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, + client3_3_symlink_cbk, NULL, + (xdrproc_t)xdr_gfs3_symlink_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + GF_FREE(req.xdata.xdata_val); + + return 0; +unwind: + + CLIENT_STACK_UNWIND(symlink, frame, -1, op_errno, NULL, NULL, NULL, NULL, + NULL); + + GF_FREE(req.xdata.xdata_val); + + return 0; +} + +int32_t +client3_3_rename(call_frame_t *frame, xlator_t *this, void *data) +{ + clnt_conf_t *conf = NULL; + clnt_args_t *args = NULL; + gfs3_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(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, + client3_3_rename_cbk, NULL, + (xdrproc_t)xdr_gfs3_rename_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + GF_FREE(req.xdata.xdata_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND(rename, frame, -1, op_errno, NULL, NULL, NULL, NULL, + NULL, NULL); + + GF_FREE(req.xdata.xdata_val); + + return 0; +} + +int32_t +client3_3_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; + gfs3_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(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, + client3_3_link_cbk, NULL, + (xdrproc_t)xdr_gfs3_link_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + GF_FREE(req.xdata.xdata_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND(link, frame, -1, op_errno, NULL, NULL, NULL, NULL, + NULL); + GF_FREE(req.xdata.xdata_val); + + return 0; +} + +int32_t +client3_3_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; + gfs3_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(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, + client3_3_mknod_cbk, NULL, + (xdrproc_t)xdr_gfs3_mknod_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + GF_FREE(req.xdata.xdata_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND(mknod, frame, -1, op_errno, NULL, NULL, NULL, NULL, + NULL); + + GF_FREE(req.xdata.xdata_val); + + return 0; +} + +int32_t +client3_3_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; + gfs3_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_sizen(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(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, + client3_3_mkdir_cbk, NULL, + (xdrproc_t)xdr_gfs3_mkdir_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + GF_FREE(req.xdata.xdata_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND(mkdir, frame, -1, op_errno, NULL, NULL, NULL, NULL, + NULL); + + GF_FREE(req.xdata.xdata_val); + + return 0; +} + +int32_t +client3_3_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; + gfs3_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(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, + client3_3_create_cbk, NULL, + (xdrproc_t)xdr_gfs3_create_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + GF_FREE(req.xdata.xdata_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND(create, frame, -1, op_errno, NULL, NULL, NULL, NULL, + NULL, NULL); + + GF_FREE(req.xdata.xdata_val); + + return 0; +} + +int32_t +client3_3_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; + gfs3_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(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, + client3_3_open_cbk, NULL, + (xdrproc_t)xdr_gfs3_open_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + GF_FREE(req.xdata.xdata_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND(open, frame, -1, op_errno, NULL, NULL); + + GF_FREE(req.xdata.xdata_val); + + return 0; +} + +int32_t +client3_3_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; + gfs3_read_req req = { + { + 0, + }, + }; + int ret = 0; + struct iovec rsp_vec = { + 0, + }; + struct iobuf *rsp_iobuf = NULL; + struct iobref *rsp_iobref = NULL; + client_payload_t cp; + + if (!frame || !this || !data) + goto unwind; + + args = data; + conf = this->private; + + ret = client_pre_readv(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; + } + + rsp_vec.iov_base = iobuf_ptr(rsp_iobuf); + rsp_vec.iov_len = iobuf_pagesize(rsp_iobuf); + + iobref_add(rsp_iobref, rsp_iobuf); + iobuf_unref(rsp_iobuf); + rsp_iobuf = NULL; + + if (args->size > rsp_vec.iov_len) { + gf_smsg(this->name, GF_LOG_WARNING, ENOMEM, PC_MSG_BIGGER_SIZE, + "read-size=%lu", (unsigned long)args->size, "iobuf size=%lu", + (unsigned long)rsp_vec.iov_len, NULL); + op_errno = EINVAL; + goto unwind; + } + + local->iobref = rsp_iobref; + rsp_iobref = NULL; + + memset(&cp, 0, sizeof(client_payload_t)); + cp.rsp_payload = &rsp_vec; + cp.rsp_payload_cnt = 1; + cp.rsp_iobref = local->iobref; + ret = client_submit_request(this, &req, frame, conf->fops, GFS3_OP_READ, + client3_3_readv_cbk, &cp, + (xdrproc_t)xdr_gfs3_read_req); + if (ret) { + // unwind is done in the cbk + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + GF_FREE(req.xdata.xdata_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.xdata_val); + + return 0; +} + +int32_t +client3_3_writev(call_frame_t *frame, xlator_t *this, void *data) +{ + clnt_args_t *args = NULL; + clnt_conf_t *conf = NULL; + gfs3_write_req req = { + { + 0, + }, + }; + int op_errno = ESTALE; + int ret = 0; + client_payload_t cp; + + if (!frame || !this || !data) + goto unwind; + + args = data; + conf = this->private; + + ret = client_pre_writev(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; + } + + memset(&cp, 0, sizeof(client_payload_t)); + cp.iobref = args->iobref; + cp.payload = args->vector; + cp.payload_cnt = args->count; + ret = client_submit_request(this, &req, frame, conf->fops, GFS3_OP_WRITE, + client3_3_writev_cbk, &cp, + (xdrproc_t)xdr_gfs3_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_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + GF_FREE(req.xdata.xdata_val); + + return 0; + +unwind: + CLIENT_STACK_UNWIND(writev, frame, -1, op_errno, NULL, NULL, NULL); + GF_FREE(req.xdata.xdata_val); + + return 0; +} + +int32_t +client3_3_flush(call_frame_t *frame, xlator_t *this, void *data) +{ + clnt_args_t *args = NULL; + gfs3_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(this, &req, args->fd, args->xdata); + if (ret) { + op_errno = -ret; + if (op_errno == EBADF) { + 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); + } + + goto unwind; + } + + ret = client_submit_request(this, &req, frame, conf->fops, GFS3_OP_FLUSH, + client3_3_flush_cbk, NULL, + (xdrproc_t)xdr_gfs3_flush_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + GF_FREE(req.xdata.xdata_val); + + return 0; + +unwind: + CLIENT_STACK_UNWIND(flush, frame, -1, op_errno, NULL); + GF_FREE(req.xdata.xdata_val); + + return 0; +} + +int32_t +client3_3_fsync(call_frame_t *frame, xlator_t *this, void *data) +{ + clnt_args_t *args = NULL; + gfs3_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(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, + client3_3_fsync_cbk, NULL, + (xdrproc_t)xdr_gfs3_fsync_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + GF_FREE(req.xdata.xdata_val); + + return 0; + +unwind: + CLIENT_STACK_UNWIND(fsync, frame, -1, op_errno, NULL, NULL, NULL); + GF_FREE(req.xdata.xdata_val); + + return 0; +} + +int32_t +client3_3_fstat(call_frame_t *frame, xlator_t *this, void *data) +{ + clnt_args_t *args = NULL; + gfs3_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(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, + client3_3_fstat_cbk, NULL, + (xdrproc_t)xdr_gfs3_fstat_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + GF_FREE(req.xdata.xdata_val); + + return 0; + +unwind: + CLIENT_STACK_UNWIND(fstat, frame, -1, op_errno, NULL, NULL); + GF_FREE(req.xdata.xdata_val); + + return 0; +} + +int32_t +client3_3_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; + gfs3_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(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, + client3_3_opendir_cbk, NULL, + (xdrproc_t)xdr_gfs3_opendir_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + GF_FREE(req.xdata.xdata_val); + + return 0; + +unwind: + CLIENT_STACK_UNWIND(opendir, frame, -1, op_errno, NULL, NULL); + + GF_FREE(req.xdata.xdata_val); + + return 0; +} + +int32_t +client3_3_fsyncdir(call_frame_t *frame, xlator_t *this, void *data) +{ + clnt_args_t *args = NULL; + clnt_conf_t *conf = NULL; + gfs3_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(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, + client3_3_fsyncdir_cbk, NULL, + (xdrproc_t)xdr_gfs3_fsyncdir_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + GF_FREE(req.xdata.xdata_val); + + return 0; + +unwind: + CLIENT_STACK_UNWIND(fsyncdir, frame, -1, op_errno, NULL); + GF_FREE(req.xdata.xdata_val); + + return 0; +} + +int32_t +client3_3_statfs(call_frame_t *frame, xlator_t *this, void *data) +{ + clnt_conf_t *conf = NULL; + clnt_args_t *args = NULL; + gfs3_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(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, + client3_3_statfs_cbk, NULL, + (xdrproc_t)xdr_gfs3_statfs_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + GF_FREE(req.xdata.xdata_val); + + return 0; + +unwind: + CLIENT_STACK_UNWIND(statfs, frame, -1, op_errno, NULL, NULL); + GF_FREE(req.xdata.xdata_val); + + return 0; +} + +int32_t +client3_3_setxattr(call_frame_t *frame, xlator_t *this, void *data) +{ + clnt_conf_t *conf = NULL; + clnt_args_t *args = NULL; + gfs3_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(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, + client3_3_setxattr_cbk, NULL, + (xdrproc_t)xdr_gfs3_setxattr_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + GF_FREE(req.dict.dict_val); + + GF_FREE(req.xdata.xdata_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND(setxattr, frame, -1, op_errno, NULL); + GF_FREE(req.dict.dict_val); + + GF_FREE(req.xdata.xdata_val); + + return 0; +} + +int32_t +client3_3_fsetxattr(call_frame_t *frame, xlator_t *this, void *data) +{ + clnt_args_t *args = NULL; + clnt_conf_t *conf = NULL; + gfs3_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(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, client3_3_fsetxattr_cbk, + NULL, (xdrproc_t)xdr_gfs3_fsetxattr_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + GF_FREE(req.dict.dict_val); + + GF_FREE(req.xdata.xdata_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND(fsetxattr, frame, -1, op_errno, NULL); + GF_FREE(req.dict.dict_val); + + GF_FREE(req.xdata.xdata_val); + + return 0; +} + +int32_t +client3_3_fgetxattr(call_frame_t *frame, xlator_t *this, void *data) +{ + clnt_args_t *args = NULL; + clnt_conf_t *conf = NULL; + gfs3_fgetxattr_req req = { + { + 0, + }, + }; + int op_errno = ESTALE; + int ret = 0; + int count = 0; + clnt_local_t *local = NULL; + struct iobref *rsp_iobref = NULL; + struct iobuf *rsp_iobuf = NULL; + struct iovec *rsphdr = NULL; + struct iovec vector[MAX_IOVEC] = { + {0}, + }; + client_payload_t cp; + + 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; + + rsp_iobref = iobref_new(); + if (rsp_iobref == NULL) { + op_errno = ENOMEM; + goto unwind; + } + + /* TODO: what is the size we should send ? */ + rsp_iobuf = iobuf_get2(this->ctx->iobuf_pool, 8 * GF_UNIT_KB); + if (rsp_iobuf == NULL) { + op_errno = ENOMEM; + goto unwind; + } + + rsphdr = &vector[0]; + rsphdr->iov_base = iobuf_ptr(rsp_iobuf); + rsphdr->iov_len = iobuf_pagesize(rsp_iobuf); + ; + count = 1; + local->iobref = rsp_iobref; + iobref_add(rsp_iobref, rsp_iobuf); + iobuf_unref(rsp_iobuf); + rsp_iobuf = NULL; + rsp_iobref = NULL; + + ret = client_pre_fgetxattr(this, &req, args->fd, args->name, args->xdata); + if (ret) { + op_errno = -ret; + goto unwind; + } + + memset(&cp, 0, sizeof(client_payload_t)); + cp.rsphdr = rsphdr; + cp.rsphdr_cnt = count; + cp.rsp_iobref = local->iobref; + ret = client_submit_request(this, &req, frame, conf->fops, + GFS3_OP_FGETXATTR, client3_3_fgetxattr_cbk, &cp, + (xdrproc_t)xdr_gfs3_fgetxattr_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + GF_FREE(req.xdata.xdata_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND(fgetxattr, frame, -1, op_errno, NULL, NULL); + + if (rsp_iobref) + iobref_unref(rsp_iobref); + + GF_FREE(req.xdata.xdata_val); + + return 0; +} + +int32_t +client3_3_getxattr(call_frame_t *frame, xlator_t *this, void *data) +{ + clnt_conf_t *conf = NULL; + clnt_args_t *args = NULL; + gfs3_getxattr_req req = { + { + 0, + }, + }; + dict_t *dict = NULL; + int ret = 0; + int32_t op_ret = -1; + int op_errno = ESTALE; + int count = 0; + clnt_local_t *local = NULL; + struct iobref *rsp_iobref = NULL; + struct iobuf *rsp_iobuf = NULL; + struct iovec *rsphdr = NULL; + struct iovec vector[MAX_IOVEC] = { + {0}, + }; + client_payload_t cp; + + 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); + + rsp_iobref = iobref_new(); + if (rsp_iobref == NULL) { + op_errno = ENOMEM; + goto unwind; + } + + /* TODO: what is the size we should send ? */ + rsp_iobuf = iobuf_get2(this->ctx->iobuf_pool, 8 * GF_UNIT_KB); + if (rsp_iobuf == NULL) { + op_errno = ENOMEM; + goto unwind; + } + + rsphdr = &vector[0]; + rsphdr->iov_base = iobuf_ptr(rsp_iobuf); + rsphdr->iov_len = iobuf_pagesize(rsp_iobuf); + count = 1; + local->iobref = rsp_iobref; + iobref_add(rsp_iobref, rsp_iobuf); + iobuf_unref(rsp_iobuf); + rsp_iobuf = NULL; + rsp_iobref = NULL; + + 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_smsg(this->name, GF_LOG_WARNING, EINVAL, + PC_MSG_CLIENT_DUMP_LOCKS_FAILED, NULL); + op_errno = ENOMEM; + goto unwind; + } + + GF_ASSERT(dict); + op_ret = 0; + op_errno = 0; + goto unwind; + } + } + + ret = client_pre_getxattr(this, &req, args->loc, args->name, args->xdata); + if (ret) { + op_errno = -ret; + goto unwind; + } + + memset(&cp, 0, sizeof(client_payload_t)); + cp.rsphdr = rsphdr; + cp.rsphdr_cnt = count; + cp.rsp_iobref = local->iobref; + ret = client_submit_request(this, &req, frame, conf->fops, GFS3_OP_GETXATTR, + client3_3_getxattr_cbk, &cp, + (xdrproc_t)xdr_gfs3_getxattr_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + GF_FREE(req.xdata.xdata_val); + + return 0; +unwind: + if (rsp_iobref) + iobref_unref(rsp_iobref); + + CLIENT_STACK_UNWIND(getxattr, frame, op_ret, op_errno, dict, NULL); + + if (dict) { + dict_unref(dict); + } + + GF_FREE(req.xdata.xdata_val); + + return 0; +} + +int32_t +client3_3_xattrop(call_frame_t *frame, xlator_t *this, void *data) +{ + clnt_conf_t *conf = NULL; + clnt_args_t *args = NULL; + gfs3_xattrop_req req = { + { + 0, + }, + }; + int ret = 0; + int op_errno = ESTALE; + int count = 0; + clnt_local_t *local = NULL; + struct iobref *rsp_iobref = NULL; + struct iobuf *rsp_iobuf = NULL; + struct iovec *rsphdr = NULL; + struct iovec vector[MAX_IOVEC] = { + {0}, + }; + client_payload_t cp; + + 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; + + rsp_iobref = iobref_new(); + if (rsp_iobref == NULL) { + op_errno = ENOMEM; + goto unwind; + } + + /* TODO: what is the size we should send ? */ + rsp_iobuf = iobuf_get2(this->ctx->iobuf_pool, 8 * GF_UNIT_KB); + if (rsp_iobuf == NULL) { + op_errno = ENOMEM; + goto unwind; + } + + rsphdr = &vector[0]; + rsphdr->iov_base = iobuf_ptr(rsp_iobuf); + rsphdr->iov_len = iobuf_pagesize(rsp_iobuf); + count = 1; + local->iobref = rsp_iobref; + iobref_add(rsp_iobref, rsp_iobuf); + iobuf_unref(rsp_iobuf); + rsp_iobuf = NULL; + rsp_iobref = NULL; + + loc_copy(&local->loc, args->loc); + loc_path(&local->loc, NULL); + conf = this->private; + + ret = client_pre_xattrop(this, &req, args->loc, args->xattr, args->flags, + args->xdata); + if (ret) { + op_errno = -ret; + goto unwind; + } + + memset(&cp, 0, sizeof(client_payload_t)); + cp.rsphdr = rsphdr; + cp.rsphdr_cnt = count; + cp.rsp_iobref = local->iobref; + ret = client_submit_request(this, &req, frame, conf->fops, GFS3_OP_XATTROP, + client3_3_xattrop_cbk, &cp, + (xdrproc_t)xdr_gfs3_xattrop_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + GF_FREE(req.dict.dict_val); + + GF_FREE(req.xdata.xdata_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND(xattrop, frame, -1, op_errno, NULL, NULL); + + GF_FREE(req.dict.dict_val); + + if (rsp_iobref) + iobref_unref(rsp_iobref); + + GF_FREE(req.xdata.xdata_val); + + return 0; +} + +int32_t +client3_3_fxattrop(call_frame_t *frame, xlator_t *this, void *data) +{ + clnt_args_t *args = NULL; + clnt_conf_t *conf = NULL; + clnt_local_t *local = NULL; + gfs3_fxattrop_req req = { + { + 0, + }, + }; + 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}, + }; + client_payload_t cp; + + if (!frame || !this || !data) + goto unwind; + + args = data; + conf = this->private; + + ret = client_pre_fxattrop(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; + } + + local = frame->local; + + rsp_iobref = iobref_new(); + if (rsp_iobref == NULL) { + op_errno = ENOMEM; + goto unwind; + } + + /* TODO: what is the size we should send ? */ + rsp_iobuf = iobuf_get2(this->ctx->iobuf_pool, 8 * GF_UNIT_KB); + if (rsp_iobuf == NULL) { + op_errno = ENOMEM; + goto unwind; + } + + rsphdr = &vector[0]; + rsphdr->iov_base = iobuf_ptr(rsp_iobuf); + rsphdr->iov_len = iobuf_pagesize(rsp_iobuf); + count = 1; + local->iobref = rsp_iobref; + iobref_add(rsp_iobref, rsp_iobuf); + iobuf_unref(rsp_iobuf); + rsp_iobuf = NULL; + rsp_iobref = NULL; + + memset(&cp, 0, sizeof(client_payload_t)); + cp.rsphdr = rsphdr; + cp.rsphdr_cnt = count; + cp.rsp_iobref = local->iobref; + ret = client_submit_request(this, &req, frame, conf->fops, GFS3_OP_FXATTROP, + client3_3_fxattrop_cbk, &cp, + (xdrproc_t)xdr_gfs3_fxattrop_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + GF_FREE(req.dict.dict_val); + + GF_FREE(req.xdata.xdata_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND(fxattrop, frame, -1, op_errno, NULL, NULL); + + GF_FREE(req.dict.dict_val); + + if (rsp_iobref) + iobref_unref(rsp_iobref); + + GF_FREE(req.xdata.xdata_val); + + return 0; +} + +int32_t +client3_3_removexattr(call_frame_t *frame, xlator_t *this, void *data) +{ + clnt_conf_t *conf = NULL; + clnt_args_t *args = NULL; + gfs3_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(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, client3_3_removexattr_cbk, + NULL, (xdrproc_t)xdr_gfs3_removexattr_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + GF_FREE(req.xdata.xdata_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND(removexattr, frame, -1, op_errno, NULL); + GF_FREE(req.xdata.xdata_val); + + return 0; +} + +int32_t +client3_3_fremovexattr(call_frame_t *frame, xlator_t *this, void *data) +{ + clnt_conf_t *conf = NULL; + clnt_args_t *args = NULL; + gfs3_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(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, + client3_3_fremovexattr_cbk, NULL, (xdrproc_t)xdr_gfs3_fremovexattr_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + GF_FREE(req.xdata.xdata_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND(fremovexattr, frame, -1, op_errno, NULL); + GF_FREE(req.xdata.xdata_val); + + return 0; +} + +int32_t +client3_3_lease(call_frame_t *frame, xlator_t *this, void *data) +{ + clnt_args_t *args = NULL; + gfs3_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(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, + client3_3_lease_cbk, NULL, + (xdrproc_t)xdr_gfs3_lease_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + GF_FREE(req.xdata.xdata_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND(lease, frame, -1, op_errno, NULL, NULL); + GF_FREE(req.xdata.xdata_val); + + return 0; +} + +int32_t +client3_3_lk(call_frame_t *frame, xlator_t *this, void *data) +{ + clnt_args_t *args = NULL; + gfs3_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_smsg(this->name, GF_LOG_WARNING, EINVAL, PC_MSG_UNKNOWN_CMD, + "gf_cmd=%d", gf_cmd, NULL); + goto unwind; + } + + local->owner = frame->root->lk_owner; + local->cmd = args->cmd; + local->fd = fd_ref(args->fd); + + ret = client_pre_lk(this, &req, args->cmd, args->flock, args->fd, + args->xdata); + if (ret) { + op_errno = -ret; + + if ((op_errno == EBADF) && (args->flock->l_type == F_UNLCK) && + client_is_setlk(local->cmd)) { + client_add_lock_for_recovery(local->fd, args->flock, &local->owner, + local->cmd); + } + + goto unwind; + } + + ret = client_submit_request(this, &req, frame, conf->fops, GFS3_OP_LK, + client3_3_lk_cbk, NULL, + (xdrproc_t)xdr_gfs3_lk_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + GF_FREE(req.xdata.xdata_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND(lk, frame, -1, op_errno, NULL, NULL); + GF_FREE(req.xdata.xdata_val); + + return 0; +} + +int32_t +client3_3_inodelk(call_frame_t *frame, xlator_t *this, void *data) +{ + clnt_conf_t *conf = NULL; + clnt_args_t *args = NULL; + gfs3_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(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, + client3_3_inodelk_cbk, NULL, + (xdrproc_t)xdr_gfs3_inodelk_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + GF_FREE(req.xdata.xdata_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND(inodelk, frame, -1, op_errno, NULL); + GF_FREE(req.xdata.xdata_val); + + return 0; +} + +int32_t +client3_3_finodelk(call_frame_t *frame, xlator_t *this, void *data) +{ + clnt_args_t *args = NULL; + gfs3_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(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, + client3_3_finodelk_cbk, NULL, + (xdrproc_t)xdr_gfs3_finodelk_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + GF_FREE(req.xdata.xdata_val); + return 0; +unwind: + CLIENT_STACK_UNWIND(finodelk, frame, -1, op_errno, NULL); + GF_FREE(req.xdata.xdata_val); + + return 0; +} + +int32_t +client3_3_entrylk(call_frame_t *frame, xlator_t *this, void *data) +{ + clnt_conf_t *conf = NULL; + clnt_args_t *args = NULL; + gfs3_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(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, + client3_3_entrylk_cbk, NULL, + (xdrproc_t)xdr_gfs3_entrylk_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + GF_FREE(req.xdata.xdata_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND(entrylk, frame, -1, op_errno, NULL); + GF_FREE(req.xdata.xdata_val); + + return 0; +} + +int32_t +client3_3_fentrylk(call_frame_t *frame, xlator_t *this, void *data) +{ + clnt_args_t *args = NULL; + gfs3_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(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, + client3_3_fentrylk_cbk, NULL, + (xdrproc_t)xdr_gfs3_fentrylk_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + GF_FREE(req.xdata.xdata_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND(fentrylk, frame, -1, op_errno, NULL); + GF_FREE(req.xdata.xdata_val); + + return 0; +} + +int32_t +client3_3_rchecksum(call_frame_t *frame, xlator_t *this, void *data) +{ + clnt_args_t *args = NULL; + clnt_conf_t *conf = NULL; + gfs3_rchecksum_req req = { + 0, + }; + int op_errno = ESTALE; + int ret = 0; + + if (!frame || !this || !data) + goto unwind; + + args = data; + conf = this->private; + + ret = client_pre_rchecksum(this, &req, args->fd, args->len, args->offset, + args->xdata); + if (ret) { + op_errno = -ret; + goto unwind; + } + ret = client_submit_request(this, &req, frame, conf->fops, + GFS3_OP_RCHECKSUM, client3_3_rchecksum_cbk, + NULL, (xdrproc_t)xdr_gfs3_rchecksum_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + 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; +} + +int32_t +client3_3_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; + gfs3_readdir_req req = { + { + 0, + }, + }; + gfs3_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; + client_payload_t cp; + + if (!frame || !this || !data) + goto unwind; + + args = data; + conf = this->private; + + readdir_rsp_size = xdr_sizeof((xdrproc_t)xdr_gfs3_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(this, &req, args->fd, args->size, args->offset, + args->xdata); + if (ret) { + op_errno = -ret; + goto unwind; + } + + memset(&cp, 0, sizeof(client_payload_t)); + cp.rsphdr = rsphdr; + cp.rsphdr_cnt = count; + cp.rsp_iobref = rsp_iobref; + ret = client_submit_request(this, &req, frame, conf->fops, GFS3_OP_READDIR, + client3_3_readdir_cbk, &cp, + (xdrproc_t)xdr_gfs3_readdir_req); + + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + GF_FREE(req.xdata.xdata_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.xdata_val); + + return 0; +} + +int32_t +client3_3_readdirp(call_frame_t *frame, xlator_t *this, void *data) +{ + clnt_args_t *args = NULL; + gfs3_readdirp_req req = { + { + 0, + }, + }; + gfs3_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; + client_payload_t cp; + + 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(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_gfs3_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; + } + + rsphdr = &vector[0]; + rsphdr->iov_base = iobuf_ptr(rsp_iobuf); + rsphdr->iov_len = iobuf_pagesize(rsp_iobuf); + count = 1; + local->iobref = rsp_iobref; + iobref_add(rsp_iobref, rsp_iobuf); + iobuf_unref(rsp_iobuf); + rsp_iobuf = NULL; + rsp_iobref = NULL; + } + + local->fd = fd_ref(args->fd); + + memset(&cp, 0, sizeof(client_payload_t)); + cp.rsphdr = rsphdr; + cp.rsphdr_cnt = count; + cp.rsp_iobref = rsp_iobref; + ret = client_submit_request(this, &req, frame, conf->fops, GFS3_OP_READDIRP, + client3_3_readdirp_cbk, &cp, + (xdrproc_t)xdr_gfs3_readdirp_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + GF_FREE(req.dict.dict_val); + + return 0; +unwind: + if (rsp_iobref) + iobref_unref(rsp_iobref); + + GF_FREE(req.dict.dict_val); + + CLIENT_STACK_UNWIND(readdirp, frame, -1, op_errno, NULL, NULL); + return 0; +} + +int32_t +client3_3_setattr(call_frame_t *frame, xlator_t *this, void *data) +{ + clnt_conf_t *conf = NULL; + clnt_args_t *args = NULL; + gfs3_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(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, + client3_3_setattr_cbk, NULL, + (xdrproc_t)xdr_gfs3_setattr_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + GF_FREE(req.xdata.xdata_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND(setattr, frame, -1, op_errno, NULL, NULL, NULL); + GF_FREE(req.xdata.xdata_val); + + return 0; +} + +int32_t +client3_3_fsetattr(call_frame_t *frame, xlator_t *this, void *data) +{ + clnt_args_t *args = NULL; + clnt_conf_t *conf = NULL; + gfs3_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(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, + client3_3_fsetattr_cbk, NULL, + (xdrproc_t)xdr_gfs3_fsetattr_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + 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 +client3_3_fallocate(call_frame_t *frame, xlator_t *this, void *data) +{ + clnt_args_t *args = NULL; + clnt_conf_t *conf = NULL; + gfs3_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(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, client3_3_fallocate_cbk, + NULL, (xdrproc_t)xdr_gfs3_fallocate_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + GF_FREE(req.xdata.xdata_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND(fallocate, frame, -1, op_errno, NULL, NULL, NULL); + GF_FREE(req.xdata.xdata_val); + + return 0; +} + +int32_t +client3_3_discard(call_frame_t *frame, xlator_t *this, void *data) +{ + clnt_args_t *args = NULL; + clnt_conf_t *conf = NULL; + gfs3_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(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, + client3_3_discard_cbk, NULL, + (xdrproc_t)xdr_gfs3_discard_req); + if (ret) + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + + GF_FREE(req.xdata.xdata_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND(discard, frame, -1, op_errno, NULL, NULL, NULL); + GF_FREE(req.xdata.xdata_val); + + return 0; +} + +int32_t +client3_3_zerofill(call_frame_t *frame, xlator_t *this, void *data) +{ + clnt_args_t *args = NULL; + clnt_conf_t *conf = NULL; + gfs3_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(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, + client3_3_zerofill_cbk, NULL, + (xdrproc_t)xdr_gfs3_zerofill_req); + if (ret) + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + + GF_FREE(req.xdata.xdata_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND(zerofill, frame, -1, op_errno, NULL, NULL, NULL); + GF_FREE(req.xdata.xdata_val); + + return 0; +} + +int32_t +client3_3_ipc(call_frame_t *frame, xlator_t *this, void *data) +{ + clnt_args_t *args = NULL; + clnt_conf_t *conf = NULL; + gfs3_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(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, + client3_3_ipc_cbk, NULL, + (xdrproc_t)xdr_gfs3_ipc_req); + if (ret) + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + + GF_FREE(req.xdata.xdata_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND(ipc, frame, -1, op_errno, NULL); + GF_FREE(req.xdata.xdata_val); + + return 0; +} + +int32_t +client3_3_seek(call_frame_t *frame, xlator_t *this, void *data) +{ + clnt_args_t *args = NULL; + clnt_conf_t *conf = NULL; + struct gfs3_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(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, + client3_3_seek_cbk, NULL, + (xdrproc_t)xdr_gfs3_seek_req); + if (ret) + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + + GF_FREE(req.xdata.xdata_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND(ipc, frame, -1, op_errno, NULL); + GF_FREE(req.xdata.xdata_val); + + return 0; +} + +static int32_t +client3_3_getactivelk(call_frame_t *frame, xlator_t *this, void *data) +{ + clnt_conf_t *conf = NULL; + clnt_args_t *args = NULL; + gfs3_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; + + 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_GETACTIVELK, client3_3_getactivelk_cbk, + NULL, (xdrproc_t)xdr_gfs3_getactivelk_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + GF_FREE(req.xdata.xdata_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND(getactivelk, frame, -1, op_errno, NULL, NULL); + + GF_FREE(req.xdata.xdata_val); + + return 0; +} + +static int32_t +client3_3_setactivelk(call_frame_t *frame, xlator_t *this, void *data) +{ + clnt_conf_t *conf = NULL; + clnt_args_t *args = NULL; + gfs3_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; + + GF_PROTOCOL_DICT_SERIALIZE(this, args->xdata, (&req.xdata.xdata_val), + req.xdata.xdata_len, op_errno, unwind); + + ret = serialize_req_locklist(args->locklist, &req); + + if (ret) + goto unwind; + + ret = client_submit_request(this, &req, frame, conf->fops, + GFS3_OP_SETACTIVELK, client3_3_setactivelk_cbk, + NULL, (xdrproc_t)xdr_gfs3_setactivelk_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + clnt_setactivelk_req_cleanup(&req); + + GF_FREE(req.xdata.xdata_val); + + return 0; + +unwind: + + CLIENT_STACK_UNWIND(setactivelk, frame, -1, op_errno, NULL); + + GF_FREE(req.xdata.xdata_val); + + clnt_setactivelk_req_cleanup(&req); + + return 0; +} + +/* Table Specific to FOPS */ +rpc_clnt_procedure_t clnt3_3_fop_actors[GF_FOP_MAXVALUE] = { + [GF_FOP_NULL] = {"NULL", NULL}, + [GF_FOP_STAT] = {"STAT", client3_3_stat}, + [GF_FOP_READLINK] = {"READLINK", client3_3_readlink}, + [GF_FOP_MKNOD] = {"MKNOD", client3_3_mknod}, + [GF_FOP_MKDIR] = {"MKDIR", client3_3_mkdir}, + [GF_FOP_UNLINK] = {"UNLINK", client3_3_unlink}, + [GF_FOP_RMDIR] = {"RMDIR", client3_3_rmdir}, + [GF_FOP_SYMLINK] = {"SYMLINK", client3_3_symlink}, + [GF_FOP_RENAME] = {"RENAME", client3_3_rename}, + [GF_FOP_LINK] = {"LINK", client3_3_link}, + [GF_FOP_TRUNCATE] = {"TRUNCATE", client3_3_truncate}, + [GF_FOP_OPEN] = {"OPEN", client3_3_open}, + [GF_FOP_READ] = {"READ", client3_3_readv}, + [GF_FOP_WRITE] = {"WRITE", client3_3_writev}, + [GF_FOP_STATFS] = {"STATFS", client3_3_statfs}, + [GF_FOP_FLUSH] = {"FLUSH", client3_3_flush}, + [GF_FOP_FSYNC] = {"FSYNC", client3_3_fsync}, + [GF_FOP_SETXATTR] = {"SETXATTR", client3_3_setxattr}, + [GF_FOP_GETXATTR] = {"GETXATTR", client3_3_getxattr}, + [GF_FOP_REMOVEXATTR] = {"REMOVEXATTR", client3_3_removexattr}, + [GF_FOP_OPENDIR] = {"OPENDIR", client3_3_opendir}, + [GF_FOP_FSYNCDIR] = {"FSYNCDIR", client3_3_fsyncdir}, + [GF_FOP_ACCESS] = {"ACCESS", client3_3_access}, + [GF_FOP_CREATE] = {"CREATE", client3_3_create}, + [GF_FOP_FTRUNCATE] = {"FTRUNCATE", client3_3_ftruncate}, + [GF_FOP_FSTAT] = {"FSTAT", client3_3_fstat}, + [GF_FOP_LK] = {"LK", client3_3_lk}, + [GF_FOP_LOOKUP] = {"LOOKUP", client3_3_lookup}, + [GF_FOP_READDIR] = {"READDIR", client3_3_readdir}, + [GF_FOP_INODELK] = {"INODELK", client3_3_inodelk}, + [GF_FOP_FINODELK] = {"FINODELK", client3_3_finodelk}, + [GF_FOP_ENTRYLK] = {"ENTRYLK", client3_3_entrylk}, + [GF_FOP_FENTRYLK] = {"FENTRYLK", client3_3_fentrylk}, + [GF_FOP_XATTROP] = {"XATTROP", client3_3_xattrop}, + [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", client3_3_rchecksum}, + [GF_FOP_SETATTR] = {"SETATTR", client3_3_setattr}, + [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}, + [GF_FOP_ZEROFILL] = {"ZEROFILL", client3_3_zerofill}, + [GF_FOP_RELEASE] = {"RELEASE", client3_3_release}, + [GF_FOP_RELEASEDIR] = {"RELEASEDIR", client3_3_releasedir}, + [GF_FOP_GETSPEC] = {"GETSPEC", client3_getspec}, + [GF_FOP_FREMOVEXATTR] = {"FREMOVEXATTR", client3_3_fremovexattr}, + [GF_FOP_IPC] = {"IPC", client3_3_ipc}, + [GF_FOP_SEEK] = {"SEEK", client3_3_seek}, + [GF_FOP_LEASE] = {"LEASE", client3_3_lease}, + [GF_FOP_GETACTIVELK] = {"GETACTIVELK", client3_3_getactivelk}, + [GF_FOP_SETACTIVELK] = {"SETACTIVELK", client3_3_setactivelk}, + [GF_FOP_COMPOUND] = {"COMPOUND", NULL}, +}; + +/* Used From RPC-CLNT library to log proper name of procedure based on number */ +char *clnt3_3_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", +}; + +rpc_clnt_prog_t clnt3_3_fop_prog = { + .progname = "GlusterFS 3.3", + .prognum = GLUSTER_FOP_PROGRAM, + .progver = GLUSTER_FOP_VERSION, + .numproc = GLUSTER_FOP_PROCCNT, + .proctable = clnt3_3_fop_actors, + .procnames = clnt3_3_fop_names, +}; 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..0d80d4e8efb --- /dev/null +++ b/xlators/protocol/client/src/client-rpc-fops_v2.c @@ -0,0 +1,6177 @@ +/* + 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 <glusterfs/compat-errno.h> +#include "client-messages.h" +#include <glusterfs/defaults.h> +#include "client-common.h" + +extern int32_t +client3_getspec(call_frame_t *frame, xlator_t *this, void *data); +extern int32_t +client3_3_getxattr(call_frame_t *frame, xlator_t *this, void *data); + +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_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + 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_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, "source=%s", local->loc.path, + "target=%s", local->loc2.path, NULL); + } + } + + 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_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + 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_smsg(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, + "path=%s", local->loc.path, NULL); + } + + 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_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + 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_smsg(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, + "path=%s", local->loc.path, NULL); + } + + 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_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + 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_smsg(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, + "path=%s", local->loc.path, "gfid=%s", + loc_gfid_utoa(&local->loc), NULL); + } + + 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_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + 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_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, NULL); + } + } + + 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_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + 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_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, NULL); + } + } + + 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_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + 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_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, NULL); + } + } + + 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_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + 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_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, NULL); + } + } + 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_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + 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_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, NULL); + } + 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_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + 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_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, NULL); + } + 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_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + 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_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, NULL); + } 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_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + if ((rsp.op_ret >= 0 || (rsp.op_errno == ENOTCONN)) && + !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_smsg(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, NULL); + } + 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_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + 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_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, NULL); + } + 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_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + 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_smsg(this->name, GF_LOG_WARNING, op_errno, + PC_MSG_REMOTE_OP_FAILED, NULL); + } + } + + 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_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + 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_smsg(this->name, GF_LOG_WARNING, op_errno, + PC_MSG_REMOTE_OP_FAILED, "path=%s", local->loc.path, + "gfid=%s", loc_gfid_utoa(&local->loc), "key=%s", + (local->name) ? local->name : "(null)", NULL); + } + } else { + /* This is required as many places, `if (ret)` is checked + for syncop_getxattr() */ + gf_msg_debug(this->name, 0, "resetting op_ret to 0 from %d", + rsp.op_ret); + rsp.op_ret = 0; + } + + 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_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + 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_smsg(this->name, GF_LOG_WARNING, op_errno, + PC_MSG_REMOTE_OP_FAILED, NULL); + } + } else { + /* This is required as many places, `if (ret)` is checked + for syncop_fgetxattr() */ + gf_msg_debug(this->name, 0, "resetting op_ret to 0 from %d", + rsp.op_ret); + rsp.op_ret = 0; + } + + 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_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + xdr_to_dict(&rsp.xdata, &xdata); +out: + if (rsp.op_ret == -1) { + /* EPERM/EACCESS is returned some times in case of selinux + attributes, or other system attributes which may not be + possible to remove from an user process is encountered. + we can't treat it as an error */ + if ((ENODATA == rsp.op_errno) || (ENOATTR == rsp.op_errno) || + (EPERM == rsp.op_errno) || (EACCES == rsp.op_errno)) + loglevel = GF_LOG_DEBUG; + else + loglevel = GF_LOG_WARNING; + + gf_smsg(this->name, loglevel, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, NULL); + } + + 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_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + xdr_to_dict(&rsp.xdata, &xdata); +out: + if (rsp.op_ret == -1) { + gf_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, NULL); + } + 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_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + xdr_to_dict(&rsp.xdata, &xdata); + +out: + if (rsp.op_ret == -1) { + gf_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, NULL); + } + 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_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + xdr_to_dict(&rsp.xdata, &xdata); + +out: + if (rsp.op_ret == -1) { + gf_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, NULL); + } + 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_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + 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_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, NULL); + } + 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_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + 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_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, NULL); + } + 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_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + xdr_to_dict(&rsp.xdata, &xdata); +out: + if (rsp.op_ret == -1) { + gf_smsg(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, NULL); + } + 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_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + xdr_to_dict(&rsp.xdata, &xdata); +out: + if (rsp.op_ret == -1) { + gf_smsg(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, NULL); + } 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_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + xdr_to_dict(&rsp.xdata, &xdata); +out: + if (rsp.op_ret == -1) { + gf_smsg(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, NULL); + } + + 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_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + 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_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, NULL); + } + + 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_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + 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_smsg(this->name, fop_log_level(GF_FOP_XATTROP, op_errno), + gf_error_to_errno(rsp.op_errno), PC_MSG_REMOTE_OP_FAILED, + "Path=%s", local->loc.path, "gfid=%s", + loc_gfid_utoa(&local->loc), NULL); + } else { + /* This is required as many places, `if (ret)` is checked + for syncop_xattrop() */ + gf_msg_debug(this->name, 0, "resetting op_ret to 0 from %d", + rsp.op_ret); + rsp.op_ret = 0; + } + + 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_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + 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_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, NULL); + } else { + /* This is required as many places, `if (ret)` is checked + for syncop_fxattrop() */ + gf_msg_debug(this->name, 0, "resetting op_ret to 0 from %d", + rsp.op_ret); + 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_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + 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_smsg(this->name, GF_LOG_WARNING, rsp.op_errno, + PC_MSG_REMOTE_OP_FAILED, NULL); + } + } + + 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_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + 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_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, NULL); + } + 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_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + 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_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, NULL); + } + 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_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + 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_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, NULL); + } + 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_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + xdr_to_dict(&rsp.xdata, &xdata); +out: + if (rsp.op_ret == -1) { + gf_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, NULL); + } + 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_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + xdr_to_dict(&rsp.xdata, &xdata); +out: + if (rsp.op_ret == -1) { + gf_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, NULL); + } + 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_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + 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_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, NULL); + } + 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_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + 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_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, NULL); + } + 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_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + ret = client_post_create_v2(this, &rsp, &stbuf, &preparent, &postparent, + local, &xdata); + if (ret < 0) + 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; + } + } + +out: + if (rsp.op_ret == -1) { + gf_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, "path=%s", local->loc.path, NULL); + } + + 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_smsg(this->name, GF_LOG_ERROR, ENOTCONN, PC_MSG_REMOTE_OP_FAILED, + NULL); + 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_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + 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_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, NULL); + } + + 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; + 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_lk_rsp); + if (ret < 0) { + gf_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + 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.*/ + + if (client_is_setlk(local->cmd)) { + 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_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, NULL); + } + + 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_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + 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_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, "remote_fd=%d", local->cmd, NULL); + } + 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_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + 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_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, NULL); + } + 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_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + 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_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, NULL); + } + 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_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + 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_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, "source=%s", local->loc.path, + "target=%s", local->loc2.path, NULL); + } + } + + 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_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + 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_smsg(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, + "path=%s", local->loc.path, "gfid=%s", + loc_gfid_utoa(&local->loc), NULL); + } + 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_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + 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_sizen(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_smsg(this->name, GF_LOG_WARNING, rsp.op_errno, + PC_MSG_REMOTE_OP_FAILED, "path=%s", local->loc.path, + "gfid=%s", loc_gfid_utoa(&local->loc), NULL); + 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; + + 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_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + memset(vector, 0, sizeof(vector)); + + 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_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, NULL); + } 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_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + 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_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, NULL); + } + + 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_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + xdr_to_dict(&rsp.xdata, &xdata); +out: + if (rsp.op_ret == -1) { + gf_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, NULL); + } + + CLIENT_STACK_UNWIND(setactivelk, frame, rsp.op_ret, + gf_error_to_errno(rsp.op_errno), xdata); + + if (xdata) + dict_unref(xdata); + + return 0; +} + +int +client4_0_copy_file_range_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 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_3iatt_rsp); + if (ret < 0) { + gf_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + ret = client_post_common_3iatt(this, &rsp, &stbuf, &prestat, &poststat, + &xdata); + if (ret < 0) + goto out; +out: + if (rsp.op_ret == -1) { + gf_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, NULL); + } else if (rsp.op_ret >= 0) { + if (local->attempt_reopen) + client_attempt_reopen(local->fd, this); + if (local->attempt_reopen_out) + client_attempt_reopen(local->fd_out, this); + } + CLIENT_STACK_UNWIND(copy_file_range, frame, rsp.op_ret, + gf_error_to_errno(rsp.op_errno), &stbuf, &prestat, + &poststat, 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_spin_lock(&conf->fd_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_spin_unlock(&conf->fd_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; + gf_boolean_t destroy = _gf_false; + + if (!this || !data) + goto out; + + args = data; + conf = this->private; + + pthread_spin_lock(&conf->fd_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_spin_unlock(&conf->fd_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; + client_payload_t cp; + + if (!frame || !this || !data) + goto unwind; + + 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_sizen(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); + memset(vector, 0, sizeof(vector)); + 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; + } + + memset(&cp, 0, sizeof(client_payload_t)); + + cp.rsphdr = rsphdr; + cp.rsphdr_cnt = count; + cp.rsp_iobref = local->iobref; + ret = client_submit_request(this, &req, frame, conf->fops, GFS3_OP_LOOKUP, + client4_0_lookup_cbk, &cp, + (xdrproc_t)xdr_gfx_lookup_req); + + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + 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, + (xdrproc_t)xdr_gfx_stat_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + 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, + (xdrproc_t)xdr_gfx_truncate_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + 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, (xdrproc_t)xdr_gfx_ftruncate_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + 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, + (xdrproc_t)xdr_gfx_access_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + 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, + (xdrproc_t)xdr_gfx_readlink_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + 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, + (xdrproc_t)xdr_gfx_unlink_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + 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, + (xdrproc_t)xdr_gfx_rmdir_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + 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, + (xdrproc_t)xdr_gfx_symlink_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + 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, + (xdrproc_t)xdr_gfx_rename_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + 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, + (xdrproc_t)xdr_gfx_link_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + 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, + (xdrproc_t)xdr_gfx_mknod_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + 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_sizen(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, + (xdrproc_t)xdr_gfx_mkdir_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + 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, + (xdrproc_t)xdr_gfx_create_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + 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, + (xdrproc_t)xdr_gfx_open_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + 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; + client_payload_t cp; + + 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_smsg(this->name, GF_LOG_WARNING, ENOMEM, PC_MSG_BIGGER_SIZE, + "read-size=%lu", (unsigned long)args->size, "iobuf-size=%lu", + (unsigned long)rsp_vec.iov_len, NULL); + op_errno = EINVAL; + goto unwind; + } + + memset(&cp, 0, sizeof(client_payload_t)); + + cp.rsp_payload = &rsp_vec; + cp.rsp_payload_cnt = 1; + cp.rsp_iobref = local->iobref; + ret = client_submit_request(this, &req, frame, conf->fops, GFS3_OP_READ, + client4_0_readv_cbk, &cp, + (xdrproc_t)xdr_gfx_read_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + GF_FREE(req.xdata.pairs.pairs_val); + + return 0; +unwind: + if (rsp_iobuf) + iobuf_unref(rsp_iobuf); + + 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; + client_payload_t cp; + + 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; + } + + memset(&cp, 0, sizeof(client_payload_t)); + + cp.iobref = args->iobref; + cp.payload = args->vector; + cp.payload_cnt = args->count; + ret = client_submit_request(this, &req, frame, conf->fops, GFS3_OP_WRITE, + client4_0_writev_cbk, &cp, + (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_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + 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; + if (op_errno == EBADF) { + 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); + } + + goto unwind; + } + ret = client_submit_request(this, &req, frame, conf->fops, GFS3_OP_FLUSH, + client4_0_flush_cbk, NULL, + (xdrproc_t)xdr_gfx_flush_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + 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, + (xdrproc_t)xdr_gfx_fsync_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + 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, + (xdrproc_t)xdr_gfx_fstat_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + 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, + (xdrproc_t)xdr_gfx_opendir_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + 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, + (xdrproc_t)xdr_gfx_fsyncdir_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + 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, + (xdrproc_t)xdr_gfx_statfs_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + 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, + (xdrproc_t)xdr_gfx_setxattr_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + 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, (xdrproc_t)xdr_gfx_fsetxattr_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + 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, (xdrproc_t)xdr_gfx_fgetxattr_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + 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_smsg(this->name, GF_LOG_WARNING, EINVAL, + PC_MSG_CLIENT_DUMP_LOCKS_FAILED, NULL); + 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, + (xdrproc_t)xdr_gfx_getxattr_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + 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, + (xdrproc_t)xdr_gfx_xattrop_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + 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, + (xdrproc_t)xdr_gfx_fxattrop_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + 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, (xdrproc_t)xdr_gfx_removexattr_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + 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, (xdrproc_t)xdr_gfx_fremovexattr_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + 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, + (xdrproc_t)xdr_gfx_lease_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + 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_smsg(this->name, GF_LOG_WARNING, EINVAL, PC_MSG_UNKNOWN_CMD, + "gf_cmd=%d", gf_cmd, NULL); + 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; + + if ((op_errno == EBADF) && (args->flock->l_type == F_UNLCK) && + client_is_setlk(local->cmd)) { + client_add_lock_for_recovery(local->fd, args->flock, &local->owner, + local->cmd); + } + + goto unwind; + } + + ret = client_submit_request(this, &req, frame, conf->fops, GFS3_OP_LK, + client4_0_lk_cbk, NULL, + (xdrproc_t)xdr_gfx_lk_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + 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, + (xdrproc_t)xdr_gfx_inodelk_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + 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, + (xdrproc_t)xdr_gfx_finodelk_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + 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, + (xdrproc_t)xdr_gfx_entrylk_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + 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, + (xdrproc_t)xdr_gfx_fentrylk_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + 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; + client_payload_t cp; + + 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; + } + + memset(&cp, 0, sizeof(client_payload_t)); + + cp.rsphdr = rsphdr; + cp.rsphdr_cnt = count; + cp.rsp_iobref = rsp_iobref; + ret = client_submit_request(this, &req, frame, conf->fops, GFS3_OP_READDIR, + client4_0_readdir_cbk, &cp, + (xdrproc_t)xdr_gfx_readdir_req); + + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + 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; + client_payload_t cp; + + 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; + } + + rsphdr = &vector[0]; + rsphdr->iov_base = iobuf_ptr(rsp_iobuf); + rsphdr->iov_len = iobuf_pagesize(rsp_iobuf); + count = 1; + local->iobref = rsp_iobref; + iobref_add(rsp_iobref, rsp_iobuf); + iobuf_unref(rsp_iobuf); + rsp_iobuf = NULL; + rsp_iobref = NULL; + } + + local->fd = fd_ref(args->fd); + + memset(&cp, 0, sizeof(client_payload_t)); + + cp.rsphdr = rsphdr; + cp.rsphdr_cnt = count; + cp.rsp_iobref = rsp_iobref; + ret = client_submit_request(this, &req, frame, conf->fops, GFS3_OP_READDIRP, + client4_0_readdirp_cbk, &cp, + (xdrproc_t)xdr_gfx_readdirp_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + 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, + (xdrproc_t)xdr_gfx_setattr_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + 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, (xdrproc_t)xdr_gfx_fallocate_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + 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, + (xdrproc_t)xdr_gfx_discard_req); + if (ret) + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + + 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, + (xdrproc_t)xdr_gfx_zerofill_req); + if (ret) + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + + 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, + (xdrproc_t)xdr_gfx_ipc_req); + if (ret) + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + + 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, + (xdrproc_t)xdr_gfx_seek_req); + if (ret) + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + + 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, (xdrproc_t)xdr_gfx_getactivelk_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + 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, (xdrproc_t)xdr_gfx_setactivelk_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + 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_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + xdr_to_dict(&rsp.xdata, &xdata); +out: + if (rsp.op_ret == -1) { + gf_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, NULL); + } + + 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; +} + +int +client4_0_put_cbk(struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + gfx_common_3iatt_rsp rsp = { + 0, + }; + call_frame_t *frame = NULL; + int ret = 0; + xlator_t *this = NULL; + dict_t *xdata = NULL; + clnt_local_t *local = NULL; + struct iatt stbuf = { + 0, + }; + struct iatt preparent = { + 0, + }; + struct iatt postparent = { + 0, + }; + inode_t *inode = 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_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_XDR_DECODING_FAILED, + NULL); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + if (-1 != rsp.op_ret) { + ret = client_post_common_3iatt(this, &rsp, &stbuf, &preparent, + &postparent, &xdata); + if (ret < 0) + goto out; + } +out: + if (rsp.op_ret == -1) { + gf_smsg(this->name, GF_LOG_WARNING, gf_error_to_errno(rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, NULL); + } + + CLIENT_STACK_UNWIND(put, frame, rsp.op_ret, gf_error_to_errno(rsp.op_errno), + inode, &stbuf, &preparent, &postparent, xdata); + + if (xdata) + dict_unref(xdata); + + return 0; +} + +int32_t +client4_0_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, + (xdrproc_t)xdr_gfx_namelink_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + 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_0_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, + (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_put(call_frame_t *frame, xlator_t *this, void *data) +{ + clnt_args_t *args = NULL; + clnt_conf_t *conf = NULL; + gfx_put_req req = { + { + 0, + }, + }; + int op_errno = ESTALE; + int ret = 0; + clnt_local_t *local = NULL; + client_payload_t cp; + + 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_put_v2(this, &req, args->loc, args->mode, args->umask, + args->flags, args->size, args->offset, args->xattr, + args->xdata); + + if (ret) { + op_errno = -ret; + goto unwind; + } + + memset(&cp, 0, sizeof(client_payload_t)); + + cp.iobref = args->iobref; + cp.payload = args->vector; + cp.payload_cnt = args->count; + ret = client_submit_request(this, &req, frame, conf->fops, GFS3_OP_PUT, + client4_0_put_cbk, &cp, + (xdrproc_t)xdr_gfx_put_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_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + return 0; + +unwind: + CLIENT_STACK_UNWIND(put, frame, -1, op_errno, NULL, NULL, NULL, NULL, NULL); + return 0; +} + +int32_t +client4_0_copy_file_range(call_frame_t *frame, xlator_t *this, void *data) +{ + clnt_args_t *args = NULL; + clnt_conf_t *conf = NULL; + clnt_local_t *local = NULL; + gfx_copy_file_range_req req = { + { + 0, + }, + }; + int op_errno = ESTALE; + int ret = 0; + + if (!frame || !this || !data) + goto unwind; + + args = data; + conf = this->private; + + ret = client_pre_copy_file_range_v2(this, &req, args->fd, args->off_in, + args->fd_out, args->off_out, args->size, + args->flags, &args->xdata); + + if (ret) { + op_errno = -ret; + goto unwind; + } + + ret = client_fd_fop_prepare_local(frame, args->fd, req.fd_in); + if (ret) { + op_errno = -ret; + goto unwind; + } + + /* + * Since frame->local is allocated in above function call + * itself, better to use it (with the assumption that it + * has been allocated) directly instead of again calling + * client_fd_fop_prepare_local or modifying it, as doing + * so requires changes in other places as well. + */ + + local = frame->local; + local->fd_out = fd_ref(args->fd_out); + local->attempt_reopen_out = client_is_reopen_needed(args->fd_out, this, + req.fd_out); + + ret = client_submit_request(this, &req, frame, conf->fops, + GFS3_OP_COPY_FILE_RANGE, + client4_0_copy_file_range_cbk, NULL, + (xdrproc_t)xdr_gfx_copy_file_range_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_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + GF_FREE(req.xdata.pairs.pairs_val); + + return 0; + +unwind: + CLIENT_STACK_UNWIND(copy_file_range, frame, -1, op_errno, NULL, NULL, NULL, + NULL); + GF_FREE(req.xdata.pairs.pairs_val); + + 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, + (xdrproc_t)xdr_gfx_fsetattr_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + 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, + (xdrproc_t)xdr_gfx_rchecksum_req); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, NULL); + } + + 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; +} + +/* 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", +}; + +rpc_clnt_procedure_t clnt4_0_fop_actors[GF_FOP_MAXVALUE] = { + [GF_FOP_NULL] = {"NULL", NULL}, + [GF_FOP_STAT] = {"STAT", client4_0_stat}, + [GF_FOP_READLINK] = {"READLINK", client4_0_readlink}, + [GF_FOP_MKNOD] = {"MKNOD", client4_0_mknod}, + [GF_FOP_MKDIR] = {"MKDIR", client4_0_mkdir}, + [GF_FOP_UNLINK] = {"UNLINK", client4_0_unlink}, + [GF_FOP_RMDIR] = {"RMDIR", client4_0_rmdir}, + [GF_FOP_SYMLINK] = {"SYMLINK", client4_0_symlink}, + [GF_FOP_RENAME] = {"RENAME", client4_0_rename}, + [GF_FOP_LINK] = {"LINK", client4_0_link}, + [GF_FOP_TRUNCATE] = {"TRUNCATE", client4_0_truncate}, + [GF_FOP_OPEN] = {"OPEN", client4_0_open}, + [GF_FOP_READ] = {"READ", client4_0_readv}, + [GF_FOP_WRITE] = {"WRITE", client4_0_writev}, + [GF_FOP_STATFS] = {"STATFS", client4_0_statfs}, + [GF_FOP_FLUSH] = {"FLUSH", client4_0_flush}, + [GF_FOP_FSYNC] = {"FSYNC", client4_0_fsync}, + [GF_FOP_GETXATTR] = {"GETXATTR", client4_0_getxattr}, + [GF_FOP_SETXATTR] = {"SETXATTR", client4_0_setxattr}, + [GF_FOP_REMOVEXATTR] = {"REMOVEXATTR", client4_0_removexattr}, + [GF_FOP_OPENDIR] = {"OPENDIR", client4_0_opendir}, + [GF_FOP_FSYNCDIR] = {"FSYNCDIR", client4_0_fsyncdir}, + [GF_FOP_ACCESS] = {"ACCESS", client4_0_access}, + [GF_FOP_CREATE] = {"CREATE", client4_0_create}, + [GF_FOP_FTRUNCATE] = {"FTRUNCATE", client4_0_ftruncate}, + [GF_FOP_FSTAT] = {"FSTAT", client4_0_fstat}, + [GF_FOP_LK] = {"LK", client4_0_lk}, + [GF_FOP_LOOKUP] = {"LOOKUP", client4_0_lookup}, + [GF_FOP_READDIR] = {"READDIR", client4_0_readdir}, + [GF_FOP_INODELK] = {"INODELK", client4_0_inodelk}, + [GF_FOP_FINODELK] = {"FINODELK", client4_0_finodelk}, + [GF_FOP_ENTRYLK] = {"ENTRYLK", client4_0_entrylk}, + [GF_FOP_FENTRYLK] = {"FENTRYLK", client4_0_fentrylk}, + [GF_FOP_XATTROP] = {"XATTROP", client4_0_xattrop}, + [GF_FOP_FXATTROP] = {"FXATTROP", client4_0_fxattrop}, + [GF_FOP_FGETXATTR] = {"FGETXATTR", client4_0_fgetxattr}, + [GF_FOP_FSETXATTR] = {"FSETXATTR", client4_0_fsetxattr}, + [GF_FOP_RCHECKSUM] = {"RCHECKSUM", client4_0_rchecksum}, + [GF_FOP_SETATTR] = {"SETATTR", client4_0_setattr}, + [GF_FOP_FSETATTR] = {"FSETATTR", client4_0_fsetattr}, + [GF_FOP_READDIRP] = {"READDIRP", client4_0_readdirp}, + [GF_FOP_FALLOCATE] = {"FALLOCATE", client4_0_fallocate}, + [GF_FOP_DISCARD] = {"DISCARD", client4_0_discard}, + [GF_FOP_ZEROFILL] = {"ZEROFILL", client4_0_zerofill}, + [GF_FOP_RELEASE] = {"RELEASE", client4_0_release}, + [GF_FOP_RELEASEDIR] = {"RELEASEDIR", client4_0_releasedir}, + [GF_FOP_GETSPEC] = {"GETSPEC", client3_getspec}, + [GF_FOP_FREMOVEXATTR] = {"FREMOVEXATTR", client4_0_fremovexattr}, + [GF_FOP_IPC] = {"IPC", client4_0_ipc}, + [GF_FOP_SEEK] = {"SEEK", client4_0_seek}, + [GF_FOP_LEASE] = {"LEASE", client4_0_lease}, + [GF_FOP_GETACTIVELK] = {"GETACTIVELK", client4_0_getactivelk}, + [GF_FOP_SETACTIVELK] = {"SETACTIVELK", client4_0_setactivelk}, + [GF_FOP_COMPOUND] = {"COMPOUND", NULL}, + [GF_FOP_ICREATE] = {"ICREATE", client4_0_icreate}, + [GF_FOP_NAMELINK] = {"NAMELINK", client4_0_namelink}, + [GF_FOP_COPY_FILE_RANGE] = {"COPY-FILE-RANGE", client4_0_copy_file_range}, +}; + +rpc_clnt_prog_t clnt4_0_fop_prog = { + .progname = "GlusterFS 4.x v1", + .prognum = GLUSTER_FOP_PROGRAM, + .progver = GLUSTER_FOP_VERSION_v2, + .numproc = GLUSTER_FOP_PROCCNT, + .proctable = clnt4_0_fop_actors, + .procnames = clnt4_0_fop_names, +}; diff --git a/xlators/protocol/client/src/client.c b/xlators/protocol/client/src/client.c index 03e0ec44266..0f31fea9511 100644 --- a/xlators/protocol/client/src/client.c +++ b/xlators/protocol/client/src/client.c @@ -1,2002 +1,2997 @@ /* - Copyright (c) 2010 Gluster, Inc. <http://www.gluster.com> + Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.com> This file is part of GlusterFS. - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. + 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. */ - -#ifndef _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif - #include "client.h" -#include "xlator.h" -#include "defaults.h" -#include "glusterfs.h" -#include "statedump.h" -#include "compat-errno.h" - +#include <glusterfs/xlator.h> +#include <glusterfs/defaults.h> +#include <glusterfs/glusterfs.h> +#include <glusterfs/statedump.h> +#include <glusterfs/compat-errno.h> +#include <glusterfs/gf-event.h> + +#include "xdr-rpc.h" #include "glusterfs3.h" +#include "client-messages.h" extern rpc_clnt_prog_t clnt_handshake_prog; extern rpc_clnt_prog_t clnt_dump_prog; extern struct rpcclnt_cb_program gluster_cbk_prog; -int client_handshake (xlator_t *this, struct rpc_clnt *rpc); -void client_start_ping (void *data); -int client_init_rpc (xlator_t *this); -int client_destroy_rpc (xlator_t *this); - int -client_submit_request (xlator_t *this, void *req, call_frame_t *frame, - rpc_clnt_prog_t *prog, int procnum, fop_cbk_fn_t cbk, - struct iobref *iobref, gfs_serialize_t sfunc, - struct iovec *rsphdr, int rsphdr_count, - struct iovec *rsp_payload, int rsp_payload_count, - struct iobref *rsp_iobref) -{ - int ret = -1; - clnt_conf_t *conf = NULL; - struct iovec iov = {0, }; - struct iobuf *iobuf = NULL; - int count = 0; - char new_iobref = 0, start_ping = 0; - - if (!this || !prog || !frame) - goto out; +client_handshake(xlator_t *this, struct rpc_clnt *rpc); +static int +client_destroy_rpc(xlator_t *this); - conf = this->private; +static void +client_filter_o_direct(clnt_conf_t *conf, int32_t *flags) +{ + if (conf->filter_o_direct) + *flags = (*flags & ~O_DIRECT); +} - /* If 'setvolume' is not successful, we should not send frames to - server, mean time we should be able to send 'DUMP' and 'SETVOLUME' - call itself even if its not connected */ - if (!(conf->connected || - ((prog->prognum == GLUSTER_DUMP_PROGRAM) || - (prog->prognum == GLUSTER_PMAP_PROGRAM) || - ((prog->prognum == GLUSTER_HNDSK_PROGRAM) && (procnum == GF_HNDSK_SETVOLUME))))) - goto out; +static int +client_fini_complete(xlator_t *this) +{ + GF_VALIDATE_OR_GOTO(this->name, this->private, out); - iobuf = iobuf_get (this->ctx->iobuf_pool); - if (!iobuf) { - goto out; - }; + clnt_conf_t *conf = this->private; + if (!conf->destroy) + return 0; - if (!iobref) { - iobref = iobref_new (); - if (!iobref) { - goto out; - } + pthread_mutex_lock(&conf->lock); + { + conf->fini_completed = _gf_true; + pthread_cond_broadcast(&conf->fini_complete_cond); + } + pthread_mutex_unlock(&conf->lock); - new_iobref = 1; - } +out: + return 0; +} + +static int +client_is_last_child_down(xlator_t *this, int32_t event, struct rpc_clnt *rpc) +{ + rpc_clnt_connection_t *conn = NULL; + clnt_conf_t *conf = NULL; + int ret = 0; - iobref_add (iobref, iobuf); + if (!this || !rpc) + goto out; - iov.iov_base = iobuf->ptr; - iov.iov_len = 128 * GF_UNIT_KB; + conf = this->private; + if (!conf) + goto out; - /* Create the xdr payload */ - if (req && sfunc) { - ret = sfunc (iov, req); - if (ret == -1) { - goto out; - } - iov.iov_len = ret; - count = 1; + if (!conf->parent_down) + goto out; + + if (event != GF_EVENT_CHILD_DOWN) + goto out; + + conn = &rpc->conn; + pthread_mutex_lock(&conn->lock); + { + if (!conn->reconnect && rpc->disabled) { + ret = 1; } - /* Send the msg */ - ret = rpc_clnt_submit (conf->rpc, prog, procnum, cbk, &iov, count, NULL, - 0, iobref, frame, rsphdr, rsphdr_count, - rsp_payload, rsp_payload_count, rsp_iobref); + } + pthread_mutex_unlock(&conn->lock); +out: + return ret; +} - if (ret == 0) { - pthread_mutex_lock (&conf->rpc->conn.lock); - { - if (!conf->rpc->conn.ping_started) { - start_ping = 1; - } +int +client_notify_dispatch_uniq(xlator_t *this, int32_t event, void *data, ...) +{ + clnt_conf_t *conf = this->private; + glusterfs_ctx_t *ctx = this->ctx; + glusterfs_graph_t *graph = this->graph; + + pthread_mutex_lock(&ctx->notify_lock); + { + while (ctx->notifying) + pthread_cond_wait(&ctx->notify_cond, &ctx->notify_lock); + + if (client_is_last_child_down(this, event, data) && graph) { + pthread_mutex_lock(&graph->mutex); + { + graph->parent_down++; + if (graph->parent_down == graph_total_client_xlator(graph)) { + graph->used = 0; + pthread_cond_broadcast(&graph->child_down_cond); } - pthread_mutex_unlock (&conf->rpc->conn.lock); + } + pthread_mutex_unlock(&graph->mutex); } + } + pthread_mutex_unlock(&ctx->notify_lock); - if (start_ping) - client_start_ping ((void *) this); - - ret = 0; -out: - if (new_iobref) - iobref_unref (iobref); + if (conf->last_sent_event == event) + return 0; - if (iobuf) - iobuf_unref (iobuf); + return client_notify_dispatch(this, event, data); - return ret; + /* Please avoid any code that access xlator object here + * Because for a child down event, once we do the signal + * we will start cleanup. + */ } - -int32_t -client_forget (xlator_t *this, inode_t *inode) +int +client_notify_dispatch(xlator_t *this, int32_t event, void *data, ...) { - /* Nothing here */ - return 0; + int ret = -1; + glusterfs_ctx_t *ctx = this->ctx; + + clnt_conf_t *conf = this->private; + + pthread_mutex_lock(&ctx->notify_lock); + { + while (ctx->notifying) + pthread_cond_wait(&ctx->notify_cond, &ctx->notify_lock); + ctx->notifying = 1; + } + pthread_mutex_unlock(&ctx->notify_lock); + + /* We assume that all translators in the graph handle notification + * events in sequence. + * */ + + ret = default_notify(this, event, data); + + /* NB (Even) with MT-epoll and EPOLLET|EPOLLONESHOT we are guaranteed + * that there would be atmost one poller thread executing this + * notification function. This allows us to update last_sent_event + * without explicit synchronization. See epoll(7). + */ + conf->last_sent_event = event; + + pthread_mutex_lock(&ctx->notify_lock); + { + ctx->notifying = 0; + pthread_cond_signal(&ctx->notify_cond); + } + pthread_mutex_unlock(&ctx->notify_lock); + + /* Please avoid any code that access xlator object here + * Because for a child down event, once we do the signal + * we will start cleanup. + */ + + return ret; } -int32_t -client_releasedir (xlator_t *this, fd_t *fd) +int +client_submit_request(xlator_t *this, void *req, call_frame_t *frame, + rpc_clnt_prog_t *prog, int procnum, fop_cbk_fn_t cbkfn, + client_payload_t *cp, xdrproc_t xdrproc) { - int ret = -1; - clnt_conf_t *conf = NULL; - rpc_clnt_procedure_t *proc = NULL; - clnt_args_t args = {0,}; - call_frame_t *frame = NULL; - - conf = this->private; - if (!conf->fops) - goto out; + int ret = -1; + clnt_conf_t *conf = NULL; + struct iovec iov = { + 0, + }; + struct iobuf *iobuf = NULL; + int count = 0; + struct iobref *new_iobref = NULL; + ssize_t xdr_size = 0; + struct rpc_req rpcreq = { + 0, + }; + + GF_VALIDATE_OR_GOTO("client", this, out); + GF_VALIDATE_OR_GOTO(this->name, prog, out); + GF_VALIDATE_OR_GOTO(this->name, frame, out); + + conf = this->private; + + /* If 'setvolume' is not successful, we should not send frames to + server, mean time we should be able to send 'DUMP' and 'SETVOLUME' + call itself even if its not connected */ + if (!(conf->connected || ((prog->prognum == GLUSTER_DUMP_PROGRAM) || + (prog->prognum == GLUSTER_PMAP_PROGRAM) || + ((prog->prognum == GLUSTER_HNDSK_PROGRAM) && + (procnum == GF_HNDSK_SETVOLUME))))) { + /* This particular error captured/logged in + functions calling this */ + gf_msg_debug(this->name, 0, "connection in disconnected state"); + goto out; + } + + if (req && xdrproc) { + xdr_size = xdr_sizeof(xdrproc, req); + iobuf = iobuf_get2(this->ctx->iobuf_pool, xdr_size); + if (!iobuf) { + goto out; + } - args.fd = fd; + new_iobref = iobref_new(); + if (!new_iobref) { + goto out; + } - proc = &conf->fops->proctable[GF_FOP_RELEASEDIR]; - if (proc->fn) { - frame = create_frame (this, this->ctx->pool); - if (!frame) { - goto out; - } - ret = proc->fn (frame, this, &args); + if (cp && cp->iobref != NULL) { + ret = iobref_merge(new_iobref, cp->iobref); + if (ret != 0) { + gf_smsg(this->name, GF_LOG_WARNING, ENOMEM, + PC_MSG_MERGE_IOBREF_FAILED, NULL); + } } -out: - if (ret) - gf_log (this->name, GF_LOG_TRACE, - "releasedir fop failed"); - return 0; -} -int32_t -client_release (xlator_t *this, fd_t *fd) -{ - int ret = -1; - clnt_conf_t *conf = NULL; - rpc_clnt_procedure_t *proc = NULL; - clnt_args_t args = {0,}; - call_frame_t *frame = NULL; + ret = iobref_add(new_iobref, iobuf); + if (ret != 0) { + gf_smsg(this->name, GF_LOG_WARNING, ENOMEM, PC_MSG_ADD_IOBUF_FAILED, + NULL); + goto out; + } - conf = this->private; - if (!conf->fops) - goto out; + iov.iov_base = iobuf->ptr; + iov.iov_len = iobuf_size(iobuf); - args.fd = fd; - proc = &conf->fops->proctable[GF_FOP_RELEASE]; - if (proc->fn) { - frame = create_frame (this, this->ctx->pool); - if (!frame) { - goto out; - } - ret = proc->fn (frame, this, &args); + /* Create the xdr payload */ + ret = xdr_serialize_generic(iov, req, xdrproc); + if (ret == -1) { + /* callingfn so that, we can get to know which xdr + function was called */ + gf_log_callingfn(this->name, GF_LOG_WARNING, + "XDR payload creation failed"); + goto out; } -out: - if (ret) - gf_log (this->name, GF_LOG_TRACE, - "release fop failed"); - return 0; -} + iov.iov_len = ret; + count = 1; + } + + /* do not send all groups if they are resolved server-side */ + if (!conf->send_gids) { + if (frame->root->ngrps <= SMALL_GROUP_COUNT) { + frame->root->groups_small[0] = frame->root->gid; + frame->root->groups = frame->root->groups_small; + } + frame->root->ngrps = 1; + } + /* Send the msg */ + if (cp) { + ret = rpc_clnt_submit(conf->rpc, prog, procnum, cbkfn, &iov, count, + cp->payload, cp->payload_cnt, new_iobref, frame, + cp->rsphdr, cp->rsphdr_cnt, cp->rsp_payload, + cp->rsp_payload_cnt, cp->rsp_iobref); + } else { + ret = rpc_clnt_submit(conf->rpc, prog, procnum, cbkfn, &iov, count, + NULL, 0, new_iobref, frame, NULL, 0, NULL, 0, + NULL); + } -int32_t -client_lookup (call_frame_t *frame, xlator_t *this, loc_t *loc, - dict_t *xattr_req) -{ - int ret = -1; - clnt_conf_t *conf = NULL; - rpc_clnt_procedure_t *proc = NULL; - clnt_args_t args = {0,}; + if (ret < 0) { + gf_msg_debug(this->name, 0, "rpc_clnt_submit failed"); + } - conf = this->private; - if (!conf->fops) - goto out; + ret = 0; - args.loc = loc; - args.dict = xattr_req; + if (new_iobref) + iobref_unref(new_iobref); + + if (iobuf) + iobuf_unref(iobuf); + + return ret; - proc = &conf->fops->proctable[GF_FOP_LOOKUP]; - if (proc->fn) - ret = proc->fn (frame, this, &args); out: - /* think of avoiding a missing frame */ - if (ret) - STACK_UNWIND_STRICT (lookup, frame, -1, ENOTCONN, - NULL, NULL, NULL, NULL); + rpcreq.rpc_status = -1; + + cbkfn(&rpcreq, NULL, 0, frame); + + if (new_iobref) + iobref_unref(new_iobref); - return 0; + if (iobuf) + iobuf_unref(iobuf); + + return ret; } +static int32_t +client_forget(xlator_t *this, inode_t *inode) +{ + /* Nothing here */ + return 0; +} -int32_t -client_stat (call_frame_t *frame, xlator_t *this, loc_t *loc) +static int32_t +client_releasedir(xlator_t *this, fd_t *fd) { - int ret = -1; - clnt_conf_t *conf = NULL; - rpc_clnt_procedure_t *proc = NULL; - clnt_args_t args = {0,}; + int ret = -1; + clnt_conf_t *conf = NULL; + rpc_clnt_procedure_t *proc = NULL; + clnt_args_t args = { + 0, + }; + + conf = this->private; + if (!conf || !conf->fops) + goto out; + + proc = &conf->fops->proctable[GF_FOP_RELEASEDIR]; + if (proc->fn) { + args.fd = fd; + ret = proc->fn(NULL, this, &args); + } +out: + if (ret) + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_RELEASE_DIR_OP_FAILED, + NULL); + return 0; +} - conf = this->private; - if (!conf->fops) - goto out; +static int32_t +client_release(xlator_t *this, fd_t *fd) +{ + int ret = -1; + clnt_conf_t *conf = NULL; + rpc_clnt_procedure_t *proc = NULL; + clnt_args_t args = { + 0, + }; + + conf = this->private; + if (!conf || !conf->fops) + goto out; + + proc = &conf->fops->proctable[GF_FOP_RELEASE]; + if (proc->fn) { + args.fd = fd; + ret = proc->fn(NULL, this, &args); + } +out: + if (ret) + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_FILE_OP_FAILED, NULL); + return 0; +} +static int32_t +client_lookup(call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata) +{ + int ret = -1; + clnt_conf_t *conf = NULL; + rpc_clnt_procedure_t *proc = NULL; + clnt_args_t args = { + 0, + }; + + conf = this->private; + if (!conf || !conf->fops) + goto out; + + proc = &conf->fops->proctable[GF_FOP_LOOKUP]; + if (proc->fn) { args.loc = loc; - - proc = &conf->fops->proctable[GF_FOP_STAT]; - if (proc->fn) - ret = proc->fn (frame, this, &args); + args.xdata = xdata; + ret = proc->fn(frame, this, &args); + } out: - if (ret) - STACK_UNWIND_STRICT (stat, frame, -1, ENOTCONN, NULL); + /* think of avoiding a missing frame */ + if (ret) + STACK_UNWIND_STRICT(lookup, frame, -1, ENOTCONN, NULL, NULL, NULL, + NULL); - - return 0; + return 0; } - -int32_t -client_truncate (call_frame_t *frame, xlator_t *this, loc_t *loc, off_t offset) +static int32_t +client_stat(call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata) { - int ret = -1; - clnt_conf_t *conf = NULL; - rpc_clnt_procedure_t *proc = NULL; - clnt_args_t args = {0,}; + int ret = -1; + clnt_conf_t *conf = NULL; + rpc_clnt_procedure_t *proc = NULL; + clnt_args_t args = { + 0, + }; + + conf = this->private; + if (!conf || !conf->fops) + goto out; + + proc = &conf->fops->proctable[GF_FOP_STAT]; + if (proc->fn) { + args.loc = loc; + args.xdata = xdata; + ret = proc->fn(frame, this, &args); + } +out: + if (ret) + STACK_UNWIND_STRICT(stat, frame, -1, ENOTCONN, NULL, NULL); - conf = this->private; - if (!conf->fops) - goto out; + return 0; +} - args.loc = loc; +static int32_t +client_truncate(call_frame_t *frame, xlator_t *this, loc_t *loc, off_t offset, + dict_t *xdata) +{ + int ret = -1; + clnt_conf_t *conf = NULL; + rpc_clnt_procedure_t *proc = NULL; + clnt_args_t args = { + 0, + }; + + conf = this->private; + if (!conf || !conf->fops) + goto out; + + proc = &conf->fops->proctable[GF_FOP_TRUNCATE]; + if (proc->fn) { + args.loc = loc; args.offset = offset; - - proc = &conf->fops->proctable[GF_FOP_TRUNCATE]; - if (proc->fn) - ret = proc->fn (frame, this, &args); + args.xdata = xdata; + ret = proc->fn(frame, this, &args); + } out: - if (ret) - STACK_UNWIND_STRICT (truncate, frame, -1, ENOTCONN, NULL, NULL); - + if (ret) + STACK_UNWIND_STRICT(truncate, frame, -1, ENOTCONN, NULL, NULL, NULL); - return 0; + return 0; } - -int32_t -client_ftruncate (call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset) +static int32_t +client_ftruncate(call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset, + dict_t *xdata) { - int ret = -1; - clnt_conf_t *conf = NULL; - rpc_clnt_procedure_t *proc = NULL; - clnt_args_t args = {0,}; - - conf = this->private; - if (!conf->fops) - goto out; - - args.fd = fd; + int ret = -1; + clnt_conf_t *conf = NULL; + rpc_clnt_procedure_t *proc = NULL; + clnt_args_t args = { + 0, + }; + + conf = this->private; + if (!conf || !conf->fops) + goto out; + + proc = &conf->fops->proctable[GF_FOP_FTRUNCATE]; + if (proc->fn) { + args.fd = fd; args.offset = offset; - - proc = &conf->fops->proctable[GF_FOP_FTRUNCATE]; - if (proc->fn) - ret = proc->fn (frame, this, &args); + args.xdata = xdata; + ret = proc->fn(frame, this, &args); + } out: - if (ret) - STACK_UNWIND_STRICT (ftruncate, frame, -1, ENOTCONN, NULL, NULL); + if (ret) + STACK_UNWIND_STRICT(ftruncate, frame, -1, ENOTCONN, NULL, NULL, NULL); - return 0; + return 0; } - - -int32_t -client_access (call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t mask) +static int32_t +client_access(call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t mask, + dict_t *xdata) { - int ret = -1; - clnt_conf_t *conf = NULL; - rpc_clnt_procedure_t *proc = NULL; - clnt_args_t args = {0,}; - - conf = this->private; - if (!conf->fops) - goto out; - - args.loc = loc; + int ret = -1; + clnt_conf_t *conf = NULL; + rpc_clnt_procedure_t *proc = NULL; + clnt_args_t args = { + 0, + }; + + conf = this->private; + if (!conf || !conf->fops) + goto out; + + proc = &conf->fops->proctable[GF_FOP_ACCESS]; + if (proc->fn) { + args.loc = loc; args.mask = mask; - - proc = &conf->fops->proctable[GF_FOP_ACCESS]; - if (proc->fn) - ret = proc->fn (frame, this, &args); + args.xdata = xdata; + ret = proc->fn(frame, this, &args); + } out: - if (ret) - STACK_UNWIND_STRICT (access, frame, -1, ENOTCONN); + if (ret) + STACK_UNWIND_STRICT(access, frame, -1, ENOTCONN, NULL); - return 0; + return 0; } - - - -int32_t -client_readlink (call_frame_t *frame, xlator_t *this, loc_t *loc, size_t size) +static int32_t +client_readlink(call_frame_t *frame, xlator_t *this, loc_t *loc, size_t size, + dict_t *xdata) { - int ret = -1; - clnt_conf_t *conf = NULL; - rpc_clnt_procedure_t *proc = NULL; - clnt_args_t args = {0,}; - - conf = this->private; - if (!conf->fops) - goto out; - - args.loc = loc; + int ret = -1; + clnt_conf_t *conf = NULL; + rpc_clnt_procedure_t *proc = NULL; + clnt_args_t args = { + 0, + }; + + conf = this->private; + if (!conf || !conf->fops) + goto out; + + proc = &conf->fops->proctable[GF_FOP_READLINK]; + if (proc->fn) { + args.loc = loc; args.size = size; - - proc = &conf->fops->proctable[GF_FOP_READLINK]; - if (proc->fn) - ret = proc->fn (frame, this, &args); + args.xdata = xdata; + ret = proc->fn(frame, this, &args); + } out: - if (ret) - STACK_UNWIND_STRICT (readlink, frame, -1, ENOTCONN, NULL, NULL); + if (ret) + STACK_UNWIND_STRICT(readlink, frame, -1, ENOTCONN, NULL, NULL, NULL); - return 0; + return 0; } - -int -client_mknod (call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode, - dev_t rdev, dict_t *params) +static int +client_mknod(call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode, + dev_t rdev, mode_t umask, dict_t *xdata) { - int ret = -1; - clnt_conf_t *conf = NULL; - rpc_clnt_procedure_t *proc = NULL; - clnt_args_t args = {0,}; - - conf = this->private; - if (!conf->fops) - goto out; - - args.loc = loc; + int ret = -1; + clnt_conf_t *conf = NULL; + rpc_clnt_procedure_t *proc = NULL; + clnt_args_t args = { + 0, + }; + + conf = this->private; + if (!conf || !conf->fops) + goto out; + + proc = &conf->fops->proctable[GF_FOP_MKNOD]; + if (proc->fn) { + args.loc = loc; args.mode = mode; args.rdev = rdev; - args.dict = params; - - proc = &conf->fops->proctable[GF_FOP_MKNOD]; - if (proc->fn) - ret = proc->fn (frame, this, &args); + args.umask = umask; + args.xdata = xdata; + ret = proc->fn(frame, this, &args); + } out: - if (ret) - STACK_UNWIND_STRICT (mknod, frame, -1, ENOTCONN, - NULL, NULL, NULL, NULL); + if (ret) + STACK_UNWIND_STRICT(mknod, frame, -1, ENOTCONN, NULL, NULL, NULL, NULL, + NULL); - return 0; + return 0; } - -int -client_mkdir (call_frame_t *frame, xlator_t *this, loc_t *loc, - mode_t mode, dict_t *params) +static int +client_mkdir(call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode, + mode_t umask, dict_t *xdata) { - int ret = -1; - clnt_conf_t *conf = NULL; - rpc_clnt_procedure_t *proc = NULL; - clnt_args_t args = {0,}; - - conf = this->private; - if (!conf->fops) - goto out; - - args.loc = loc; + int ret = -1; + clnt_conf_t *conf = NULL; + rpc_clnt_procedure_t *proc = NULL; + clnt_args_t args = { + 0, + }; + + conf = this->private; + if (!conf || !conf->fops) + goto out; + + proc = &conf->fops->proctable[GF_FOP_MKDIR]; + if (proc->fn) { + args.loc = loc; args.mode = mode; - args.dict = params; - - proc = &conf->fops->proctable[GF_FOP_MKDIR]; - if (proc->fn) - ret = proc->fn (frame, this, &args); + args.umask = umask; + args.xdata = xdata; + ret = proc->fn(frame, this, &args); + } out: - if (ret) - STACK_UNWIND_STRICT (mkdir, frame, -1, ENOTCONN, - NULL, NULL, NULL, NULL); + if (ret) + STACK_UNWIND_STRICT(mkdir, frame, -1, ENOTCONN, NULL, NULL, NULL, NULL, + NULL); - return 0; + return 0; } - - -int32_t -client_unlink (call_frame_t *frame, xlator_t *this, loc_t *loc) +static int32_t +client_unlink(call_frame_t *frame, xlator_t *this, loc_t *loc, int xflag, + dict_t *xdata) { - int ret = -1; - clnt_conf_t *conf = NULL; - rpc_clnt_procedure_t *proc = NULL; - clnt_args_t args = {0,}; - - conf = this->private; - if (!conf->fops) - goto out; - + int ret = -1; + clnt_conf_t *conf = NULL; + rpc_clnt_procedure_t *proc = NULL; + clnt_args_t args = { + 0, + }; + + conf = this->private; + if (!conf || !conf->fops) + goto out; + + proc = &conf->fops->proctable[GF_FOP_UNLINK]; + if (proc->fn) { args.loc = loc; - - proc = &conf->fops->proctable[GF_FOP_UNLINK]; - if (proc->fn) - ret = proc->fn (frame, this, &args); + args.xdata = xdata; + args.flags = xflag; + ret = proc->fn(frame, this, &args); + } out: - if (ret) - STACK_UNWIND_STRICT (unlink, frame, -1, ENOTCONN, - NULL, NULL); + if (ret) + STACK_UNWIND_STRICT(unlink, frame, -1, ENOTCONN, NULL, NULL, NULL); - return 0; + return 0; } -int32_t -client_rmdir (call_frame_t *frame, xlator_t *this, loc_t *loc) +static int32_t +client_rmdir(call_frame_t *frame, xlator_t *this, loc_t *loc, int flags, + dict_t *xdata) { - int ret = -1; - clnt_conf_t *conf = NULL; - rpc_clnt_procedure_t *proc = NULL; - clnt_args_t args = {0,}; - - conf = this->private; - if (!conf->fops) - goto out; - + int ret = -1; + clnt_conf_t *conf = NULL; + rpc_clnt_procedure_t *proc = NULL; + clnt_args_t args = { + 0, + }; + + conf = this->private; + if (!conf || !conf->fops) + goto out; + + proc = &conf->fops->proctable[GF_FOP_RMDIR]; + if (proc->fn) { args.loc = loc; - - proc = &conf->fops->proctable[GF_FOP_RMDIR]; - if (proc->fn) - ret = proc->fn (frame, this, &args); + args.flags = flags; + args.xdata = xdata; + ret = proc->fn(frame, this, &args); + } out: - /* think of avoiding a missing frame */ - if (ret) - STACK_UNWIND_STRICT (rmdir, frame, -1, ENOTCONN, - NULL, NULL); + /* think of avoiding a missing frame */ + if (ret) + STACK_UNWIND_STRICT(rmdir, frame, -1, ENOTCONN, NULL, NULL, NULL); - return 0; + return 0; } - -int -client_symlink (call_frame_t *frame, xlator_t *this, const char *linkpath, - loc_t *loc, dict_t *params) +static int +client_symlink(call_frame_t *frame, xlator_t *this, const char *linkpath, + loc_t *loc, mode_t umask, dict_t *xdata) { - int ret = -1; - clnt_conf_t *conf = NULL; - rpc_clnt_procedure_t *proc = NULL; - clnt_args_t args = {0,}; - - conf = this->private; - if (!conf->fops) - goto out; - + int ret = -1; + clnt_conf_t *conf = NULL; + rpc_clnt_procedure_t *proc = NULL; + clnt_args_t args = { + 0, + }; + + conf = this->private; + if (!conf || !conf->fops) + goto out; + + proc = &conf->fops->proctable[GF_FOP_SYMLINK]; + if (proc->fn) { args.linkname = linkpath; - args.loc = loc; - args.dict = params; - - proc = &conf->fops->proctable[GF_FOP_SYMLINK]; - if (proc->fn) - ret = proc->fn (frame, this, &args); + args.loc = loc; + args.umask = umask; + args.xdata = xdata; + ret = proc->fn(frame, this, &args); + } out: - if (ret) - STACK_UNWIND_STRICT (symlink, frame, -1, ENOTCONN, - NULL, NULL, NULL, NULL); + if (ret) + STACK_UNWIND_STRICT(symlink, frame, -1, ENOTCONN, NULL, NULL, NULL, + NULL, NULL); - return 0; + return 0; } - - -int32_t -client_rename (call_frame_t *frame, xlator_t *this, loc_t *oldloc, - loc_t *newloc) +static int32_t +client_rename(call_frame_t *frame, xlator_t *this, loc_t *oldloc, loc_t *newloc, + dict_t *xdata) { - int ret = -1; - clnt_conf_t *conf = NULL; - rpc_clnt_procedure_t *proc = NULL; - clnt_args_t args = {0,}; - - conf = this->private; - if (!conf->fops) - goto out; - + int ret = -1; + clnt_conf_t *conf = NULL; + rpc_clnt_procedure_t *proc = NULL; + clnt_args_t args = { + 0, + }; + + conf = this->private; + if (!conf || !conf->fops) + goto out; + + proc = &conf->fops->proctable[GF_FOP_RENAME]; + if (proc->fn) { args.oldloc = oldloc; args.newloc = newloc; - proc = &conf->fops->proctable[GF_FOP_RENAME]; - if (proc->fn) - ret = proc->fn (frame, this, &args); + args.xdata = xdata; + ret = proc->fn(frame, this, &args); + } out: - if (ret) - STACK_UNWIND_STRICT (rename, frame, -1, ENOTCONN, - NULL, NULL, NULL, NULL, NULL); + if (ret) + STACK_UNWIND_STRICT(rename, frame, -1, ENOTCONN, NULL, NULL, NULL, NULL, + NULL, NULL); - return 0; + return 0; } - - -int32_t -client_link (call_frame_t *frame, xlator_t *this, loc_t *oldloc, - loc_t *newloc) +static int32_t +client_link(call_frame_t *frame, xlator_t *this, loc_t *oldloc, loc_t *newloc, + dict_t *xdata) { - int ret = -1; - clnt_conf_t *conf = NULL; - rpc_clnt_procedure_t *proc = NULL; - clnt_args_t args = {0,}; - - conf = this->private; - if (!conf->fops) - goto out; - + int ret = -1; + clnt_conf_t *conf = NULL; + rpc_clnt_procedure_t *proc = NULL; + clnt_args_t args = { + 0, + }; + + conf = this->private; + if (!conf || !conf->fops) + goto out; + + proc = &conf->fops->proctable[GF_FOP_LINK]; + if (proc->fn) { args.oldloc = oldloc; args.newloc = newloc; - - proc = &conf->fops->proctable[GF_FOP_LINK]; - if (proc->fn) - ret = proc->fn (frame, this, &args); + args.xdata = xdata; + ret = proc->fn(frame, this, &args); + } out: - if (ret) - STACK_UNWIND_STRICT (link, frame, -1, ENOTCONN, - NULL, NULL, NULL, NULL); + if (ret) + STACK_UNWIND_STRICT(link, frame, -1, ENOTCONN, NULL, NULL, NULL, NULL, + NULL); - return 0; + return 0; } - - -int32_t -client_create (call_frame_t *frame, xlator_t *this, loc_t *loc, - int32_t flags, mode_t mode, fd_t *fd, dict_t *params) +static int32_t +client_create(call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags, + mode_t mode, mode_t umask, fd_t *fd, dict_t *xdata) { - int ret = -1; - clnt_conf_t *conf = NULL; - rpc_clnt_procedure_t *proc = NULL; - clnt_args_t args = {0,}; - - conf = this->private; - if (!conf->fops) - goto out; - + int ret = -1; + clnt_conf_t *conf = NULL; + rpc_clnt_procedure_t *proc = NULL; + clnt_args_t args = { + 0, + }; + + conf = this->private; + if (!conf || !conf->fops) + goto out; + + proc = &conf->fops->proctable[GF_FOP_CREATE]; + if (proc->fn) { args.loc = loc; - args.flags = flags; args.mode = mode; args.fd = fd; - args.dict = params; - - proc = &conf->fops->proctable[GF_FOP_CREATE]; - if (proc->fn) - ret = proc->fn (frame, this, &args); + args.umask = umask; + args.xdata = xdata; + args.flags = flags; + client_filter_o_direct(conf, &args.flags); + ret = proc->fn(frame, this, &args); + } out: - if (ret) - STACK_UNWIND_STRICT (create, frame, -1, ENOTCONN, - NULL, NULL, NULL, NULL, NULL); + if (ret) + STACK_UNWIND_STRICT(create, frame, -1, ENOTCONN, NULL, NULL, NULL, NULL, + NULL, NULL); - return 0; + return 0; } - - -int32_t -client_open (call_frame_t *frame, xlator_t *this, loc_t *loc, - int32_t flags, fd_t *fd, int32_t wbflags) +static int32_t +client_open(call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags, + fd_t *fd, dict_t *xdata) { - int ret = -1; - clnt_conf_t *conf = NULL; - rpc_clnt_procedure_t *proc = NULL; - clnt_args_t args = {0,}; - - conf = this->private; - if (!conf->fops) - goto out; - + int ret = -1; + clnt_conf_t *conf = NULL; + rpc_clnt_procedure_t *proc = NULL; + clnt_args_t args = { + 0, + }; + + conf = this->private; + if (!conf || !conf->fops) + goto out; + + proc = &conf->fops->proctable[GF_FOP_OPEN]; + if (proc->fn) { args.loc = loc; - args.flags = flags; args.fd = fd; - args.wbflags = wbflags; - - proc = &conf->fops->proctable[GF_FOP_OPEN]; - if (proc->fn) - ret = proc->fn (frame, this, &args); - + args.xdata = xdata; + args.flags = flags; + client_filter_o_direct(conf, &args.flags); + ret = proc->fn(frame, this, &args); + } out: - if (ret) - STACK_UNWIND_STRICT (open, frame, -1, ENOTCONN, NULL); + if (ret) + STACK_UNWIND_STRICT(open, frame, -1, ENOTCONN, NULL, NULL); - return 0; + return 0; } - - -int32_t -client_readv (call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size, - off_t offset) +static int32_t +client_readv(call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size, + off_t offset, uint32_t flags, dict_t *xdata) { - int ret = -1; - clnt_conf_t *conf = NULL; - rpc_clnt_procedure_t *proc = NULL; - clnt_args_t args = {0,}; - - conf = this->private; - if (!conf->fops) - goto out; - - args.fd = fd; - args.size = size; + int ret = -1; + clnt_conf_t *conf = NULL; + rpc_clnt_procedure_t *proc = NULL; + clnt_args_t args = { + 0, + }; + + conf = this->private; + if (!conf || !conf->fops) + goto out; + + proc = &conf->fops->proctable[GF_FOP_READ]; + if (proc->fn) { + args.fd = fd; + args.size = size; args.offset = offset; + args.flags = flags; + args.xdata = xdata; + client_filter_o_direct(conf, &args.flags); - proc = &conf->fops->proctable[GF_FOP_READ]; - if (proc->fn) - ret = proc->fn (frame, this, &args); - + ret = proc->fn(frame, this, &args); + } out: - if (ret) - STACK_UNWIND_STRICT (readv, frame, -1, ENOTCONN, - NULL, 0, NULL, NULL); + if (ret) + STACK_UNWIND_STRICT(readv, frame, -1, ENOTCONN, NULL, 0, NULL, NULL, + NULL); - return 0; + return 0; } - - - -int32_t -client_writev (call_frame_t *frame, xlator_t *this, fd_t *fd, - struct iovec *vector, int32_t count, off_t off, - struct iobref *iobref) +static int32_t +client_writev(call_frame_t *frame, xlator_t *this, fd_t *fd, + struct iovec *vector, int32_t count, off_t off, uint32_t flags, + struct iobref *iobref, dict_t *xdata) { - int ret = -1; - clnt_conf_t *conf = NULL; - rpc_clnt_procedure_t *proc = NULL; - clnt_args_t args = {0,}; - - conf = this->private; - if (!conf->fops) - goto out; - - args.fd = fd; + int ret = -1; + clnt_conf_t *conf = NULL; + rpc_clnt_procedure_t *proc = NULL; + clnt_args_t args = { + 0, + }; + + conf = this->private; + if (!conf || !conf->fops) + goto out; + + proc = &conf->fops->proctable[GF_FOP_WRITE]; + if (proc->fn) { + args.fd = fd; args.vector = vector; - args.count = count; + args.count = count; args.offset = off; + args.size = iov_length(vector, count); + args.flags = flags; args.iobref = iobref; - - proc = &conf->fops->proctable[GF_FOP_WRITE]; - if (proc->fn) - ret = proc->fn (frame, this, &args); + args.xdata = xdata; + client_filter_o_direct(conf, &args.flags); + ret = proc->fn(frame, this, &args); + } out: - if (ret) - STACK_UNWIND_STRICT (writev, frame, -1, ENOTCONN, NULL, NULL); + if (ret) + STACK_UNWIND_STRICT(writev, frame, -1, ENOTCONN, NULL, NULL, NULL); - return 0; + return 0; } - - -int32_t -client_flush (call_frame_t *frame, xlator_t *this, fd_t *fd) +static int32_t +client_flush(call_frame_t *frame, xlator_t *this, fd_t *fd, dict_t *xdata) { - int ret = -1; - clnt_conf_t *conf = NULL; - rpc_clnt_procedure_t *proc = NULL; - clnt_args_t args = {0,}; - - conf = this->private; - if (!conf->fops) - goto out; - + int ret = -1; + clnt_conf_t *conf = NULL; + rpc_clnt_procedure_t *proc = NULL; + clnt_args_t args = { + 0, + }; + + conf = this->private; + if (!conf || !conf->fops) + goto out; + + proc = &conf->fops->proctable[GF_FOP_FLUSH]; + if (proc->fn) { args.fd = fd; - - proc = &conf->fops->proctable[GF_FOP_FLUSH]; - if (proc->fn) - ret = proc->fn (frame, this, &args); + args.xdata = xdata; + ret = proc->fn(frame, this, &args); + } out: - if (ret) - STACK_UNWIND_STRICT (flush, frame, -1, ENOTCONN); + if (ret) + STACK_UNWIND_STRICT(flush, frame, -1, ENOTCONN, NULL); - return 0; + return 0; } - - -int32_t -client_fsync (call_frame_t *frame, xlator_t *this, fd_t *fd, - int32_t flags) +static int32_t +client_fsync(call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t flags, + dict_t *xdata) { - int ret = -1; - clnt_conf_t *conf = NULL; - rpc_clnt_procedure_t *proc = NULL; - clnt_args_t args = {0,}; - - conf = this->private; - if (!conf->fops) - goto out; - - args.fd = fd; + int ret = -1; + clnt_conf_t *conf = NULL; + rpc_clnt_procedure_t *proc = NULL; + clnt_args_t args = { + 0, + }; + + conf = this->private; + if (!conf || !conf->fops) + goto out; + + proc = &conf->fops->proctable[GF_FOP_FSYNC]; + if (proc->fn) { + args.fd = fd; args.flags = flags; - - proc = &conf->fops->proctable[GF_FOP_FSYNC]; - if (proc->fn) - ret = proc->fn (frame, this, &args); + args.xdata = xdata; + ret = proc->fn(frame, this, &args); + } out: - if (ret) - STACK_UNWIND_STRICT (fsync, frame, -1, ENOTCONN, NULL, NULL); + if (ret) + STACK_UNWIND_STRICT(fsync, frame, -1, ENOTCONN, NULL, NULL, NULL); - return 0; + return 0; } - - -int32_t -client_fstat (call_frame_t *frame, xlator_t *this, fd_t *fd) +static int32_t +client_fstat(call_frame_t *frame, xlator_t *this, fd_t *fd, dict_t *xdata) { - int ret = -1; - clnt_conf_t *conf = NULL; - rpc_clnt_procedure_t *proc = NULL; - clnt_args_t args = {0,}; - - conf = this->private; - if (!conf->fops) - goto out; - + int ret = -1; + clnt_conf_t *conf = NULL; + rpc_clnt_procedure_t *proc = NULL; + clnt_args_t args = { + 0, + }; + + conf = this->private; + if (!conf || !conf->fops) + goto out; + + proc = &conf->fops->proctable[GF_FOP_FSTAT]; + if (proc->fn) { args.fd = fd; - - proc = &conf->fops->proctable[GF_FOP_FSTAT]; - if (proc->fn) - ret = proc->fn (frame, this, &args); + args.xdata = xdata; + ret = proc->fn(frame, this, &args); + } out: - if (ret) - STACK_UNWIND_STRICT (fstat, frame, -1, ENOTCONN, NULL); + if (ret) + STACK_UNWIND_STRICT(fstat, frame, -1, ENOTCONN, NULL, NULL); - return 0; + return 0; } - - -int32_t -client_opendir (call_frame_t *frame, xlator_t *this, loc_t *loc, fd_t *fd) +static int32_t +client_opendir(call_frame_t *frame, xlator_t *this, loc_t *loc, fd_t *fd, + dict_t *xdata) { - int ret = -1; - clnt_conf_t *conf = NULL; - rpc_clnt_procedure_t *proc = NULL; - clnt_args_t args = {0,}; - - conf = this->private; - if (!conf->fops) - goto out; - + int ret = -1; + clnt_conf_t *conf = NULL; + rpc_clnt_procedure_t *proc = NULL; + clnt_args_t args = { + 0, + }; + + conf = this->private; + if (!conf || !conf->fops) + goto out; + + proc = &conf->fops->proctable[GF_FOP_OPENDIR]; + if (proc->fn) { args.loc = loc; - args.fd = fd; - - proc = &conf->fops->proctable[GF_FOP_OPENDIR]; - if (proc->fn) - ret = proc->fn (frame, this, &args); + args.fd = fd; + args.xdata = xdata; + ret = proc->fn(frame, this, &args); + } out: - if (ret) - STACK_UNWIND_STRICT (opendir, frame, -1, ENOTCONN, NULL); + if (ret) + STACK_UNWIND_STRICT(opendir, frame, -1, ENOTCONN, NULL, NULL); - return 0; + return 0; } - - int32_t -client_fsyncdir (call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t flags) +client_fsyncdir(call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t flags, + dict_t *xdata) { - int ret = -1; - clnt_conf_t *conf = NULL; - rpc_clnt_procedure_t *proc = NULL; - clnt_args_t args = {0,}; - - conf = this->private; - if (!conf->fops) - goto out; - - args.fd = fd; + int ret = -1; + clnt_conf_t *conf = NULL; + rpc_clnt_procedure_t *proc = NULL; + clnt_args_t args = { + 0, + }; + + conf = this->private; + if (!conf || !conf->fops) + goto out; + + proc = &conf->fops->proctable[GF_FOP_FSYNCDIR]; + if (proc->fn) { + args.fd = fd; args.flags = flags; - - proc = &conf->fops->proctable[GF_FOP_FSYNCDIR]; - if (proc->fn) - ret = proc->fn (frame, this, &args); + args.xdata = xdata; + ret = proc->fn(frame, this, &args); + } out: - if (ret) - STACK_UNWIND_STRICT (fsyncdir, frame, -1, ENOTCONN); + if (ret) + STACK_UNWIND_STRICT(fsyncdir, frame, -1, ENOTCONN, NULL); - return 0; + return 0; } - - -int32_t -client_statfs (call_frame_t *frame, xlator_t *this, loc_t *loc) +static int32_t +client_statfs(call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata) { - int ret = -1; - clnt_conf_t *conf = NULL; - rpc_clnt_procedure_t *proc = NULL; - clnt_args_t args = {0,}; - - conf = this->private; - if (!conf->fops) - goto out; - + int ret = -1; + clnt_conf_t *conf = NULL; + rpc_clnt_procedure_t *proc = NULL; + clnt_args_t args = { + 0, + }; + + conf = this->private; + if (!conf || !conf->fops) + goto out; + + proc = &conf->fops->proctable[GF_FOP_STATFS]; + if (proc->fn) { args.loc = loc; + args.xdata = xdata; + ret = proc->fn(frame, this, &args); + } +out: + if (ret) + STACK_UNWIND_STRICT(statfs, frame, -1, ENOTCONN, NULL, NULL); - proc = &conf->fops->proctable[GF_FOP_STATFS]; - if (proc->fn) - ret = proc->fn (frame, this, &args); + return 0; +} + +static int32_t +client_copy_file_range(call_frame_t *frame, xlator_t *this, fd_t *fd_in, + off_t off_in, fd_t *fd_out, off_t off_out, size_t len, + uint32_t flags, dict_t *xdata) +{ + int ret = -1; + clnt_conf_t *conf = NULL; + rpc_clnt_procedure_t *proc = NULL; + clnt_args_t args = { + 0, + }; + + conf = this->private; + if (!conf || !conf->fops) + goto out; + + proc = &conf->fops->proctable[GF_FOP_COPY_FILE_RANGE]; + if (proc->fn) { + args.fd = fd_in; + args.fd_out = fd_out; + args.offset = off_in; + args.off_out = off_out; + args.size = len; + args.flags = flags; + args.xdata = xdata; + ret = proc->fn(frame, this, &args); + } out: - if (ret) - STACK_UNWIND_STRICT (statfs, frame, -1, ENOTCONN, NULL); + if (ret) + STACK_UNWIND_STRICT(copy_file_range, frame, -1, ENOTCONN, NULL, NULL, + NULL, NULL); - return 0; + return 0; } static gf_boolean_t -is_client_rpc_init_command (dict_t *dict, xlator_t *this, - char **value) +is_client_rpc_init_command(dict_t *dict, xlator_t *this, char **value) { - gf_boolean_t ret = _gf_false; - int dict_ret = -1; + gf_boolean_t ret = _gf_false; - if (!strstr (this->name, "replace-brick")) - goto out; - - dict_ret = dict_get_str (dict, CLIENT_CMD_CONNECT, value); - if (dict_ret) - goto out; + int dict_ret = dict_get_str_sizen(dict, CLIENT_CMD_CONNECT, value); + if (dict_ret) { + gf_msg_trace(this->name, 0, "key %s not present", CLIENT_CMD_CONNECT); + goto out; + } - ret = _gf_true; + ret = _gf_true; out: - return ret; - + return ret; } static gf_boolean_t -is_client_rpc_destroy_command (dict_t *dict, xlator_t *this) +is_client_rpc_destroy_command(dict_t *dict, xlator_t *this) { - gf_boolean_t ret = _gf_false; - int dict_ret = -1; - char *dummy = NULL; + gf_boolean_t ret = _gf_false; + int dict_ret = -1; + char *dummy = NULL; - if (strncmp (this->name, "replace-brick", 13)) - goto out; + if (strncmp(this->name, "replace-brick", 13)) { + gf_msg_trace(this->name, 0, "name is !replace-brick"); + goto out; + } - dict_ret = dict_get_str (dict, CLIENT_CMD_DISCONNECT, &dummy); - if (dict_ret) - goto out; + dict_ret = dict_get_str_sizen(dict, CLIENT_CMD_DISCONNECT, &dummy); + if (dict_ret) { + gf_msg_trace(this->name, 0, "key %s not present", + CLIENT_CMD_DISCONNECT); + goto out; + } - ret = _gf_true; + ret = _gf_true; out: - return ret; - + return ret; } -static gf_boolean_t -client_set_remote_options (char *value, xlator_t *this) -{ - clnt_conf_t *conf = NULL; - char *dup_value = NULL; - char *host = NULL; - char *subvol = NULL; - char *host_dup = NULL; - char *subvol_dup = NULL; - char *tmp = NULL; - gf_boolean_t ret = _gf_false; - - conf = this->private; - - dup_value = gf_strdup (value); - host = strtok_r (dup_value, ":", &tmp); - subvol = strtok_r (NULL, ":", &tmp); - if (!subvol) { - gf_log (this->name, GF_LOG_WARNING, - "proper value not passed as subvolume"); - goto out; - } - - host_dup = gf_strdup (host); +static int +client_set_remote_options(char *value, xlator_t *this) +{ + char *dup_value = NULL; + char *host = NULL; + char *subvol = NULL; + char *host_dup = NULL; + char *subvol_dup = NULL; + char *remote_port_str = NULL; + char *tmp = NULL; + int remote_port = 0; + int ret = -1; + + dup_value = gf_strdup(value); + if (dup_value == NULL) { + goto out; + } + host = strtok_r(dup_value, ":", &tmp); + subvol = strtok_r(NULL, ":", &tmp); + remote_port_str = strtok_r(NULL, ":", &tmp); + + if (host) { + host_dup = gf_strdup(host); if (!host_dup) { - gf_log (this->name, GF_LOG_ERROR, - "Out of memory"); - goto out; + goto out; } - - ret = dict_set_dynstr (this->options, "remote-host", host_dup); + ret = dict_set_dynstr_sizen(this->options, "remote-host", host_dup); if (ret) { - gf_log (this->name, GF_LOG_WARNING, - "failed to set remote-host with %s", host); - goto out; + gf_smsg(this->name, GF_LOG_WARNING, 0, + PC_MSG_REMOTE_HOST_SET_FAILED, "host=%s", host, NULL); + GF_FREE(host_dup); + goto out; } + } - subvol_dup = gf_strdup (subvol); + if (subvol) { + subvol_dup = gf_strdup(subvol); if (!subvol_dup) { - gf_log (this->name, GF_LOG_ERROR, - "Out of memory"); - goto out; + goto out; } - ret = dict_set_dynstr (this->options, "remote-subvolume", subvol_dup); + ret = dict_set_dynstr_sizen(this->options, "remote-subvolume", + subvol_dup); if (ret) { - gf_log (this->name, GF_LOG_WARNING, - "failed to set remote-host with %s", host); - goto out; + gf_smsg(this->name, GF_LOG_WARNING, 0, + PC_MSG_REMOTE_HOST_SET_FAILED, "host=%s", host, NULL); + GF_FREE(subvol_dup); + goto out; } + } - ret = _gf_true; -out: - if (dup_value) - GF_FREE (dup_value); - - return ret; -} + if (remote_port_str) { + remote_port = atoi(remote_port_str); + ret = dict_set_int32_sizen(this->options, "remote-port", remote_port); + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, 0, PC_MSG_REMOTE_PORT_SET_FAILED, + "remote-port=%d", remote_port, NULL); + goto out; + } + } -int32_t -client_setxattr (call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *dict, - int32_t flags) -{ - int ret = -1; - int op_ret = -1; - int op_errno = ENOTCONN; - int need_unwind = 0; - clnt_conf_t *conf = NULL; - rpc_clnt_procedure_t *proc = NULL; - clnt_args_t args = {0,}; - char *value = NULL; - - - if (is_client_rpc_init_command (dict, this, &value) == _gf_true) { - GF_ASSERT (value); - ret = client_set_remote_options (value, this); - if (ret) - ret = client_init_rpc (this); + ret = 0; +out: + GF_FREE(dup_value); - if (!ret) { - op_ret = 0; - op_errno = 0; - } - need_unwind = 1; - goto out; - } + return ret; +} - if (is_client_rpc_destroy_command (dict, this) == _gf_true) { - ret = client_destroy_rpc (this); - if (ret) { - op_ret = 0; - op_errno = 0; - } - need_unwind = 1; - goto out; +static int32_t +client_setxattr(call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *dict, + int32_t flags, dict_t *xdata) +{ + int ret = -1; + int op_ret = -1; + int op_errno = ENOTCONN; + int need_unwind = 0; + clnt_conf_t *conf = NULL; + rpc_clnt_procedure_t *proc = NULL; + clnt_args_t args = { + 0, + }; + char *value = NULL; + + if (is_client_rpc_init_command(dict, this, &value) == _gf_true) { + GF_ASSERT(value); + gf_smsg(this->name, GF_LOG_INFO, 0, PC_MSG_RPC_INIT, NULL); + ret = client_set_remote_options(value, this); + if (!ret) { + op_ret = 0; + op_errno = 0; } + need_unwind = 1; + goto out; + } - conf = this->private; - if (!conf->fops) { - op_errno = ENOTCONN; - need_unwind = 1; - goto out; + if (is_client_rpc_destroy_command(dict, this) == _gf_true) { + gf_smsg(this->name, GF_LOG_INFO, 0, PC_MSG_RPC_DESTROY, NULL); + ret = client_destroy_rpc(this); + if (ret) { + op_ret = 0; + op_errno = 0; } - - args.loc = loc; - args.dict = dict; + need_unwind = 1; + goto out; + } + + conf = this->private; + if (!conf || !conf->fops) { + op_errno = ENOTCONN; + need_unwind = 1; + goto out; + } + + proc = &conf->fops->proctable[GF_FOP_SETXATTR]; + if (proc->fn) { + args.loc = loc; + args.xattr = dict; args.flags = flags; - - proc = &conf->fops->proctable[GF_FOP_SETXATTR]; - if (proc->fn) { - ret = proc->fn (frame, this, &args); - if (ret) { - op_ret = -1; - op_errno = ENOTCONN; - need_unwind = 1; - } + args.xdata = xdata; + ret = proc->fn(frame, this, &args); + if (ret) { + need_unwind = 1; } + } out: - if (need_unwind) - STACK_UNWIND_STRICT (setxattr, frame, op_ret, op_errno); + if (need_unwind) + STACK_UNWIND_STRICT(setxattr, frame, op_ret, op_errno, NULL); - return 0; + return 0; } - - -int32_t -client_fsetxattr (call_frame_t *frame, xlator_t *this, fd_t *fd, - dict_t *dict, int32_t flags) +static int32_t +client_fsetxattr(call_frame_t *frame, xlator_t *this, fd_t *fd, dict_t *dict, + int32_t flags, dict_t *xdata) { - int ret = -1; - clnt_conf_t *conf = NULL; - rpc_clnt_procedure_t *proc = NULL; - clnt_args_t args = {0,}; - - conf = this->private; - if (!conf->fops) - goto out; - + int ret = -1; + clnt_conf_t *conf = NULL; + rpc_clnt_procedure_t *proc = NULL; + clnt_args_t args = { + 0, + }; + + conf = this->private; + if (!conf || !conf->fops) + goto out; + + proc = &conf->fops->proctable[GF_FOP_FSETXATTR]; + if (proc->fn) { args.fd = fd; - args.dict = dict; + args.xattr = dict; args.flags = flags; - - proc = &conf->fops->proctable[GF_FOP_FSETXATTR]; - if (proc->fn) - ret = proc->fn (frame, this, &args); + args.xdata = xdata; + ret = proc->fn(frame, this, &args); + } out: - if (ret) - STACK_UNWIND_STRICT (fsetxattr, frame, -1, ENOTCONN); + if (ret) + STACK_UNWIND_STRICT(fsetxattr, frame, -1, ENOTCONN, NULL); - return 0; + return 0; } - - - -int32_t -client_fgetxattr (call_frame_t *frame, xlator_t *this, fd_t *fd, - const char *name) +static int32_t +client_fgetxattr(call_frame_t *frame, xlator_t *this, fd_t *fd, + const char *name, dict_t *xdata) { - int ret = -1; - clnt_conf_t *conf = NULL; - rpc_clnt_procedure_t *proc = NULL; - clnt_args_t args = {0,}; - - conf = this->private; - if (!conf->fops) - goto out; - + int ret = -1; + clnt_conf_t *conf = NULL; + rpc_clnt_procedure_t *proc = NULL; + clnt_args_t args = { + 0, + }; + + conf = this->private; + if (!conf || !conf->fops) + goto out; + + proc = &conf->fops->proctable[GF_FOP_FGETXATTR]; + if (proc->fn) { args.fd = fd; args.name = name; - - proc = &conf->fops->proctable[GF_FOP_FGETXATTR]; - if (proc->fn) - ret = proc->fn (frame, this, &args); + args.xdata = xdata; + ret = proc->fn(frame, this, &args); + } out: - if (ret) - STACK_UNWIND_STRICT (fgetxattr, frame, -1, ENOTCONN, NULL); + if (ret) + STACK_UNWIND_STRICT(fgetxattr, frame, -1, ENOTCONN, NULL, NULL); - return 0; + return 0; } - - -int32_t -client_getxattr (call_frame_t *frame, xlator_t *this, loc_t *loc, - const char *name) +static int32_t +client_getxattr(call_frame_t *frame, xlator_t *this, loc_t *loc, + const char *name, dict_t *xdata) { - int ret = -1; - clnt_conf_t *conf = NULL; - rpc_clnt_procedure_t *proc = NULL; - clnt_args_t args = {0,}; - - conf = this->private; - if (!conf->fops) - goto out; - + int ret = -1; + clnt_conf_t *conf = NULL; + rpc_clnt_procedure_t *proc = NULL; + clnt_args_t args = { + 0, + }; + + conf = this->private; + if (!conf || !conf->fops) + goto out; + + proc = &conf->fops->proctable[GF_FOP_GETXATTR]; + if (proc->fn) { args.name = name; - args.loc = loc; - - proc = &conf->fops->proctable[GF_FOP_GETXATTR]; - if (proc->fn) - ret = proc->fn (frame, this, &args); + args.loc = loc; + args.xdata = xdata; + ret = proc->fn(frame, this, &args); + } out: - if (ret) - STACK_UNWIND_STRICT (getxattr, frame, -1, ENOTCONN, NULL); + if (ret) + STACK_UNWIND_STRICT(getxattr, frame, -1, ENOTCONN, NULL, NULL); - return 0; + return 0; } - - -int32_t -client_xattrop (call_frame_t *frame, xlator_t *this, loc_t *loc, - gf_xattrop_flags_t flags, dict_t *dict) +static int32_t +client_xattrop(call_frame_t *frame, xlator_t *this, loc_t *loc, + gf_xattrop_flags_t flags, dict_t *dict, dict_t *xdata) { - int ret = -1; - clnt_conf_t *conf = NULL; - rpc_clnt_procedure_t *proc = NULL; - clnt_args_t args = {0,}; - - conf = this->private; - if (!conf->fops) - goto out; - + int ret = -1; + clnt_conf_t *conf = NULL; + rpc_clnt_procedure_t *proc = NULL; + clnt_args_t args = { + 0, + }; + + conf = this->private; + if (!conf || !conf->fops) + goto out; + + proc = &conf->fops->proctable[GF_FOP_XATTROP]; + if (proc->fn) { args.loc = loc; args.flags = flags; - args.dict = dict; - - proc = &conf->fops->proctable[GF_FOP_XATTROP]; - if (proc->fn) - ret = proc->fn (frame, this, &args); + args.xattr = dict; + args.xdata = xdata; + ret = proc->fn(frame, this, &args); + } out: - if (ret) - STACK_UNWIND_STRICT (xattrop, frame, -1, ENOTCONN, NULL); + if (ret) + STACK_UNWIND_STRICT(xattrop, frame, -1, ENOTCONN, NULL, NULL); - return 0; + return 0; } - - -int32_t -client_fxattrop (call_frame_t *frame, xlator_t *this, fd_t *fd, - gf_xattrop_flags_t flags, dict_t *dict) +static int32_t +client_fxattrop(call_frame_t *frame, xlator_t *this, fd_t *fd, + gf_xattrop_flags_t flags, dict_t *dict, dict_t *xdata) { - int ret = -1; - clnt_conf_t *conf = NULL; - rpc_clnt_procedure_t *proc = NULL; - clnt_args_t args = {0,}; - - conf = this->private; - if (!conf->fops) - goto out; - + int ret = -1; + clnt_conf_t *conf = NULL; + rpc_clnt_procedure_t *proc = NULL; + clnt_args_t args = { + 0, + }; + + conf = this->private; + if (!conf || !conf->fops) + goto out; + + proc = &conf->fops->proctable[GF_FOP_FXATTROP]; + if (proc->fn) { args.fd = fd; args.flags = flags; - args.dict = dict; - - proc = &conf->fops->proctable[GF_FOP_FXATTROP]; - if (proc->fn) - ret = proc->fn (frame, this, &args); + args.xattr = dict; + args.xdata = xdata; + ret = proc->fn(frame, this, &args); + } out: - if (ret) - STACK_UNWIND_STRICT (fxattrop, frame, -1, ENOTCONN, NULL); + if (ret) + STACK_UNWIND_STRICT(fxattrop, frame, -1, ENOTCONN, NULL, NULL); - return 0; + return 0; } - - -int32_t -client_removexattr (call_frame_t *frame, xlator_t *this, loc_t *loc, - const char *name) +static int32_t +client_removexattr(call_frame_t *frame, xlator_t *this, loc_t *loc, + const char *name, dict_t *xdata) { - int ret = -1; - clnt_conf_t *conf = NULL; - rpc_clnt_procedure_t *proc = NULL; - clnt_args_t args = {0,}; + int ret = -1; + clnt_conf_t *conf = NULL; + rpc_clnt_procedure_t *proc = NULL; + clnt_args_t args = { + 0, + }; + + conf = this->private; + if (!conf || !conf->fops) + goto out; + + proc = &conf->fops->proctable[GF_FOP_REMOVEXATTR]; + if (proc->fn) { + args.name = name; + args.loc = loc; + args.xdata = xdata; + ret = proc->fn(frame, this, &args); + } +out: + if (ret) + STACK_UNWIND_STRICT(removexattr, frame, -1, ENOTCONN, NULL); - conf = this->private; - if (!conf->fops) - goto out; + return 0; +} +static int32_t +client_fremovexattr(call_frame_t *frame, xlator_t *this, fd_t *fd, + const char *name, dict_t *xdata) +{ + int ret = -1; + clnt_conf_t *conf = NULL; + rpc_clnt_procedure_t *proc = NULL; + clnt_args_t args = { + 0, + }; + + conf = this->private; + if (!conf || !conf->fops) + goto out; + + proc = &conf->fops->proctable[GF_FOP_FREMOVEXATTR]; + if (proc->fn) { args.name = name; - args.loc = loc; - - proc = &conf->fops->proctable[GF_FOP_REMOVEXATTR]; - if (proc->fn) - ret = proc->fn (frame, this, &args); + args.fd = fd; + args.xdata = xdata; + ret = proc->fn(frame, this, &args); + } out: - if (ret) - STACK_UNWIND_STRICT (removexattr, frame, -1, ENOTCONN); + if (ret) + STACK_UNWIND_STRICT(fremovexattr, frame, -1, ENOTCONN, NULL); - return 0; + return 0; } - -int32_t -client_lk (call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t cmd, - struct flock *lock) +static int32_t +client_lease(call_frame_t *frame, xlator_t *this, loc_t *loc, + struct gf_lease *lease, dict_t *xdata) { - int ret = -1; - clnt_conf_t *conf = NULL; - rpc_clnt_procedure_t *proc = NULL; - clnt_args_t args = {0,}; + int ret = -1; + clnt_conf_t *conf = NULL; + rpc_clnt_procedure_t *proc = NULL; + clnt_args_t args = { + 0, + }; + + conf = this->private; + if (!conf || !conf->fops) + goto out; + + proc = &conf->fops->proctable[GF_FOP_LEASE]; + if (proc->fn) { + args.loc = loc; + args.lease = lease; + args.xdata = xdata; + ret = proc->fn(frame, this, &args); + } +out: + if (ret) + STACK_UNWIND_STRICT(lk, frame, -1, ENOTCONN, NULL, NULL); - conf = this->private; - if (!conf->fops) - goto out; + return 0; +} - args.fd = fd; - args.cmd = cmd; +static int32_t +client_lk(call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t cmd, + struct gf_flock *lock, dict_t *xdata) +{ + int ret = -1; + clnt_conf_t *conf = NULL; + rpc_clnt_procedure_t *proc = NULL; + clnt_args_t args = { + 0, + }; + + conf = this->private; + if (!conf || !conf->fops) + goto out; + + proc = &conf->fops->proctable[GF_FOP_LK]; + if (proc->fn) { + args.fd = fd; + args.cmd = cmd; args.flock = lock; - - proc = &conf->fops->proctable[GF_FOP_LK]; - if (proc->fn) - ret = proc->fn (frame, this, &args); + args.xdata = xdata; + ret = proc->fn(frame, this, &args); + } out: - if (ret) - STACK_UNWIND_STRICT (lk, frame, -1, ENOTCONN, NULL); + if (ret) + STACK_UNWIND_STRICT(lk, frame, -1, ENOTCONN, NULL, NULL); - return 0; + return 0; } - -int32_t -client_inodelk (call_frame_t *frame, xlator_t *this, const char *volume, - loc_t *loc, int32_t cmd, struct flock *lock) +static int32_t +client_inodelk(call_frame_t *frame, xlator_t *this, const char *volume, + loc_t *loc, int32_t cmd, struct gf_flock *lock, dict_t *xdata) { - int ret = -1; - clnt_conf_t *conf = NULL; - rpc_clnt_procedure_t *proc = NULL; - clnt_args_t args = {0,}; - - conf = this->private; - if (!conf->fops) - goto out; - - args.loc = loc; - args.cmd = cmd; - args.flock = lock; + int ret = -1; + clnt_conf_t *conf = NULL; + rpc_clnt_procedure_t *proc = NULL; + clnt_args_t args = { + 0, + }; + + conf = this->private; + if (!conf || !conf->fops) + goto out; + + proc = &conf->fops->proctable[GF_FOP_INODELK]; + if (proc->fn) { + args.loc = loc; + args.cmd = cmd; + args.flock = lock; args.volume = volume; - - proc = &conf->fops->proctable[GF_FOP_INODELK]; - if (proc->fn) - ret = proc->fn (frame, this, &args); + args.xdata = xdata; + ret = proc->fn(frame, this, &args); + } out: - if (ret) - STACK_UNWIND_STRICT (inodelk, frame, -1, ENOTCONN); + if (ret) + STACK_UNWIND_STRICT(inodelk, frame, -1, ENOTCONN, NULL); - return 0; + return 0; } +static int32_t +client_finodelk(call_frame_t *frame, xlator_t *this, const char *volume, + fd_t *fd, int32_t cmd, struct gf_flock *lock, dict_t *xdata) +{ + int ret = -1; + clnt_conf_t *conf = NULL; + rpc_clnt_procedure_t *proc = NULL; + clnt_args_t args = { + 0, + }; + + conf = this->private; + if (!conf || !conf->fops) + goto out; + + proc = &conf->fops->proctable[GF_FOP_FINODELK]; + if (proc->fn) { + args.fd = fd; + args.cmd = cmd; + args.flock = lock; + args.volume = volume; + args.xdata = xdata; + ret = proc->fn(frame, this, &args); + } +out: + if (ret) + STACK_UNWIND_STRICT(finodelk, frame, -1, ENOTCONN, NULL); + return 0; +} -int32_t -client_finodelk (call_frame_t *frame, xlator_t *this, const char *volume, - fd_t *fd, int32_t cmd, struct flock *lock) +static int32_t +client_entrylk(call_frame_t *frame, xlator_t *this, const char *volume, + loc_t *loc, const char *basename, entrylk_cmd cmd, + entrylk_type type, dict_t *xdata) { - int ret = -1; - clnt_conf_t *conf = NULL; - rpc_clnt_procedure_t *proc = NULL; - clnt_args_t args = {0,}; + int ret = -1; + clnt_conf_t *conf = NULL; + rpc_clnt_procedure_t *proc = NULL; + clnt_args_t args = { + 0, + }; + + conf = this->private; + if (!conf || !conf->fops) + goto out; + + proc = &conf->fops->proctable[GF_FOP_ENTRYLK]; + if (proc->fn) { + args.loc = loc; + args.basename = basename; + args.type = type; + args.volume = volume; + args.cmd_entrylk = cmd; + args.xdata = xdata; + ret = proc->fn(frame, this, &args); + } +out: + if (ret) + STACK_UNWIND_STRICT(entrylk, frame, -1, ENOTCONN, NULL); - conf = this->private; - if (!conf->fops) - goto out; + return 0; +} - args.fd = fd; - args.cmd = cmd; - args.flock = lock; +static int32_t +client_fentrylk(call_frame_t *frame, xlator_t *this, const char *volume, + fd_t *fd, const char *basename, entrylk_cmd cmd, + entrylk_type type, dict_t *xdata) +{ + int ret = -1; + clnt_conf_t *conf = NULL; + rpc_clnt_procedure_t *proc = NULL; + clnt_args_t args = { + 0, + }; + + conf = this->private; + if (!conf || !conf->fops) + goto out; + + proc = &conf->fops->proctable[GF_FOP_FENTRYLK]; + if (proc->fn) { + args.fd = fd; + args.basename = basename; + args.type = type; args.volume = volume; - - proc = &conf->fops->proctable[GF_FOP_FINODELK]; - if (proc->fn) - ret = proc->fn (frame, this, &args); + args.cmd_entrylk = cmd; + args.xdata = xdata; + ret = proc->fn(frame, this, &args); + } out: - if (ret) - STACK_UNWIND_STRICT (finodelk, frame, -1, ENOTCONN); + if (ret) + STACK_UNWIND_STRICT(fentrylk, frame, -1, ENOTCONN, NULL); - return 0; + return 0; } - -int32_t -client_entrylk (call_frame_t *frame, xlator_t *this, const char *volume, - loc_t *loc, const char *basename, entrylk_cmd cmd, - entrylk_type type) +static int32_t +client_rchecksum(call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset, + int32_t len, dict_t *xdata) { - int ret = -1; - clnt_conf_t *conf = NULL; - rpc_clnt_procedure_t *proc = NULL; - clnt_args_t args = {0,}; + int ret = -1; + clnt_conf_t *conf = NULL; + rpc_clnt_procedure_t *proc = NULL; + clnt_args_t args = { + 0, + }; + + conf = this->private; + if (!conf || !conf->fops) + goto out; + + proc = &conf->fops->proctable[GF_FOP_RCHECKSUM]; + if (proc->fn) { + args.fd = fd; + args.offset = offset; + args.len = len; + args.xdata = xdata; + ret = proc->fn(frame, this, &args); + } +out: + if (ret) + STACK_UNWIND_STRICT(rchecksum, frame, -1, ENOTCONN, 0, NULL, NULL); - conf = this->private; - if (!conf->fops) - goto out; + return 0; +} - args.loc = loc; - args.basename = basename; - args.type = type; - args.volume = volume; - args.cmd_entrylk = cmd; +int32_t +client_readdir(call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size, + off_t off, dict_t *xdata) +{ + int ret = -1; + clnt_conf_t *conf = NULL; + rpc_clnt_procedure_t *proc = NULL; + clnt_args_t args = { + 0, + }; + + conf = this->private; + if (!conf || !conf->fops) + goto out; + + proc = &conf->fops->proctable[GF_FOP_READDIR]; + if (proc->fn) { + if (off != 0) + off = gf_dirent_orig_offset(this, off); - proc = &conf->fops->proctable[GF_FOP_ENTRYLK]; - if (proc->fn) - ret = proc->fn (frame, this, &args); + args.fd = fd; + args.size = size; + args.offset = off; + args.xdata = xdata; + ret = proc->fn(frame, this, &args); + } out: - if (ret) - STACK_UNWIND_STRICT (entrylk, frame, -1, ENOTCONN); + if (ret) + STACK_UNWIND_STRICT(readdir, frame, -1, ENOTCONN, NULL, NULL); - return 0; + return 0; } - - -int32_t -client_fentrylk (call_frame_t *frame, xlator_t *this, const char *volume, - fd_t *fd, const char *basename, entrylk_cmd cmd, - entrylk_type type) +static int32_t +client_readdirp(call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size, + off_t off, dict_t *dict) { - int ret = -1; - clnt_conf_t *conf = NULL; - rpc_clnt_procedure_t *proc = NULL; - clnt_args_t args = {0,}; + int ret = -1; + clnt_conf_t *conf = NULL; + rpc_clnt_procedure_t *proc = NULL; + clnt_args_t args = { + 0, + }; + + conf = this->private; + if (!conf || !conf->fops) + goto out; + + proc = &conf->fops->proctable[GF_FOP_READDIRP]; + if (proc->fn) { + if (off != 0) + off = gf_dirent_orig_offset(this, off); - conf = this->private; - if (!conf->fops) - goto out; + args.fd = fd; + args.size = size; + args.offset = off; + args.xdata = dict; + ret = proc->fn(frame, this, &args); + } +out: + if (ret) + STACK_UNWIND_STRICT(readdirp, frame, -1, ENOTCONN, NULL, NULL); - args.fd = fd; - args.basename = basename; - args.type = type; - args.volume = volume; - args.cmd_entrylk = cmd; + return 0; +} - proc = &conf->fops->proctable[GF_FOP_FENTRYLK]; - if (proc->fn) - ret = proc->fn (frame, this, &args); +static int32_t +client_setattr(call_frame_t *frame, xlator_t *this, loc_t *loc, + struct iatt *stbuf, int32_t valid, dict_t *xdata) +{ + int ret = -1; + clnt_conf_t *conf = NULL; + rpc_clnt_procedure_t *proc = NULL; + clnt_args_t args = { + 0, + }; + + conf = this->private; + if (!conf || !conf->fops) + goto out; + + proc = &conf->fops->proctable[GF_FOP_SETATTR]; + if (proc->fn) { + args.loc = loc; + args.stbuf = stbuf; + args.valid = valid; + args.xdata = xdata; + ret = proc->fn(frame, this, &args); + } out: - if (ret) - STACK_UNWIND_STRICT (fentrylk, frame, -1, ENOTCONN); + if (ret) + STACK_UNWIND_STRICT(setattr, frame, -1, ENOTCONN, NULL, NULL, NULL); - return 0; + return 0; } - -int32_t -client_rchecksum (call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset, - int32_t len) +static int32_t +client_fsetattr(call_frame_t *frame, xlator_t *this, fd_t *fd, + struct iatt *stbuf, int32_t valid, dict_t *xdata) { - int ret = -1; - clnt_conf_t *conf = NULL; - rpc_clnt_procedure_t *proc = NULL; - clnt_args_t args = {0,}; + int ret = -1; + clnt_conf_t *conf = NULL; + rpc_clnt_procedure_t *proc = NULL; + clnt_args_t args = { + 0, + }; + + conf = this->private; + if (!conf || !conf->fops) + goto out; + + proc = &conf->fops->proctable[GF_FOP_FSETATTR]; + if (proc->fn) { + args.fd = fd; + args.stbuf = stbuf; + args.valid = valid; + args.xdata = xdata; + ret = proc->fn(frame, this, &args); + } +out: + if (ret) + STACK_UNWIND_STRICT(fsetattr, frame, -1, ENOTCONN, NULL, NULL, NULL); - conf = this->private; - if (!conf->fops) - goto out; + return 0; +} +static int32_t +client_fallocate(call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t mode, + off_t offset, size_t len, dict_t *xdata) +{ + int ret = -1; + clnt_conf_t *conf = NULL; + rpc_clnt_procedure_t *proc = NULL; + clnt_args_t args = { + 0, + }; + + conf = this->private; + if (!conf || !conf->fops) + goto out; + + proc = &conf->fops->proctable[GF_FOP_FALLOCATE]; + if (proc->fn) { args.fd = fd; + args.flags = mode; args.offset = offset; - args.len = len; - - proc = &conf->fops->proctable[GF_FOP_RCHECKSUM]; - if (proc->fn) - ret = proc->fn (frame, this, &args); + args.size = len; + args.xdata = xdata; + ret = proc->fn(frame, this, &args); + } out: - if (ret) - STACK_UNWIND_STRICT (rchecksum, frame, -1, ENOTCONN, 0, NULL); + if (ret) + STACK_UNWIND_STRICT(fallocate, frame, -1, ENOTCONN, NULL, NULL, NULL); - return 0; + return 0; } -int32_t -client_readdir (call_frame_t *frame, xlator_t *this, fd_t *fd, - size_t size, off_t off) +static int32_t +client_discard(call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset, + size_t len, dict_t *xdata) { - int ret = -1; - clnt_conf_t *conf = NULL; - rpc_clnt_procedure_t *proc = NULL; - clnt_args_t args = {0,}; + int ret = -1; + clnt_conf_t *conf = NULL; + rpc_clnt_procedure_t *proc = NULL; + clnt_args_t args = { + 0, + }; + + conf = this->private; + if (!conf || !conf->fops) + goto out; + + proc = &conf->fops->proctable[GF_FOP_DISCARD]; + if (proc->fn) { + args.fd = fd; + args.offset = offset; + args.size = len; + args.xdata = xdata; + ret = proc->fn(frame, this, &args); + } +out: + if (ret) + STACK_UNWIND_STRICT(discard, frame, -1, ENOTCONN, NULL, NULL, NULL); - conf = this->private; - if (!conf->fops) - goto out; + return 0; +} +static int32_t +client_zerofill(call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset, + off_t len, dict_t *xdata) +{ + int ret = -1; + clnt_conf_t *conf = NULL; + rpc_clnt_procedure_t *proc = NULL; + clnt_args_t args = { + 0, + }; + + conf = this->private; + if (!conf || !conf->fops) + goto out; + + proc = &conf->fops->proctable[GF_FOP_ZEROFILL]; + if (proc->fn) { args.fd = fd; - args.size = size; - args.offset = off; - - proc = &conf->fops->proctable[GF_FOP_READDIR]; - if (proc->fn) - ret = proc->fn (frame, this, &args); + args.offset = offset; + args.size = len; + args.xdata = xdata; + ret = proc->fn(frame, this, &args); + } out: - if (ret) - STACK_UNWIND_STRICT (readdir, frame, -1, ENOTCONN, NULL); + if (ret) + STACK_UNWIND_STRICT(zerofill, frame, -1, ENOTCONN, NULL, NULL, NULL); - return 0; + return 0; } - -int32_t -client_readdirp (call_frame_t *frame, xlator_t *this, fd_t *fd, - size_t size, off_t off) +static int32_t +client_ipc(call_frame_t *frame, xlator_t *this, int32_t op, dict_t *xdata) { - int ret = -1; - clnt_conf_t *conf = NULL; - rpc_clnt_procedure_t *proc = NULL; - clnt_args_t args = {0,}; + int ret = -1; + clnt_conf_t *conf = NULL; + rpc_clnt_procedure_t *proc = NULL; + clnt_args_t args = { + 0, + }; + + conf = this->private; + if (!conf || !conf->fops) + goto out; + + proc = &conf->fops->proctable[GF_FOP_IPC]; + if (proc->fn) { + args.cmd = op; + args.xdata = xdata; + ret = proc->fn(frame, this, &args); + } +out: + if (ret) + STACK_UNWIND_STRICT(ipc, frame, -1, ENOTCONN, NULL); - conf = this->private; - if (!conf->fops) - goto out; + return 0; +} +static int32_t +client_seek(call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset, + gf_seek_what_t what, dict_t *xdata) +{ + int ret = -1; + clnt_conf_t *conf = NULL; + rpc_clnt_procedure_t *proc = NULL; + clnt_args_t args = { + 0, + }; + + conf = this->private; + if (!conf || !conf->fops) + goto out; + + proc = &conf->fops->proctable[GF_FOP_SEEK]; + if (proc->fn) { args.fd = fd; - args.size = size; - args.offset = off; - - proc = &conf->fops->proctable[GF_FOP_READDIRP]; - if (proc->fn) - ret = proc->fn (frame, this, &args); + args.offset = offset; + args.what = what; + args.xdata = xdata; + ret = proc->fn(frame, this, &args); + } out: - if (ret) - STACK_UNWIND_STRICT (readdirp, frame, -1, ENOTCONN, NULL); + if (ret) + STACK_UNWIND_STRICT(seek, frame, -1, ENOTCONN, 0, NULL); - return 0; + return 0; } - -int32_t -client_setattr (call_frame_t *frame, xlator_t *this, loc_t *loc, - struct iatt *stbuf, int32_t valid) +static int32_t +client_getactivelk(call_frame_t *frame, xlator_t *this, loc_t *loc, + dict_t *xdata) { - int ret = -1; - clnt_conf_t *conf = NULL; - rpc_clnt_procedure_t *proc = NULL; - clnt_args_t args = {0,}; + int ret = -1; + clnt_conf_t *conf = NULL; + rpc_clnt_procedure_t *proc = NULL; + clnt_args_t args = { + 0, + }; + + conf = this->private; + if (!conf || !conf->fops) + goto out; + + proc = &conf->fops->proctable[GF_FOP_GETACTIVELK]; + if (proc->fn) { + args.loc = loc; + args.xdata = xdata; + ret = proc->fn(frame, this, &args); + } +out: + if (ret) + STACK_UNWIND_STRICT(getactivelk, frame, -1, ENOTCONN, NULL, NULL); - conf = this->private; - if (!conf->fops) - goto out; + return 0; +} +static int32_t +client_setactivelk(call_frame_t *frame, xlator_t *this, loc_t *loc, + lock_migration_info_t *locklist, dict_t *xdata) +{ + int ret = -1; + clnt_conf_t *conf = NULL; + rpc_clnt_procedure_t *proc = NULL; + clnt_args_t args = { + 0, + }; + + conf = this->private; + if (!conf || !conf->fops) + goto out; + + proc = &conf->fops->proctable[GF_FOP_SETACTIVELK]; + if (proc->fn) { args.loc = loc; - args.stbuf = stbuf; - args.valid = valid; - - proc = &conf->fops->proctable[GF_FOP_SETATTR]; - if (proc->fn) - ret = proc->fn (frame, this, &args); + args.xdata = xdata; + args.locklist = locklist; + ret = proc->fn(frame, this, &args); + } out: - if (ret) - STACK_UNWIND_STRICT (setattr, frame, -1, ENOTCONN, NULL, NULL); + if (ret) + STACK_UNWIND_STRICT(setactivelk, frame, -1, ENOTCONN, NULL); - return 0; + return 0; } -int32_t -client_fsetattr (call_frame_t *frame, xlator_t *this, fd_t *fd, - struct iatt *stbuf, int32_t valid) +static int32_t +client_getspec(call_frame_t *frame, xlator_t *this, const char *key, + int32_t flags) { - int ret = -1; - clnt_conf_t *conf = NULL; - rpc_clnt_procedure_t *proc = NULL; - clnt_args_t args = {0,}; - - conf = this->private; - if (!conf->fops) - goto out; + int ret = -1; + clnt_conf_t *conf = NULL; + rpc_clnt_procedure_t *proc = NULL; + clnt_args_t args = { + 0, + }; + + conf = this->private; + if (!conf || !conf->fops || !conf->handshake) + goto out; + + /* For all other xlators, getspec is an fop, hence its in fops table */ + proc = &conf->fops->proctable[GF_FOP_GETSPEC]; + if (proc->fn) { + args.name = key; + args.flags = flags; + /* But at protocol level, this is handshake */ + ret = proc->fn(frame, this, &args); + } +out: + if (ret) + STACK_UNWIND_STRICT(getspec, frame, -1, EINVAL, NULL); - args.fd = fd; - args.stbuf = stbuf; - args.valid = valid; + return 0; +} - proc = &conf->fops->proctable[GF_FOP_FSETATTR]; - if (proc->fn) - ret = proc->fn (frame, this, &args); +static int32_t +client_compound(call_frame_t *frame, xlator_t *this, void *data, dict_t *xdata) +{ + int ret = -1; + clnt_conf_t *conf = NULL; + compound_args_t *args = data; + rpc_clnt_procedure_t *proc = NULL; + + conf = this->private; + if (!conf || !conf->fops) + goto out; + + proc = &conf->fops->proctable[GF_FOP_COMPOUND]; + if (proc->fn) { + args->xdata = xdata; + ret = proc->fn(frame, this, args); + } out: - if (ret) - STACK_UNWIND_STRICT (fsetattr, frame, -1, ENOTCONN, NULL, NULL); + if (ret) + STACK_UNWIND_STRICT(compound, frame, -1, ENOTCONN, NULL, NULL); - return 0; + return 0; } - int32_t -client_getspec (call_frame_t *frame, xlator_t *this, const char *key, - int32_t flags) +client_namelink(call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata) { - int ret = -1; - clnt_conf_t *conf = NULL; - rpc_clnt_procedure_t *proc = NULL; - clnt_args_t args = {0,}; + int32_t ret = -1; + clnt_conf_t *conf = NULL; + clnt_args_t args = { + 0, + }; + rpc_clnt_procedure_t *proc = NULL; + + conf = this->private; + if (!conf || !conf->fops || !conf->handshake) + goto out; + + proc = &conf->fops->proctable[GF_FOP_NAMELINK]; + if (proc->fn) { + args.loc = loc; + args.xdata = xdata; + ret = proc->fn(frame, this, &args); + } +out: + if (ret) + STACK_UNWIND_STRICT(namelink, frame, -1, EINVAL, NULL, NULL, NULL); + return 0; +} - conf = this->private; - if (!conf->fops || !conf->handshake) - goto out; +static int32_t +client_icreate(call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode, + dict_t *xdata) +{ + int32_t ret = -1; + clnt_conf_t *conf = NULL; + clnt_args_t args = { + 0, + }; + rpc_clnt_procedure_t *proc = NULL; + + conf = this->private; + if (!conf || !conf->fops || !conf->handshake) + goto out; + + proc = &conf->fops->proctable[GF_FOP_ICREATE]; + if (proc->fn) { + args.loc = loc; + args.mode = mode; + args.xdata = xdata; + ret = proc->fn(frame, this, &args); + } +out: + if (ret) + STACK_UNWIND_STRICT(icreate, frame, -1, EINVAL, NULL, NULL, NULL); + return 0; +} - args.name = key; +static int32_t +client_put(call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode, + mode_t umask, uint32_t flags, struct iovec *vector, int32_t count, + off_t off, struct iobref *iobref, dict_t *xattr, dict_t *xdata) +{ + int ret = -1; + clnt_conf_t *conf = NULL; + rpc_clnt_procedure_t *proc = NULL; + clnt_args_t args = { + 0, + }; + + conf = this->private; + if (!conf || !conf->fops) + goto out; + + proc = &conf->fops->proctable[GF_FOP_PUT]; + if (proc->fn) { + args.loc = loc; + args.mode = mode; + args.umask = umask; args.flags = flags; + args.vector = vector; + args.count = count; + args.offset = off; + args.size = iov_length(vector, count); + args.iobref = iobref; + args.xattr = xattr; + args.xdata = xdata; - /* For all other xlators, getspec is an fop, hence its in fops table */ - proc = &conf->fops->proctable[GF_FOP_GETSPEC]; - if (proc->fn) { - /* But at protocol level, this is handshake */ - ret = proc->fn (frame, this, &args); - } + client_filter_o_direct(conf, &args.flags); + ret = proc->fn(frame, this, &args); + } out: - if (ret) - STACK_UNWIND_STRICT (getspec, frame, -1, EINVAL, NULL); + if (ret) + STACK_UNWIND_STRICT(put, frame, -1, ENOTCONN, NULL, NULL, NULL, NULL, + NULL); - return 0; + return 0; } - - int -client_mark_fd_bad (xlator_t *this) +static void +client_mark_fd_bad(xlator_t *this) { - clnt_conf_t *conf = NULL; - clnt_fd_ctx_t *tmp = NULL, *fdctx = NULL; - - conf = this->private; + clnt_conf_t *conf = this->private; + clnt_fd_ctx_t *tmp = NULL, *fdctx = NULL; - pthread_mutex_lock (&conf->lock); + pthread_spin_lock(&conf->fd_lock); + { + list_for_each_entry_safe(fdctx, tmp, &conf->saved_fds, sfd_pos) { - list_for_each_entry_safe (fdctx, tmp, &conf->saved_fds, - sfd_pos) { - fdctx->remote_fd = -1; - } + fdctx->remote_fd = -1; } - pthread_mutex_unlock (&conf->lock); - - return 0; + } + pthread_spin_unlock(&conf->fd_lock); } - int -client_rpc_notify (struct rpc_clnt *rpc, void *mydata, rpc_clnt_event_t event, - void *data) +client_rpc_notify(struct rpc_clnt *rpc, void *mydata, rpc_clnt_event_t event, + void *data) { - xlator_t *this = NULL; - char *handshake = NULL; - clnt_conf_t *conf = NULL; - int ret = 0; + xlator_t *this = NULL; + clnt_conf_t *conf = NULL; + gf_boolean_t is_parent_down = _gf_false; + int ret = 0; + + this = mydata; + if (!this || !this->private) { + gf_smsg("client", GF_LOG_ERROR, EINVAL, PC_MSG_XLATOR_NULL, + (this != NULL) ? "private structue" : "", NULL); + goto out; + } + + conf = this->private; + + switch (event) { + case RPC_CLNT_PING: { + if (conf->connection_to_brick) { + ret = default_notify(this, GF_EVENT_CHILD_PING, data); + if (ret) + gf_log(this->name, GF_LOG_INFO, "CHILD_PING notify failed"); + conf->last_sent_event = GF_EVENT_CHILD_PING; + } + break; + } + case RPC_CLNT_CONNECT: { + conf->can_log_disconnect = 1; + // connect happened, send 'get_supported_versions' mop - this = mydata; - conf = this->private; + gf_msg_debug(this->name, 0, "got RPC_CLNT_CONNECT"); - switch (event) { - case RPC_CLNT_CONNECT: - { - // connect happened, send 'get_supported_versions' mop - ret = dict_get_str (this->options, "disable-handshake", - &handshake); - - gf_log (this->name, GF_LOG_TRACE, "got RPC_CLNT_CONNECT"); - - if ((ret < 0) || (strcasecmp (handshake, "on"))) { - ret = client_handshake (this, conf->rpc); - if (ret) - gf_log (this->name, GF_LOG_DEBUG, - "handshake msg returned %d", ret); - } else { - //conf->rpc->connected = 1; - ret = default_notify (this, GF_EVENT_CHILD_UP, NULL); - if (ret) - gf_log (this->name, GF_LOG_DEBUG, - "default notify failed"); - } - break; + ret = client_handshake(this, rpc); + if (ret) + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_HANDSHAKE_RETURN, + "ret=%d", ret, NULL); + break; } case RPC_CLNT_DISCONNECT: - - client_mark_fd_bad (this); - - gf_log (this->name, GF_LOG_TRACE, "got RPC_CLNT_DISCONNECT"); - - default_notify (this, GF_EVENT_CHILD_DOWN, NULL); - break; + gf_msg_debug(this->name, 0, "got RPC_CLNT_DISCONNECT"); + + client_mark_fd_bad(this); + + if (!conf->skip_notify) { + if (conf->can_log_disconnect) { + if (!conf->disconnect_err_logged) { + gf_smsg(this->name, GF_LOG_INFO, 0, + PC_MSG_CLIENT_DISCONNECTED, "conn-name=%s", + conf->rpc->conn.name, NULL); + } else { + gf_msg_debug(this->name, 0, + "disconnected from %s. " + "Client process will keep" + " trying to connect to " + "glusterd until brick's " + "port is available", + conf->rpc->conn.name); + } + if (conf->portmap_err_logged) + conf->disconnect_err_logged = 1; + } + /* + * Once we complete the child down notification, + * There is a chance that the graph might get freed, + * So it is not safe to access any xlator contens + * So here we are checking whether the parent is down + * or not. + */ + pthread_mutex_lock(&conf->lock); + { + is_parent_down = conf->parent_down; + } + pthread_mutex_unlock(&conf->lock); + + /* If the CHILD_DOWN event goes to parent xlator + multiple times, the logic of parent xlator notify + may get screwed up.. (eg. CHILD_MODIFIED event in + replicate), hence make sure events which are passed + to parent are genuine */ + ret = client_notify_dispatch_uniq(this, GF_EVENT_CHILD_DOWN, + rpc); + if (is_parent_down) { + /* If parent is down, then there should not be any + * operation after a child down. + */ + goto out; + } + if (ret) + gf_smsg(this->name, GF_LOG_INFO, 0, + PC_MSG_CHILD_DOWN_NOTIFY_FAILED, NULL); + + } else { + if (conf->can_log_disconnect) + gf_msg_debug(this->name, 0, + "disconnected (skipped notify)"); + } + + conf->connected = 0; + conf->can_log_disconnect = 0; + conf->skip_notify = 0; + + if (conf->quick_reconnect) { + conf->connection_to_brick = _gf_true; + conf->quick_reconnect = 0; + rpc_clnt_cleanup_and_start(rpc); + + } else { + rpc->conn.config.remote_port = 0; + conf->connection_to_brick = _gf_false; + } + break; + case RPC_CLNT_DESTROY: + ret = client_fini_complete(this); + break; default: - gf_log (this->name, GF_LOG_TRACE, - "got some other RPC event %d", event); + gf_msg_trace(this->name, 0, "got some other RPC event %d", event); - break; - } + break; + } - return 0; +out: + return 0; } - int -notify (xlator_t *this, int32_t event, void *data, ...) +notify(xlator_t *this, int32_t event, void *data, ...) { - clnt_conf_t *conf = NULL; - void *trans = NULL; + clnt_conf_t *conf = NULL; + glusterfs_graph_t *graph = this->graph; + int ret = -1; - conf = this->private; + conf = this->private; + if (!conf) + return 0; - switch (event) { - case GF_EVENT_PARENT_UP: - { - if (conf->rpc) - trans = conf->rpc->conn.trans; + switch (event) { + case GF_EVENT_PARENT_UP: { + gf_smsg(this->name, GF_LOG_INFO, 0, PC_MSG_PARENT_UP, NULL); - if (!trans) { - gf_log (this->name, GF_LOG_DEBUG, - "transport init failed"); - return 0; - } + rpc_clnt_start(conf->rpc); + break; + } - gf_log (this->name, GF_LOG_DEBUG, - "got GF_EVENT_PARENT_UP, attempting connect " - "on transport"); + case GF_EVENT_PARENT_DOWN: + gf_smsg(this->name, GF_LOG_INFO, 0, PC_MSG_PARENT_DOWN, NULL); - rpc_clnt_reconnect (trans); - } - break; + pthread_mutex_lock(&conf->lock); + { + conf->parent_down = 1; + } + pthread_mutex_unlock(&conf->lock); + + ret = rpc_clnt_disable(conf->rpc); + if (ret == -1 && graph) { + pthread_mutex_lock(&graph->mutex); + { + graph->parent_down++; + if (graph->parent_down == + graph_total_client_xlator(graph)) { + graph->used = 0; + pthread_cond_broadcast(&graph->child_down_cond); + } + } + pthread_mutex_unlock(&graph->mutex); + } + break; default: - gf_log (this->name, GF_LOG_DEBUG, - "got %d, calling default_notify ()", event); + gf_msg_debug(this->name, 0, "got %d, calling default_notify ()", + event); - default_notify (this, event, data); - break; - } + default_notify(this, event, data); + conf->last_sent_event = event; + break; + } - return 0; + return 0; } -int -build_client_config (xlator_t *this, clnt_conf_t *conf) -{ - int ret = 0; - - ret = dict_get_int32 (this->options, "frame-timeout", - &conf->rpc_conf.rpc_timeout); - if (ret >= 0) { - gf_log (this->name, GF_LOG_DEBUG, - "setting frame-timeout to %d", - conf->rpc_conf.rpc_timeout); - } else { - gf_log (this->name, GF_LOG_DEBUG, - "defaulting frame-timeout to 30mins"); - conf->rpc_conf.rpc_timeout = 1800; +static int +client_check_remote_host(xlator_t *this, dict_t *options) +{ + char *remote_host = NULL; + int ret = -1; + + ret = dict_get_str_sizen(options, "remote-host", &remote_host); + if (ret < 0) { + gf_smsg(this->name, GF_LOG_INFO, EINVAL, PC_MSG_REMOTE_HOST_NOT_SET, + NULL); + + if (!this->ctx->cmd_args.volfile_server) { + gf_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_NOREMOTE_HOST, + NULL); + goto out; } - ret = dict_get_int32 (this->options, "remote-port", - &conf->rpc_conf.remote_port); - if (ret >= 0) { - gf_log (this->name, GF_LOG_DEBUG, - "remote-port is %d", conf->rpc_conf.remote_port); - } else { - gf_log (this->name, GF_LOG_DEBUG, - "defaulting remote-port to 'auto'"); + ret = dict_set_str_sizen(options, "remote-host", + this->ctx->cmd_args.volfile_server); + if (ret == -1) { + gf_smsg(this->name, GF_LOG_ERROR, 0, PC_MSG_REMOTE_HOST_SET_FAILED, + NULL); + goto out; } + } - ret = dict_get_int32 (this->options, "ping-timeout", - &conf->opt.ping_timeout); - if (ret >= 0) { - gf_log (this->name, GF_LOG_DEBUG, - "setting ping-timeout to %d", conf->opt.ping_timeout); - } else { - gf_log (this->name, GF_LOG_DEBUG, - "defaulting ping-timeout to 42"); - conf->opt.ping_timeout = GF_UNIVERSAL_ANSWER; - } + ret = 0; +out: + return ret; +} - ret = dict_get_str (this->options, "remote-subvolume", - &conf->opt.remote_subvolume); - if (ret) { - /* This is valid only if 'cluster/pump' is the parent */ - gf_log (this->name, GF_LOG_NORMAL, - "option 'remote-subvolume' not given"); - ret = 1; - goto out; - } +static int +build_client_config(xlator_t *this, clnt_conf_t *conf) +{ + int ret = -1; - ret = 0; + GF_OPTION_INIT("frame-timeout", conf->rpc_conf.rpc_timeout, int32, out); + + GF_OPTION_INIT("remote-port", conf->rpc_conf.remote_port, int32, out); + + GF_OPTION_INIT("ping-timeout", conf->opt.ping_timeout, int32, out); + + GF_OPTION_INIT("remote-subvolume", conf->opt.remote_subvolume, path, out); + if (!conf->opt.remote_subvolume) + gf_smsg(this->name, GF_LOG_WARNING, EINVAL, + PC_MSG_REMOTE_SUBVOL_NOT_GIVEN, NULL); + + GF_OPTION_INIT("filter-O_DIRECT", conf->filter_o_direct, bool, out); + + GF_OPTION_INIT("send-gids", conf->send_gids, bool, out); + + GF_OPTION_INIT("testing.old-protocol", conf->old_protocol, bool, out); + GF_OPTION_INIT("strict-locks", conf->strict_locks, bool, out); + + conf->client_id = glusterfs_leaf_position(this); + + ret = client_check_remote_host(this, this->options); + if (ret) + goto out; + + ret = 0; out: - return ret; + return ret; } - int32_t -mem_acct_init (xlator_t *this) +mem_acct_init(xlator_t *this) { - int ret = -1; - - if (!this) - return ret; + int ret = -1; - ret = xlator_mem_acct_init (this, gf_client_mt_end + 1); + if (!this) + return ret; - if (ret != 0) { - gf_log (this->name, GF_LOG_ERROR, "Memory accounting init" - "failed"); - return ret; - } + ret = xlator_mem_acct_init(this, gf_client_mt_end + 1); + if (ret != 0) { + gf_smsg(this->name, GF_LOG_ERROR, ENOMEM, PC_MSG_NO_MEMORY, NULL); return ret; + } + + return ret; } -int -client_destroy_rpc (xlator_t *this) +static int +client_destroy_rpc(xlator_t *this) { - int ret = -1; - clnt_conf_t *conf = NULL; + int ret = -1; + clnt_conf_t *conf = NULL; - conf = this->private; + conf = this->private; + if (!conf) + goto out; - if (conf->rpc) { - rpc_clnt_destroy (conf->rpc); - ret = 0; - gf_log (this->name, GF_LOG_DEBUG, - "Client rpc conn destroyed"); - goto out; - } + if (conf->rpc) { + /* cleanup the saved-frames before last unref */ + rpc_clnt_connection_cleanup(&conf->rpc->conn); - gf_log (this->name, GF_LOG_DEBUG, - "RPC destory called on already destroyed " - "connection"); + conf->rpc = rpc_clnt_unref(conf->rpc); + ret = 0; + gf_msg_debug(this->name, 0, "Client rpc conn destroyed"); + goto out; + } + + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_RPC_INVALID_CALL, NULL); out: - return ret; + return ret; } -int -client_init_rpc (xlator_t *this) +static int +client_init_rpc(xlator_t *this) { - int ret = -1; - clnt_conf_t *conf = NULL; + int ret = -1; + clnt_conf_t *conf = NULL; - conf = this->private; + conf = this->private; - if (conf->rpc) { - gf_log (this->name, GF_LOG_DEBUG, - "client rpc already init'ed"); - ret = -1; - goto out; - } + if (conf->rpc) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PC_MSG_RPC_INITED_ALREADY, NULL); + ret = -1; + goto out; + } - conf->rpc = rpc_clnt_init (&conf->rpc_conf, this->options, this->ctx, - this->name); - if (!conf->rpc) - goto out; + conf->rpc = rpc_clnt_new(this->options, this, this->name, 0); + if (!conf->rpc) { + gf_smsg(this->name, GF_LOG_ERROR, 0, PC_MSG_RPC_INIT_FAILED, NULL); + goto out; + } - ret = rpc_clnt_register_notify (conf->rpc, client_rpc_notify, this); - if (ret) - goto out; + ret = rpc_clnt_register_notify(conf->rpc, client_rpc_notify, this); + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, 0, PC_MSG_RPC_NOTIFY_FAILED, NULL); + goto out; + } - conf->handshake = &clnt_handshake_prog; - conf->dump = &clnt_dump_prog; + conf->handshake = &clnt_handshake_prog; + conf->dump = &clnt_dump_prog; - ret = rpcclnt_cbk_program_register (conf->rpc, &gluster_cbk_prog); - if (ret) - goto out; + ret = rpcclnt_cbk_program_register(conf->rpc, &gluster_cbk_prog, this); + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, 0, PC_MSG_RPC_CBK_FAILED, NULL); + goto out; + } - ret = 0; + ret = 0; - gf_log (this->name, GF_LOG_DEBUG, "client init successful"); + gf_msg_debug(this->name, 0, "client init successful"); out: - return ret; + return ret; } -int -init (xlator_t *this) +static int +client_check_event_threads(xlator_t *this, clnt_conf_t *conf, int32_t old, + int32_t new) { - int ret = -1; - clnt_conf_t *conf = NULL; + if (old == new) + return 0; + + conf->event_threads = new; + return gf_event_reconfigure_threads(this->ctx->event_pool, + conf->event_threads); +} - /* */ - if (this->children) { - gf_log (this->name, GF_LOG_ERROR, - "FATAL: client protocol translator cannot have any " - "subvolumes"); +int +reconfigure(xlator_t *this, dict_t *options) +{ + clnt_conf_t *conf = NULL; + int ret = -1; + int subvol_ret = 0; + char *old_remote_subvol = NULL; + char *new_remote_subvol = NULL; + char *old_remote_host = NULL; + char *new_remote_host = NULL; + int32_t new_nthread = 0; + struct rpc_clnt_config rpc_config = { + 0, + }; + + conf = this->private; + + GF_OPTION_RECONF("frame-timeout", conf->rpc_conf.rpc_timeout, options, + int32, out); + + GF_OPTION_RECONF("ping-timeout", rpc_config.ping_timeout, options, int32, + out); + + GF_OPTION_RECONF("event-threads", new_nthread, options, int32, out); + ret = client_check_event_threads(this, conf, conf->event_threads, + new_nthread); + if (ret) + goto out; + + ret = client_check_remote_host(this, options); + if (ret) + goto out; + + subvol_ret = dict_get_str_sizen(this->options, "remote-host", + &old_remote_host); + + if (subvol_ret == 0) { + subvol_ret = dict_get_str_sizen(options, "remote-host", + &new_remote_host); + if (subvol_ret == 0) { + if (strcmp(old_remote_host, new_remote_host)) { + ret = 1; goto out; + } } + } - if (!this->parents) { - gf_log (this->name, GF_LOG_WARNING, - "Volume is dangling. "); - } + subvol_ret = dict_get_str_sizen(this->options, "remote-subvolume", + &old_remote_subvol); - conf = GF_CALLOC (1, sizeof (*conf), gf_client_mt_clnt_conf_t); - if (!conf) + if (subvol_ret == 0) { + subvol_ret = dict_get_str_sizen(options, "remote-subvolume", + &new_remote_subvol); + if (subvol_ret == 0) { + if (strcmp(old_remote_subvol, new_remote_subvol)) { + ret = 1; goto out; + } + } + } - pthread_mutex_init (&conf->lock, NULL); - INIT_LIST_HEAD (&conf->saved_fds); - - this->private = conf; - - /* If it returns -1, then its a failure, if it returns +1 we need - have to understand that 'this' is subvolume of a xlator which, - will set the remote host and remote subvolume in a setxattr - call. - */ + /* Reconfiguring client xlator's @rpc with new frame-timeout + * and ping-timeout */ + rpc_clnt_reconfig(conf->rpc, &rpc_config); - ret = build_client_config (this, conf); - if (ret == -1) - goto out; + GF_OPTION_RECONF("filter-O_DIRECT", conf->filter_o_direct, options, bool, + out); - if (ret) { - ret = 0; - goto out; - } + GF_OPTION_RECONF("send-gids", conf->send_gids, options, bool, out); + GF_OPTION_RECONF("strict-locks", conf->strict_locks, options, bool, out); - ret = client_init_rpc (this); + ret = 0; out: - if (ret) - this->fini (this); - - return ret; + return ret; } -void -fini (xlator_t *this) +int +init(xlator_t *this) { - clnt_conf_t *conf = NULL; + int ret = -1; + clnt_conf_t *conf = NULL; - conf = this->private; - this->private = NULL; + if (this->children) { + gf_smsg(this->name, GF_LOG_ERROR, EINVAL, PC_MSG_FATAL_CLIENT_PROTOCOL, + NULL); + goto out; + } - if (conf) { -// if (conf->rpc) -// rpc_clnt_destroy (conf->rpc); + if (!this->parents) { + gf_smsg(this->name, GF_LOG_WARNING, EINVAL, PC_MSG_VOL_DANGLING, NULL); + } - /* Saved Fds */ - /* TODO: */ + conf = GF_CALLOC(1, sizeof(*conf), gf_client_mt_clnt_conf_t); + if (!conf) + goto out; - pthread_mutex_destroy (&conf->lock); + pthread_mutex_init(&conf->lock, NULL); + pthread_cond_init(&conf->fini_complete_cond, NULL); + pthread_spin_init(&conf->fd_lock, 0); + INIT_LIST_HEAD(&conf->saved_fds); - GF_FREE (conf); - } - return; -} + conf->child_up = _gf_false; -int -client_priv_dump (xlator_t *this) -{ - clnt_conf_t *conf = NULL; - int ret = -1; - clnt_fd_ctx_t *tmp = NULL; - int i = 0; - char key[GF_DUMP_MAX_BUF_LEN]; - char key_prefix[GF_DUMP_MAX_BUF_LEN]; - - if (!this) - return -1; - - conf = this->private; - if (!conf) { - gf_log (this->name, GF_LOG_WARNING, - "conf null in xlator"); - return -1; - } + /* Set event threads to the configured default */ + GF_OPTION_INIT("event-threads", conf->event_threads, int32, out); + ret = client_check_event_threads(this, conf, STARTING_EVENT_THREADS, + conf->event_threads); + if (ret) + goto out; - ret = pthread_mutex_trylock(&conf->lock); - if (ret) { - gf_log("", GF_LOG_WARNING, "Unable to lock client %s" - " errno: %d", this->name, errno); - return -1; - } + LOCK_INIT(&conf->rec_lock); - gf_proc_dump_build_key(key_prefix, "xlator.protocol.client", - "%s.priv", this->name); + conf->last_sent_event = -1; /* To start with we don't have any events */ - gf_proc_dump_add_section(key_prefix); + this->private = conf; - list_for_each_entry(tmp, &conf->saved_fds, sfd_pos) { - gf_proc_dump_build_key(key, key_prefix, - "fd.%d.remote_fd", ++i); - gf_proc_dump_write(key, "%d", tmp->remote_fd); - } + /* If it returns -1, then its a failure, if it returns +1 we need + have to understand that 'this' is subvolume of a xlator which, + will set the remote host and remote subvolume in a setxattr + call. + */ - gf_proc_dump_build_key(key, key_prefix, "connecting"); - gf_proc_dump_write(key, "%d", conf->connecting); - gf_proc_dump_build_key(key, key_prefix, "last_sent"); - gf_proc_dump_write(key, "%s", ctime(&conf->last_sent.tv_sec)); - gf_proc_dump_build_key(key, key_prefix, "last_received"); - gf_proc_dump_write(key, "%s", ctime(&conf->last_received.tv_sec)); + ret = build_client_config(this, conf); + if (ret == -1) + goto out; - gf_proc_dump_build_key(key, key_prefix, "total_bytes_read"); - gf_proc_dump_write(key, "%"PRIu64, - conf->rpc->conn.trans->total_bytes_read); + if (ret) { + ret = 0; + goto out; + } + + this->local_pool = mem_pool_new(clnt_local_t, 64); + if (!this->local_pool) { + ret = -1; + gf_smsg(this->name, GF_LOG_ERROR, ENOMEM, PC_MSG_CREATE_MEM_POOL_FAILED, + NULL); + goto out; + } + + ret = client_init_rpc(this); +out: + if (ret) + this->fini(this); - gf_proc_dump_build_key(key, key_prefix, "total_bytes_written"); - gf_proc_dump_write(key, "%"PRIu64, - conf->rpc->conn.trans->total_bytes_write); + return ret; +} - pthread_mutex_unlock(&conf->lock); +void +fini(xlator_t *this) +{ + clnt_conf_t *conf = NULL; - return 0; + conf = this->private; + if (!conf) + return; + conf->fini_completed = _gf_false; + conf->destroy = 1; + if (conf->rpc) { + /* cleanup the saved-frames before last unref */ + rpc_clnt_connection_cleanup(&conf->rpc->conn); + rpc_clnt_unref(conf->rpc); + } + + pthread_mutex_lock(&conf->lock); + { + while (!conf->fini_completed) + pthread_cond_wait(&conf->fini_complete_cond, &conf->lock); + } + pthread_mutex_unlock(&conf->lock); + + pthread_spin_destroy(&conf->fd_lock); + pthread_mutex_destroy(&conf->lock); + pthread_cond_destroy(&conf->fini_complete_cond); + GF_FREE(conf); + + /* Saved Fds */ + /* TODO: */ + + return; } -int32_t -client_inodectx_dump (xlator_t *this, inode_t *inode) +static void +client_fd_lk_ctx_dump(xlator_t *this, fd_lk_ctx_t *lk_ctx, int nth_fd) { - ino_t par = 0; - uint64_t gen = 0; - int ret = -1; - char key[GF_DUMP_MAX_BUF_LEN]; + gf_boolean_t use_try_lock = _gf_true; + int ret = -1; + int lock_no = 0; + fd_lk_ctx_t *lk_ctx_ref = NULL; + fd_lk_ctx_node_t *plock = NULL; + char key[GF_DUMP_MAX_BUF_LEN] = { + 0, + }; + + lk_ctx_ref = fd_lk_ctx_ref(lk_ctx); + if (!lk_ctx_ref) + return; - if (!inode) - return -1; + ret = client_fd_lk_list_empty(lk_ctx_ref, (use_try_lock = _gf_true)); + if (ret != 0) + return; - if (!this) - return -1; + gf_proc_dump_write("------", "------"); - ret = inode_ctx_get2 (inode, this, &par, &gen); + lock_no = 0; - if (ret != 0) - return ret; + ret = TRY_LOCK(&lk_ctx_ref->lock); + if (ret) + return; - gf_proc_dump_build_key(key, "xlator.protocol.client", - "%s.inode.%ld.par", - this->name,inode->ino); - gf_proc_dump_write(key, "%ld, %ld", par, gen); + list_for_each_entry(plock, &lk_ctx_ref->lk_list, next) + { + snprintf(key, sizeof(key), "granted-posix-lock[%d]", lock_no++); + gf_proc_dump_write( + key, + "owner = %s, cmd = %s " + "fl_type = %s, fl_start = %" PRId64 ", fl_end = %" PRId64 + ", user_flock: l_type = %s, " + "l_start = %" PRId64 ", l_len = %" PRId64, + lkowner_utoa(&plock->user_flock.l_owner), get_lk_cmd(plock->cmd), + get_lk_type(plock->fl_type), plock->fl_start, plock->fl_end, + get_lk_type(plock->user_flock.l_type), plock->user_flock.l_start, + plock->user_flock.l_len); + } + UNLOCK(&lk_ctx_ref->lock); + + gf_proc_dump_write("------", "------"); + + fd_lk_ctx_unref(lk_ctx_ref); +} - return 0; +static int +client_priv_dump(xlator_t *this) +{ + clnt_conf_t *conf = NULL; + int ret = -1; + clnt_fd_ctx_t *tmp = NULL; + int i = 0; + char key[GF_DUMP_MAX_BUF_LEN]; + char key_prefix[GF_DUMP_MAX_BUF_LEN]; + rpc_clnt_connection_t *conn = NULL; + + if (!this) + return -1; + + conf = this->private; + if (!conf) + return -1; + + gf_proc_dump_build_key(key_prefix, "xlator.protocol.client", "%s.priv", + this->name); + + gf_proc_dump_add_section("%s", key_prefix); + + ret = pthread_mutex_trylock(&conf->lock); + if (ret) + return -1; + + pthread_spin_lock(&conf->fd_lock); + list_for_each_entry(tmp, &conf->saved_fds, sfd_pos) + { + sprintf(key, "fd.%d.remote_fd", i); + gf_proc_dump_write(key, "%" PRId64, tmp->remote_fd); + client_fd_lk_ctx_dump(this, tmp->lk_ctx, i); + i++; + } + pthread_spin_unlock(&conf->fd_lock); + + gf_proc_dump_write("connected", "%d", conf->connected); + + if (conf->rpc) { + conn = &conf->rpc->conn; + gf_proc_dump_write("total_bytes_read", "%" PRIu64, + conn->trans->total_bytes_read); + gf_proc_dump_write("ping_timeout", "%" PRIu32, conn->ping_timeout); + gf_proc_dump_write("total_bytes_written", "%" PRIu64, + conn->trans->total_bytes_write); + gf_proc_dump_write("ping_msgs_sent", "%" PRIu64, conn->pingcnt); + gf_proc_dump_write("msgs_sent", "%" PRIu64, conn->msgcnt); + } + pthread_mutex_unlock(&conf->lock); + + return 0; } +int32_t +client_inodectx_dump(xlator_t *this, inode_t *inode) +{ + if (!inode) + return -1; + if (!this) + return -1; + /*TODO*/ -struct xlator_cbks cbks = { - .forget = client_forget, - .release = client_release, - .releasedir = client_releasedir -}; + return 0; +} + +struct xlator_cbks cbks = {.forget = client_forget, + .release = client_release, + .releasedir = client_releasedir}; struct xlator_fops fops = { - .stat = client_stat, - .readlink = client_readlink, - .mknod = client_mknod, - .mkdir = client_mkdir, - .unlink = client_unlink, - .rmdir = client_rmdir, - .symlink = client_symlink, - .rename = client_rename, - .link = client_link, - .truncate = client_truncate, - .open = client_open, - .readv = client_readv, - .writev = client_writev, - .statfs = client_statfs, - .flush = client_flush, - .fsync = client_fsync, - .setxattr = client_setxattr, - .getxattr = client_getxattr, - .fsetxattr = client_fsetxattr, - .fgetxattr = client_fgetxattr, - .removexattr = client_removexattr, - .opendir = client_opendir, - .readdir = client_readdir, - .readdirp = client_readdirp, - .fsyncdir = client_fsyncdir, - .access = client_access, - .ftruncate = client_ftruncate, - .fstat = client_fstat, - .create = client_create, - .lk = client_lk, - .inodelk = client_inodelk, - .finodelk = client_finodelk, - .entrylk = client_entrylk, - .fentrylk = client_fentrylk, - .lookup = client_lookup, - .rchecksum = client_rchecksum, - .xattrop = client_xattrop, - .fxattrop = client_fxattrop, - .setattr = client_setattr, - .fsetattr = client_fsetattr, - .getspec = client_getspec, + .stat = client_stat, + .readlink = client_readlink, + .mknod = client_mknod, + .mkdir = client_mkdir, + .unlink = client_unlink, + .rmdir = client_rmdir, + .symlink = client_symlink, + .rename = client_rename, + .link = client_link, + .truncate = client_truncate, + .open = client_open, + .readv = client_readv, + .writev = client_writev, + .statfs = client_statfs, + .flush = client_flush, + .fsync = client_fsync, + .setxattr = client_setxattr, + .getxattr = client_getxattr, + .fsetxattr = client_fsetxattr, + .fgetxattr = client_fgetxattr, + .removexattr = client_removexattr, + .fremovexattr = client_fremovexattr, + .opendir = client_opendir, + .readdir = client_readdir, + .readdirp = client_readdirp, + .fsyncdir = client_fsyncdir, + .access = client_access, + .ftruncate = client_ftruncate, + .fstat = client_fstat, + .create = client_create, + .lk = client_lk, + .inodelk = client_inodelk, + .finodelk = client_finodelk, + .entrylk = client_entrylk, + .fentrylk = client_fentrylk, + .lookup = client_lookup, + .rchecksum = client_rchecksum, + .xattrop = client_xattrop, + .fxattrop = client_fxattrop, + .setattr = client_setattr, + .fsetattr = client_fsetattr, + .fallocate = client_fallocate, + .discard = client_discard, + .zerofill = client_zerofill, + .getspec = client_getspec, + .ipc = client_ipc, + .seek = client_seek, + .lease = client_lease, + .compound = client_compound, + .getactivelk = client_getactivelk, + .setactivelk = client_setactivelk, + .icreate = client_icreate, + .namelink = client_namelink, + .put = client_put, + .copy_file_range = client_copy_file_range, }; - struct xlator_dumpops dumpops = { - .priv = client_priv_dump, - .inodectx = client_inodectx_dump, + .priv = client_priv_dump, + .inodectx = client_inodectx_dump, }; - struct volume_options options[] = { - { .key = {"username"}, - .type = GF_OPTION_TYPE_ANY - }, - { .key = {"password"}, - .type = GF_OPTION_TYPE_ANY - }, - { .key = {"transport-type"}, - .value = {"tcp", "socket", "ib-verbs", "unix", "ib-sdp", - "tcp/client", "ib-verbs/client", "rdma"}, - .type = GF_OPTION_TYPE_STR - }, - { .key = {"remote-host"}, - .type = GF_OPTION_TYPE_INTERNET_ADDRESS - }, - { .key = {"remote-subvolume"}, - .type = GF_OPTION_TYPE_ANY - }, - { .key = {"frame-timeout", - "rpc-timeout" }, - .type = GF_OPTION_TYPE_TIME, - .min = 0, - .max = 86400, - }, - { .key = {"ping-timeout"}, - .type = GF_OPTION_TYPE_TIME, - .min = 1, - .max = 1013, - }, - { .key = {NULL} }, + {.key = {"username"}, .type = GF_OPTION_TYPE_ANY}, + {.key = {"password"}, .type = GF_OPTION_TYPE_ANY}, + { + .key = {"transport-type"}, + .value = {"tcp", "socket", "ib-verbs", "unix", "ib-sdp", "tcp/client", + "ib-verbs/client", "rdma"}, + .type = GF_OPTION_TYPE_STR, + .default_value = "tcp", + }, + {.key = {"remote-host"}, + .type = GF_OPTION_TYPE_INTERNET_ADDRESS, + .default_value = "{{ brick.hostname }}"}, + { + .key = {"remote-port"}, + .type = GF_OPTION_TYPE_INT, + }, + {.key = {"remote-subvolume"}, + .type = GF_OPTION_TYPE_ANY, + .default_value = "{{ brick.path }}"}, + {.key = {"frame-timeout", "rpc-timeout"}, + .type = GF_OPTION_TYPE_TIME, + .min = 0, + .max = 86400, + .default_value = "1800", + .description = "Time frame after which the (file) operation would be " + "declared as dead, if the server does not respond for " + "a particular (file) operation.", + .op_version = {1}, + .flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC}, + {.key = {"ping-timeout"}, + .type = GF_OPTION_TYPE_TIME, + .min = 0, + .max = 1013, + .default_value = TOSTRING(GF_NETWORK_TIMEOUT), + .description = "Time duration for which the client waits to " + "check if the server is responsive.", + .op_version = {1}, + .flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC}, + {.key = {"client-bind-insecure"}, .type = GF_OPTION_TYPE_BOOL}, + {.key = {"tcp-window-size"}, + .type = GF_OPTION_TYPE_SIZET, + .min = GF_MIN_SOCKET_WINDOW_SIZE, + .max = GF_MAX_SOCKET_WINDOW_SIZE, + .description = "Specifies the window size for tcp socket.", + .op_version = {1}, + .flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC}, + {.key = {"filter-O_DIRECT"}, + .type = GF_OPTION_TYPE_BOOL, + .default_value = "disable", + .description = + "If enabled, in open/creat/readv/writev fops, " + "O_DIRECT flag will be filtered at the client protocol level so " + "server will still continue to cache the file. This works similar to " + "NFS's behavior of O_DIRECT. Anon-fds can choose to readv/writev " + "using O_DIRECT", + .op_version = {2}, + .flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC}, + {.key = {"send-gids"}, + .type = GF_OPTION_TYPE_BOOL, + .default_value = "on", + .op_version = {GD_OP_VERSION_3_6_0}, + .flags = OPT_FLAG_SETTABLE}, + {.key = {"event-threads"}, + .type = GF_OPTION_TYPE_INT, + .min = 1, + .max = 32, + .default_value = "2", + .description = "Specifies the number of event threads to execute " + "in parallel. Larger values would help process" + " responses faster, depending on available processing" + " power. Range 1-32 threads.", + .op_version = {GD_OP_VERSION_3_7_0}, + .flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC}, + + /* This option is required for running code-coverage tests with + old protocol */ + { + .key = {"testing.old-protocol"}, + .type = GF_OPTION_TYPE_BOOL, + .default_value = "off", + .op_version = {GD_OP_VERSION_7_0}, + .flags = OPT_FLAG_SETTABLE, + }, + {.key = {"strict-locks"}, + .type = GF_OPTION_TYPE_BOOL, + .default_value = "off", + .op_version = {GD_OP_VERSION_7_0}, + .flags = OPT_FLAG_SETTABLE, + .description = "When set, doesn't reopen saved fds after reconnect " + "if POSIX locks are held on them. Hence subsequent " + "operations on these fds will fail. This is " + "necessary for stricter lock complaince as bricks " + "cleanup any granted locks when a client " + "disconnects."}, + {.key = {NULL}}, +}; + +xlator_api_t xlator_api = { + .init = init, + .fini = fini, + .notify = notify, + .reconfigure = reconfigure, + .mem_acct_init = mem_acct_init, + .op_version = {1}, /* Present from the initial version */ + .dumpops = &dumpops, + .fops = &fops, + .cbks = &cbks, + .options = options, + .identifier = "client", + .category = GF_MAINTAINED, }; diff --git a/xlators/protocol/client/src/client.h b/xlators/protocol/client/src/client.h index 84940de5f84..ab799c41755 100644 --- a/xlators/protocol/client/src/client.h +++ b/xlators/protocol/client/src/client.h @@ -1,20 +1,11 @@ /* - Copyright (c) 2010 Gluster, Inc. <http://www.gluster.com> - This file is part of GlusterFS. - - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. + 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. */ #ifndef _CLIENT_H @@ -24,120 +15,380 @@ #include <stdint.h> #include "rpc-clnt.h" -#include "list.h" -#include "inode.h" +#include <glusterfs/list.h> +#include <glusterfs/inode.h> #include "client-mem-types.h" #include "protocol-common.h" +#include "glusterfs3.h" #include "glusterfs3-xdr.h" +#include <glusterfs/fd-lk.h> +#include <glusterfs/defaults.h> +#include <glusterfs/default-args.h> +#include "client-messages.h" /* FIXME: Needs to be defined in a common file */ -#define CLIENT_CMD_CONNECT "trusted.glusterfs.client-connect" -#define CLIENT_CMD_DISCONNECT "trusted.glusterfs.client-disconnect" +#define CLIENT_DUMP_LOCKS "trusted.glusterfs.clientlk-dump" +#define GF_MAX_SOCKET_WINDOW_SIZE (1 * GF_UNIT_MB) +#define GF_MIN_SOCKET_WINDOW_SIZE (0) + +typedef enum { + DEFAULT_REMOTE_FD = 0, + FALLBACK_TO_ANON_FD = 1 +} clnt_remote_fd_flags_t; + +#define CLIENT_POST_FOP(fop, this_rsp_u, this_args_cbk, params...) \ + do { \ + gf_common_rsp *_this_rsp = &CPD_RSP_FIELD(this_rsp_u, fop); \ + \ + int _op_ret = _this_rsp->op_ret; \ + int _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 CLIENT_POST_FOP_TYPE(fop, this_rsp_u, this_args_cbk, params...) \ + do { \ + gfs3_##fop##_rsp *_this_rsp = &CPD_RSP_FIELD(this_rsp_u, fop); \ + \ + int _op_ret = _this_rsp->op_ret; \ + int _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 CLIENT_GET_REMOTE_FD(xl, fd, flags, remote_fd, op_errno, label) \ + do { \ + int _ret = 0; \ + _ret = client_get_remote_fd(xl, fd, flags, &remote_fd); \ + if (_ret < 0) { \ + op_errno = errno; \ + goto label; \ + } \ + if (remote_fd == -1) { \ + gf_smsg(xl->name, GF_LOG_WARNING, EBADFD, PC_MSG_BAD_FD, \ + "gfid=%s", uuid_utoa(fd->inode->gfid), NULL); \ + op_errno = EBADFD; \ + goto label; \ + } \ + } while (0) + +#define CLIENT_STACK_UNWIND(op, frame, params...) \ + do { \ + if (!frame) \ + break; \ + clnt_local_t *__local = frame->local; \ + frame->local = NULL; \ + STACK_UNWIND_STRICT(op, frame, params); \ + client_local_wipe(__local); \ + } while (0) struct clnt_options { - char *remote_subvolume; - int ping_timeout; + char *remote_subvolume; + int ping_timeout; }; typedef struct clnt_conf { - struct rpc_clnt *rpc; - struct clnt_options opt; - struct rpc_clnt_config rpc_conf; - struct list_head saved_fds; - pthread_mutex_t lock; - int connecting; - int connected; - struct timeval last_sent; - struct timeval last_received; - - rpc_clnt_prog_t *fops; - rpc_clnt_prog_t *mgmt; - rpc_clnt_prog_t *handshake; - rpc_clnt_prog_t *dump; + struct rpc_clnt *rpc; + struct clnt_options opt; + struct rpc_clnt_config rpc_conf; + struct list_head saved_fds; + pthread_spinlock_t fd_lock; /* protects saved_fds list + * and all fdctx */ + pthread_mutex_t lock; + int connected; + + rpc_clnt_prog_t *fops; + rpc_clnt_prog_t *mgmt; + rpc_clnt_prog_t *handshake; + rpc_clnt_prog_t *dump; + + int client_id; + uint64_t reopen_fd_count; /* Count of fds reopened after a + connection is established */ + gf_lock_t rec_lock; + int skip_notify; + + int last_sent_event; /* Flag used to make sure we are + not repeating the same event + which was sent earlier */ + char portmap_err_logged; /* flag used to prevent + excessive logging */ + char disconnect_err_logged; /* flag used to prevent + excessive disconnect + logging */ + char parent_down; + gf_boolean_t quick_reconnect; /* When reconnecting after + portmap query, do not let + the reconnection happen after + the usual 3-second wait + */ + gf_boolean_t filter_o_direct; /* if set, filter O_DIRECT from + the flags list of open() */ + /* set volume is the op which results in creating/re-using + * the conn-id and is called once per connection, this remembers + * how manytimes set_volume is called + */ + uint64_t setvol_count; + + gf_boolean_t send_gids; /* let the server resolve gids */ + + int event_threads; /* # of event threads + * configured */ + + gf_boolean_t destroy; /* if enabled implies fini was called + * on @this xlator instance */ + + gf_boolean_t child_up; /* Set to true, when child is up, and + * false, when child is down */ + + gf_boolean_t can_log_disconnect; /* socket level connection is + * up, disconnects can be + * logged + */ + + gf_boolean_t old_protocol; /* used only for old-protocol testing */ + pthread_cond_t fini_complete_cond; /* Used to wait till we finsh the fini + compltely, ie client_fini_complete + to return*/ + gf_boolean_t fini_completed; + gf_boolean_t strict_locks; /* When set, doesn't reopen saved fds after + reconnect if POSIX locks are held on them. + Hence subsequent operations on these fds will + fail. This is necessary for stricter lock + complaince as bricks cleanup any granted + locks when a client disconnects. + */ + + gf_boolean_t connection_to_brick; /*True from attempt to connect to brick + till disconnection to brick*/ } clnt_conf_t; typedef struct _client_fd_ctx { - struct list_head sfd_pos; /* Stores the reference to this - fd's position in the saved_fds list. - */ - int64_t remote_fd; - inode_t *inode; - uint64_t ino; - uint64_t gen; - char is_dir; - char released; - int32_t flags; - int32_t wbflags; + struct list_head sfd_pos; /* Stores the reference to this + fd's position in the saved_fds list. + */ + int64_t remote_fd; + char is_dir; + char released; + int32_t flags; + fd_lk_ctx_t *lk_ctx; + uuid_t gfid; + void (*reopen_done)(struct _client_fd_ctx *, int64_t rfd, xlator_t *); + struct list_head lock_list; /* List of all granted locks on this fd */ + int32_t reopen_attempts; } clnt_fd_ctx_t; +typedef struct _client_posix_lock { + fd_t *fd; /* The fd on which the lk operation was made */ + + struct gf_flock user_flock; /* the flock supplied by the user */ + off_t fl_start; + off_t fl_end; + short fl_type; + int32_t cmd; /* the cmd for the lock call */ + gf_lkowner_t owner; /* lock owner from fuse */ + struct list_head + list; /* reference used to add to the fdctx list of locks */ +} client_posix_lock_t; + typedef struct client_local { - loc_t loc; - loc_t loc2; - fd_t *fd; - clnt_fd_ctx_t *fdctx; - uint32_t flags; - uint32_t wbflags; - struct iobref *iobref; - fop_cbk_fn_t op; + loc_t loc; + loc_t loc2; + fd_t *fd; + fd_t *fd_out; /* used in copy_file_range */ + clnt_fd_ctx_t *fdctx; + uint32_t flags; + struct iobref *iobref; + + client_posix_lock_t *client_lock; + gf_lkowner_t owner; + int32_t cmd; + struct list_head lock_list; + pthread_mutex_t mutex; + char *name; + gf_boolean_t attempt_reopen; + /* + * The below boolean variable is used + * only for copy_file_range fop + */ + gf_boolean_t attempt_reopen_out; } clnt_local_t; typedef struct client_args { - loc_t *loc; - fd_t *fd; - dict_t *xattr_req; - const char *linkname; - struct iobref *iobref; - struct iovec *vector; - dict_t *xattr; - struct iatt *stbuf; - dict_t *dict; - loc_t *oldloc; - loc_t *newloc; - const char *name; - struct flock *flock; - const char *volume; - const char *basename; - off_t offset; - int32_t mask; - int32_t cmd; - size_t size; - mode_t mode; - dev_t rdev; - int32_t flags; - int32_t wbflags; - int32_t count; - int32_t datasync; - entrylk_cmd cmd_entrylk; - entrylk_type type; - gf_xattrop_flags_t optype; - int32_t valid; - int32_t len; + loc_t *loc; + /* + * This is the source fd for copy_file_range and + * the default fd for any other fd based fop which + * requires only one fd (i.e. opetates on one fd) + */ + fd_t *fd; + fd_t *fd_out; /* this is the destination fd for copy_file_range */ + const char *linkname; + struct iobref *iobref; + struct iovec *vector; + dict_t *xattr; + struct iatt *stbuf; + loc_t *oldloc; + loc_t *newloc; + const char *name; + struct gf_flock *flock; + const char *volume; + const char *basename; + + off_t offset; + /* + * According to the man page of copy_file_range, + * the offsets for source and destination file + * are of type loff_t. But the type loff_t is + * linux specific and is actual a typedef of + * off64_t. + */ + off64_t off_in; /* used in copy_file_range for source fd */ + off64_t off_out; /* used in copy_file_range for dst fd */ + int32_t mask; + int32_t cmd; + size_t size; + mode_t mode; + dev_t rdev; + int32_t flags; + int32_t count; + int32_t datasync; + entrylk_cmd cmd_entrylk; + entrylk_type type; + gf_xattrop_flags_t optype; + int32_t valid; + int32_t len; + gf_seek_what_t what; + struct gf_lease *lease; + + mode_t umask; + dict_t *xdata; + lock_migration_info_t *locklist; } clnt_args_t; -typedef ssize_t (*gfs_serialize_t) (struct iovec outmsg, void *args); +typedef struct client_payload { + struct iobref *iobref; + struct iovec *payload; + struct iovec *rsphdr; + struct iovec *rsp_payload; + struct iobref *rsp_iobref; + int payload_cnt; + int rsphdr_cnt; + int rsp_payload_cnt; +} client_payload_t; + +typedef ssize_t (*gfs_serialize_t)(struct iovec outmsg, void *args); + +clnt_fd_ctx_t * +this_fd_get_ctx(fd_t *file, xlator_t *this); +clnt_fd_ctx_t * +this_fd_del_ctx(fd_t *file, xlator_t *this); +void +this_fd_set_ctx(fd_t *file, xlator_t *this, loc_t *loc, clnt_fd_ctx_t *ctx); + +int +client_local_wipe(clnt_local_t *local); +int +client_submit_request(xlator_t *this, void *req, call_frame_t *frame, + rpc_clnt_prog_t *prog, int procnum, fop_cbk_fn_t cbk, + client_payload_t *cp, xdrproc_t xdrproc); + +int +unserialize_rsp_dirent(xlator_t *this, struct gfs3_readdir_rsp *rsp, + gf_dirent_t *entries); +int +unserialize_rsp_direntp(xlator_t *this, fd_t *fd, struct gfs3_readdirp_rsp *rsp, + gf_dirent_t *entries); + +int +clnt_readdir_rsp_cleanup(gfs3_readdir_rsp *rsp); +int +clnt_readdirp_rsp_cleanup(gfs3_readdirp_rsp *rsp); +int +client_attempt_lock_recovery(xlator_t *this, clnt_fd_ctx_t *fdctx); +int32_t +delete_granted_locks_owner(fd_t *fd, gf_lkowner_t *owner); +int32_t +delete_granted_locks_fd(clnt_fd_ctx_t *fdctx); +int32_t +client_cmd_to_gf_cmd(int32_t cmd, int32_t *gf_cmd); +void +client_save_number_fds(clnt_conf_t *conf, int count); +int +dump_client_locks(inode_t *inode); +int32_t +is_client_dump_locks_cmd(char *name); +int32_t +client_dump_locks(char *name, inode_t *inode, dict_t *dict); +int +client_fdctx_destroy(xlator_t *this, clnt_fd_ctx_t *fdctx); + +int +client_fd_lk_list_empty(fd_lk_ctx_t *lk_ctx, gf_boolean_t use_try_lock); +void +client_default_reopen_done(clnt_fd_ctx_t *fdctx, int64_t rfd, xlator_t *this); +void +client_attempt_reopen(fd_t *fd, xlator_t *this); +int +client_get_remote_fd(xlator_t *this, fd_t *fd, int flags, int64_t *remote_fd); +int +client_fd_fop_prepare_local(call_frame_t *frame, fd_t *fd, int64_t remote_fd); +gf_boolean_t +__is_fd_reopen_in_progress(clnt_fd_ctx_t *fdctx); +int +client_notify_dispatch(xlator_t *this, int32_t event, void *data, ...); +int +client_notify_dispatch_uniq(xlator_t *this, int32_t event, void *data, ...); + +gf_boolean_t +client_is_reopen_needed(fd_t *fd, xlator_t *this, int64_t remote_fd); + +int +client_add_fd_to_saved_fds(xlator_t *this, fd_t *fd, loc_t *loc, int32_t flags, + int64_t remote_fd, int is_dir); +int +clnt_unserialize_rsp_locklist(xlator_t *this, struct gfs3_getactivelk_rsp *rsp, + lock_migration_info_t *lmi); +void +clnt_getactivelk_rsp_cleanup(gfs3_getactivelk_rsp *rsp); + +void +clnt_setactivelk_req_cleanup(gfs3_setactivelk_req *req); + +int +serialize_req_locklist(lock_migration_info_t *locklist, + gfs3_setactivelk_req *req); + +void +clnt_getactivelk_rsp_cleanup_v2(gfx_getactivelk_rsp *rsp); + +void +clnt_setactivelk_req_cleanup_v2(gfx_setactivelk_req *req); -clnt_fd_ctx_t *this_fd_get_ctx (fd_t *file, xlator_t *this); -clnt_fd_ctx_t *this_fd_del_ctx (fd_t *file, xlator_t *this); -void this_fd_set_ctx (fd_t *file, xlator_t *this, loc_t *loc, - clnt_fd_ctx_t *ctx); +int +serialize_req_locklist_v2(lock_migration_info_t *locklist, + gfx_setactivelk_req *req); -int client_local_wipe (clnt_local_t *local); -int client_submit_request (xlator_t *this, void *req, - call_frame_t *frame, rpc_clnt_prog_t *prog, - int procnum, fop_cbk_fn_t cbk, - struct iobref *iobref, gfs_serialize_t sfunc, - struct iovec *rsphdr, int rsphdr_count, - struct iovec *rsp_payload, int rsp_count, - struct iobref *rsp_iobref); +int +clnt_unserialize_rsp_locklist_v2(xlator_t *this, + struct gfx_getactivelk_rsp *rsp, + lock_migration_info_t *lmi); -int protocol_client_reopendir (xlator_t *this, clnt_fd_ctx_t *fdctx); -int protocol_client_reopen (xlator_t *this, clnt_fd_ctx_t *fdctx); +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 unserialize_rsp_dirent (struct gfs3_readdir_rsp *rsp, gf_dirent_t *entries); -int unserialize_rsp_direntp (struct gfs3_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 clnt_readdir_rsp_cleanup (gfs3_readdir_rsp *rsp); -int clnt_readdirp_rsp_cleanup (gfs3_readdirp_rsp *rsp); +int +client_add_lock_for_recovery(fd_t *fd, struct gf_flock *flock, + gf_lkowner_t *owner, int32_t cmd); +int +client_is_setlk(int32_t cmd); #endif /* !_CLIENT_H */ diff --git a/xlators/protocol/client/src/client3_1-fops.c b/xlators/protocol/client/src/client3_1-fops.c deleted file mode 100644 index 69f2646978d..00000000000 --- a/xlators/protocol/client/src/client3_1-fops.c +++ /dev/null @@ -1,4991 +0,0 @@ -/* - Copyright (c) 2010 Gluster, Inc. <http://www.gluster.com> - This file is part of GlusterFS. - - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. -*/ - - -#ifndef _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif - -#include "client.h" -#include "glusterfs3-xdr.h" -#include "glusterfs3.h" -#include "compat-errno.h" - -int32_t client3_getspec (call_frame_t *frame, xlator_t *this, void *data); -void client_start_ping (void *data); -rpc_clnt_prog_t clnt3_1_fop_prog; - -int -client_submit_vec_request (xlator_t *this, void *req, call_frame_t *frame, - rpc_clnt_prog_t *prog, int procnum, fop_cbk_fn_t cbk, - struct iovec *payload, int payloadcnt, - struct iobref *iobref, gfs_serialize_t sfunc) -{ - int ret = 0; - clnt_conf_t *conf = NULL; - struct iovec iov = {0, }; - struct iobuf *iobuf = NULL; - int count = 0; - char new_iobref = 0; - int start_ping = 0; - - start_ping = 0; - - conf = this->private; - - iobuf = iobuf_get (this->ctx->iobuf_pool); - if (!iobuf) { - goto out; - }; - - if (!iobref) { - iobref = iobref_new (); - if (!iobref) { - goto out; - } - - new_iobref = 1; - } - - iobref_add (iobref, iobuf); - - iov.iov_base = iobuf->ptr; - iov.iov_len = 128 * GF_UNIT_KB; - - /* Create the xdr payload */ - if (req && sfunc) { - ret = sfunc (iov, req); - if (ret == -1) { - goto out; - } - iov.iov_len = ret; - count = 1; - } - /* Send the msg */ - ret = rpc_clnt_submit (conf->rpc, prog, procnum, cbk, &iov, count, - payload, payloadcnt, iobref, frame, NULL, 0, - NULL, 0, NULL); - - if (ret == 0) { - pthread_mutex_lock (&conf->rpc->conn.lock); - { - if (!conf->rpc->conn.ping_started) { - start_ping = 1; - } - } - pthread_mutex_unlock (&conf->rpc->conn.lock); - } - - if (start_ping) - client_start_ping ((void *) this); - -out: - if (new_iobref) { - iobref_unref (iobref); - } - - iobuf_unref (iobuf); - - return 0; -} - -/* CBK */ - -int -client3_1_symlink_cbk (struct rpc_req *req, struct iovec *iov, int count, - void *myframe) -{ - call_frame_t *frame = NULL; - gfs3_symlink_rsp rsp = {0,}; - struct iatt stbuf = {0,}; - struct iatt preparent = {0,}; - struct iatt postparent = {0,}; - int ret = 0; - clnt_local_t *local = NULL; - inode_t *inode = NULL; - - frame = myframe; - - local = frame->local; - frame->local = NULL; - inode = local->loc.inode; - - if (-1 == req->rpc_status) { - rsp.op_ret = -1; - rsp.op_errno = ENOTCONN; - goto out; - } - ret = xdr_to_symlink_rsp (*iov, &rsp); - if (ret < 0) { - gf_log ("", GF_LOG_ERROR, "error"); - rsp.op_ret = -1; - rsp.op_errno = EINVAL; - goto out; - } - - if (-1 != rsp.op_ret) { - gf_stat_to_iatt (&rsp.stat, &stbuf); - - gf_stat_to_iatt (&rsp.preparent, &preparent); - gf_stat_to_iatt (&rsp.postparent, &postparent); - } - -out: - frame->local = NULL; - STACK_UNWIND_STRICT (symlink, frame, rsp.op_ret, - gf_error_to_errno (rsp.op_errno), inode, &stbuf, - &preparent, &postparent); - - if (local) - client_local_wipe (local); - - return 0; -} - - -int -client3_1_mknod_cbk (struct rpc_req *req, struct iovec *iov, int count, - void *myframe) -{ - call_frame_t *frame = NULL; - gfs3_mknod_rsp rsp = {0,}; - struct iatt stbuf = {0,}; - struct iatt preparent = {0,}; - struct iatt postparent = {0,}; - int ret = 0; - clnt_local_t *local = NULL; - inode_t *inode = NULL; - - frame = myframe; - - local = frame->local; - frame->local = NULL; - inode = local->loc.inode; - - if (-1 == req->rpc_status) { - rsp.op_ret = -1; - rsp.op_errno = ENOTCONN; - goto out; - } - ret = xdr_to_mknod_rsp (*iov, &rsp); - if (ret < 0) { - gf_log ("", GF_LOG_ERROR, "error"); - rsp.op_ret = -1; - rsp.op_errno = EINVAL; - goto out; - } - - if (-1 != rsp.op_ret) { - gf_stat_to_iatt (&rsp.stat, &stbuf); - - gf_stat_to_iatt (&rsp.preparent, &preparent); - gf_stat_to_iatt (&rsp.postparent, &postparent); - } - -out: - frame->local = NULL; - STACK_UNWIND_STRICT (mknod, frame, rsp.op_ret, - gf_error_to_errno (rsp.op_errno), inode, - &stbuf, &preparent, &postparent); - - if (local) - client_local_wipe (local); - - return 0; -} - -int -client3_1_mkdir_cbk (struct rpc_req *req, struct iovec *iov, int count, - void *myframe) -{ - call_frame_t *frame = NULL; - gfs3_mkdir_rsp rsp = {0,}; - struct iatt stbuf = {0,}; - struct iatt preparent = {0,}; - struct iatt postparent = {0,}; - int ret = 0; - clnt_local_t *local = NULL; - inode_t *inode = NULL; - - frame = myframe; - - local = frame->local; - frame->local = NULL; - inode = local->loc.inode; - - if (-1 == req->rpc_status) { - rsp.op_ret = -1; - rsp.op_errno = ENOTCONN; - goto out; - } - ret = xdr_to_mkdir_rsp (*iov, &rsp); - if (ret < 0) { - gf_log ("", GF_LOG_ERROR, "error"); - rsp.op_ret = -1; - rsp.op_errno = EINVAL; - goto out; - } - - if (-1 != rsp.op_ret) { - gf_stat_to_iatt (&rsp.stat, &stbuf); - - gf_stat_to_iatt (&rsp.preparent, &preparent); - gf_stat_to_iatt (&rsp.postparent, &postparent); - } - -out: - STACK_UNWIND_STRICT (mkdir, frame, rsp.op_ret, - gf_error_to_errno (rsp.op_errno), inode, - &stbuf, &preparent, &postparent); - - if (local) - client_local_wipe (local); - - return 0; -} - -int -client3_1_open_cbk (struct rpc_req *req, struct iovec *iov, int count, - void *myframe) -{ - clnt_local_t *local = NULL; - clnt_conf_t *conf = NULL; - clnt_fd_ctx_t *fdctx = NULL; - call_frame_t *frame = NULL; - fd_t *fd = NULL; - int ret = 0; - gfs3_open_rsp rsp = {0,}; - - frame = myframe; - local = frame->local; - - if (local->op) { - local->op (req, iov, 1, myframe); - return 0; - } - - frame->local = NULL; - conf = frame->this->private; - fd = local->fd; - - if (-1 == req->rpc_status) { - rsp.op_ret = -1; - rsp.op_errno = ENOTCONN; - goto out; - } - ret = xdr_to_open_rsp (*iov, &rsp); - if (ret < 0) { - gf_log ("", GF_LOG_ERROR, "error"); - rsp.op_ret = -1; - rsp.op_errno = EINVAL; - goto out; - } - - if (-1 != rsp.op_ret) { - fdctx = GF_CALLOC (1, sizeof (*fdctx), - gf_client_mt_clnt_fdctx_t); - if (!fdctx) { - rsp.op_ret = -1; - rsp.op_errno = ENOMEM; - goto out; - } - - fdctx->remote_fd = rsp.fd; - fdctx->inode = inode_ref (fd->inode); - fdctx->flags = local->flags; - fdctx->wbflags = local->wbflags; - - INIT_LIST_HEAD (&fdctx->sfd_pos); - - this_fd_set_ctx (fd, frame->this, &local->loc, fdctx); - - pthread_mutex_lock (&conf->lock); - { - list_add_tail (&fdctx->sfd_pos, &conf->saved_fds); - } - pthread_mutex_unlock (&conf->lock); - } - -out: - frame->local = NULL; - STACK_UNWIND_STRICT (open, frame, rsp.op_ret, - gf_error_to_errno (rsp.op_errno), fd); - - client_local_wipe (local); - - return 0; -} - - -int -client3_1_stat_cbk (struct rpc_req *req, struct iovec *iov, int count, - void *myframe) -{ - gfs3_stat_rsp rsp = {0,}; - call_frame_t *frame = NULL; - struct iatt iatt = {0,}; - int ret = 0; - - frame = myframe; - - if (-1 == req->rpc_status) { - rsp.op_ret = -1; - rsp.op_errno = ENOTCONN; - goto out; - } - ret = xdr_to_stat_rsp (*iov, &rsp); - if (ret < 0) { - gf_log ("", GF_LOG_ERROR, "error"); - rsp.op_ret = -1; - rsp.op_errno = EINVAL; - goto out; - } - - if (-1 != rsp.op_ret) { - gf_stat_to_iatt (&rsp.stat, &iatt); - } - -out: - STACK_UNWIND_STRICT (stat, frame, rsp.op_ret, - gf_error_to_errno (rsp.op_errno), &iatt); - - return 0; -} - -int -client3_1_readlink_cbk (struct rpc_req *req, struct iovec *iov, int count, - void *myframe) -{ - gfs3_readlink_rsp rsp = {0,}; - call_frame_t *frame = NULL; - struct iatt iatt = {0,}; - int ret = 0; - - frame = myframe; - - if (-1 == req->rpc_status) { - rsp.op_ret = -1; - rsp.op_errno = ENOTCONN; - goto out; - } - ret = xdr_to_readlink_rsp (*iov, &rsp); - if (ret < 0) { - gf_log ("", GF_LOG_ERROR, "error"); - rsp.op_ret = -1; - rsp.op_errno = EINVAL; - goto out; - } - - if (-1 != rsp.op_ret) { - gf_stat_to_iatt (&rsp.buf, &iatt); - } - -out: - STACK_UNWIND_STRICT (readlink, frame, rsp.op_ret, - gf_error_to_errno (rsp.op_errno), rsp.path, &iatt); - - /* This is allocated by the libc while decoding RPC msg */ - /* Hence no 'GF_FREE', but just 'free' */ - if (rsp.path) - free (rsp.path); - - return 0; -} - -int -client3_1_unlink_cbk (struct rpc_req *req, struct iovec *iov, int count, - void *myframe) -{ - call_frame_t *frame = NULL; - gfs3_unlink_rsp rsp = {0,}; - struct iatt preparent = {0,}; - struct iatt postparent = {0,}; - int ret = 0; - - frame = myframe; - - if (-1 == req->rpc_status) { - rsp.op_ret = -1; - rsp.op_errno = ENOTCONN; - goto out; - } - ret = xdr_to_unlink_rsp (*iov, &rsp); - if (ret < 0) { - gf_log ("", GF_LOG_ERROR, "error"); - rsp.op_ret = -1; - rsp.op_errno = EINVAL; - goto out; - } - - if (-1 != rsp.op_ret) { - gf_stat_to_iatt (&rsp.preparent, &preparent); - gf_stat_to_iatt (&rsp.postparent, &postparent); - } - -out: - STACK_UNWIND_STRICT (unlink, frame, rsp.op_ret, - gf_error_to_errno (rsp.op_errno), &preparent, - &postparent); - - return 0; -} - -int -client3_1_rmdir_cbk (struct rpc_req *req, struct iovec *iov, int count, - void *myframe) -{ - gfs3_rmdir_rsp rsp = {0,}; - call_frame_t *frame = NULL; - struct iatt preparent = {0,}; - struct iatt postparent = {0,}; - int ret = 0; - - frame = myframe; - - if (-1 == req->rpc_status) { - rsp.op_ret = -1; - rsp.op_errno = ENOTCONN; - goto out; - } - ret = xdr_to_rmdir_rsp (*iov, &rsp); - if (ret < 0) { - gf_log ("", GF_LOG_ERROR, "error"); - rsp.op_ret = -1; - rsp.op_errno = EINVAL; - goto out; - } - - if (-1 != rsp.op_ret) { - gf_stat_to_iatt (&rsp.preparent, &preparent); - gf_stat_to_iatt (&rsp.postparent, &postparent); - } - -out: - STACK_UNWIND_STRICT (rmdir, frame, rsp.op_ret, - gf_error_to_errno (rsp.op_errno), &preparent, - &postparent); - - return 0; -} - - -int -client3_1_truncate_cbk (struct rpc_req *req, struct iovec *iov, int count, - void *myframe) -{ - gfs3_truncate_rsp rsp = {0,}; - call_frame_t *frame = NULL; - struct iatt prestat = {0,}; - struct iatt poststat = {0,}; - int ret = 0; - - frame = myframe; - - if (-1 == req->rpc_status) { - rsp.op_ret = -1; - rsp.op_errno = ENOTCONN; - goto out; - } - ret = xdr_to_truncate_rsp (*iov, &rsp); - if (ret < 0) { - gf_log ("", GF_LOG_ERROR, "error"); - rsp.op_ret = -1; - rsp.op_errno = EINVAL; - goto out; - } - - if (-1 != rsp.op_ret) { - gf_stat_to_iatt (&rsp.prestat, &prestat); - gf_stat_to_iatt (&rsp.poststat, &poststat); - } - -out: - STACK_UNWIND_STRICT (truncate, frame, rsp.op_ret, - gf_error_to_errno (rsp.op_errno), &prestat, - &poststat); - - return 0; -} - - -int -client3_1_statfs_cbk (struct rpc_req *req, struct iovec *iov, int count, - void *myframe) -{ - gfs3_statfs_rsp rsp = {0,}; - call_frame_t *frame = NULL; - struct statvfs statfs = {0,}; - int ret = 0; - - frame = myframe; - - if (-1 == req->rpc_status) { - rsp.op_ret = -1; - rsp.op_errno = ENOTCONN; - goto out; - } - ret = xdr_to_statfs_rsp (*iov, &rsp); - if (ret < 0) { - gf_log ("", GF_LOG_ERROR, "error"); - rsp.op_ret = -1; - rsp.op_errno = EINVAL; - goto out; - } - - if (-1 != rsp.op_ret) { - gf_statfs_to_statfs (&rsp.statfs, &statfs); - } - -out: - STACK_UNWIND_STRICT (statfs, frame, rsp.op_ret, - gf_error_to_errno (rsp.op_errno), &statfs); - - return 0; -} - - -int -client3_1_writev_cbk (struct rpc_req *req, struct iovec *iov, int count, - void *myframe) -{ - gfs3_write_rsp rsp = {0,}; - call_frame_t *frame = NULL; - struct iatt prestat = {0,}; - struct iatt poststat = {0,}; - int ret = 0; - - frame = myframe; - - if (-1 == req->rpc_status) { - rsp.op_ret = -1; - rsp.op_errno = ENOTCONN; - goto out; - } - - ret = xdr_to_truncate_rsp (*iov, &rsp); - if (ret < 0) { - gf_log ("", GF_LOG_ERROR, "error"); - rsp.op_ret = -1; - rsp.op_errno = EINVAL; - goto out; - } - - if (-1 != rsp.op_ret) { - gf_stat_to_iatt (&rsp.prestat, &prestat); - gf_stat_to_iatt (&rsp.poststat, &poststat); - } - -out: - STACK_UNWIND_STRICT (writev, frame, rsp.op_ret, - gf_error_to_errno (rsp.op_errno), &prestat, - &poststat); - - return 0; -} - -int -client3_1_flush_cbk (struct rpc_req *req, struct iovec *iov, int count, - void *myframe) -{ - call_frame_t *frame = NULL; - gf_common_rsp rsp = {0,}; - int ret = 0; - - frame = myframe; - - if (-1 == req->rpc_status) { - rsp.op_ret = -1; - rsp.op_errno = ENOTCONN; - goto out; - } - ret = xdr_to_common_rsp (*iov, &rsp); - if (ret < 0) { - gf_log ("", GF_LOG_ERROR, "error"); - rsp.op_ret = -1; - rsp.op_errno = EINVAL; - goto out; - } - -out: - STACK_UNWIND_STRICT (flush, frame, rsp.op_ret, - gf_error_to_errno (rsp.op_errno)); - - return 0; -} - -int -client3_1_fsync_cbk (struct rpc_req *req, struct iovec *iov, int count, - void *myframe) -{ - gfs3_fsync_rsp rsp = {0,}; - call_frame_t *frame = NULL; - struct iatt prestat = {0,}; - struct iatt poststat = {0,}; - int ret = 0; - - frame = myframe; - - if (-1 == req->rpc_status) { - rsp.op_ret = -1; - rsp.op_errno = ENOTCONN; - goto out; - } - - ret = xdr_to_truncate_rsp (*iov, &rsp); - if (ret < 0) { - gf_log ("", GF_LOG_ERROR, "error"); - rsp.op_ret = -1; - rsp.op_errno = EINVAL; - goto out; - } - - if (-1 != rsp.op_ret) { - gf_stat_to_iatt (&rsp.prestat, &prestat); - gf_stat_to_iatt (&rsp.poststat, &poststat); - } - -out: - STACK_UNWIND_STRICT (fsync, frame, rsp.op_ret, - gf_error_to_errno (rsp.op_errno), &prestat, - &poststat); - - return 0; -} - -int -client3_1_setxattr_cbk (struct rpc_req *req, struct iovec *iov, int count, - void *myframe) -{ - call_frame_t *frame = NULL; - gf_common_rsp rsp = {0,}; - int ret = 0; - - frame = myframe; - - if (-1 == req->rpc_status) { - rsp.op_ret = -1; - rsp.op_errno = ENOTCONN; - goto out; - } - - ret = xdr_to_common_rsp (*iov, &rsp); - if (ret < 0) { - gf_log ("", GF_LOG_ERROR, "error"); - rsp.op_ret = -1; - rsp.op_errno = EINVAL; - goto out; - } - -out: - STACK_UNWIND_STRICT (setxattr, frame, rsp.op_ret, - gf_error_to_errno (rsp.op_errno)); - - return 0; -} - -int -client3_1_getxattr_cbk (struct rpc_req *req, struct iovec *iov, int count, - void *myframe) -{ - call_frame_t *frame = NULL; - dict_t *dict = NULL; - char *buf = NULL; - int dict_len = 0; - int op_ret = 0; - int op_errno = EINVAL; - gfs3_getxattr_rsp rsp = {0,}; - int ret = 0; - - frame = myframe; - - if (-1 == req->rpc_status) { - op_ret = -1; - op_errno = ENOTCONN; - goto out; - } - - ret = xdr_to_getxattr_rsp (*iov, &rsp); - if (ret < 0) { - gf_log ("", GF_LOG_ERROR, "error"); - op_ret = -1; - op_errno = EINVAL; - goto out; - } - - op_errno = gf_error_to_errno (rsp.op_errno); - op_ret = rsp.op_ret; - if (-1 != op_ret) { - op_ret = -1; - dict_len = rsp.dict.dict_len; - - if (dict_len > 0) { - dict = dict_new(); - buf = memdup (rsp.dict.dict_val, rsp.dict.dict_len); - - GF_VALIDATE_OR_GOTO (frame->this->name, dict, out); - GF_VALIDATE_OR_GOTO (frame->this->name, buf, out); - - ret = dict_unserialize (buf, dict_len, &dict); - if (ret < 0) { - gf_log (frame->this->name, GF_LOG_DEBUG, - "failed to unserialize xattr dict"); - op_errno = EINVAL; - goto out; - } - dict->extra_free = buf; - buf = NULL; - } - op_ret = 0; - } - -out: - STACK_UNWIND_STRICT (getxattr, frame, op_ret, op_errno, dict); - - if (rsp.dict.dict_val) { - /* don't use GF_FREE, this memory was allocated by libc - */ - free (rsp.dict.dict_val); - rsp.dict.dict_val = NULL; - } - - if (buf) - GF_FREE (buf); - - if (dict) - dict_unref (dict); - - return 0; -} - -int -client3_1_fgetxattr_cbk (struct rpc_req *req, struct iovec *iov, int count, - void *myframe) -{ - call_frame_t *frame = NULL; - char *buf = NULL; - dict_t *dict = NULL; - gfs3_fgetxattr_rsp rsp = {0,}; - int ret = 0; - int dict_len = 0; - int op_ret = 0; - int op_errno = EINVAL; - - frame = myframe; - - if (-1 == req->rpc_status) { - op_ret = -1; - op_errno = ENOTCONN; - goto out; - } - ret = xdr_to_fgetxattr_rsp (*iov, &rsp); - if (ret < 0) { - gf_log ("", GF_LOG_ERROR, "error"); - op_ret = -1; - op_errno = EINVAL; - goto out; - } - - op_errno = gf_error_to_errno (rsp.op_errno); - op_ret = rsp.op_ret; - if (-1 != op_ret) { - op_ret = -1; - dict_len = rsp.dict.dict_len; - - if (dict_len > 0) { - dict = dict_new(); - GF_VALIDATE_OR_GOTO (frame->this->name, dict, out); - buf = memdup (rsp.dict.dict_val, rsp.dict.dict_len); - GF_VALIDATE_OR_GOTO (frame->this->name, buf, out); - - ret = dict_unserialize (buf, dict_len, &dict); - if (ret < 0) { - gf_log (frame->this->name, GF_LOG_DEBUG, - "failed to unserialize xattr dict"); - op_errno = EINVAL; - goto out; - } - dict->extra_free = buf; - buf = NULL; - } - op_ret = 0; - } -out: - STACK_UNWIND_STRICT (fgetxattr, frame, op_ret, op_errno, dict); - if (rsp.dict.dict_val) { - /* don't use GF_FREE, this memory was allocated by libc - */ - free (rsp.dict.dict_val); - rsp.dict.dict_val = NULL; - } - - if (buf) - GF_FREE (buf); - - if (dict) - dict_unref (dict); - - return 0; -} - -int -client3_1_removexattr_cbk (struct rpc_req *req, struct iovec *iov, int count, - void *myframe) -{ - call_frame_t *frame = NULL; - gf_common_rsp rsp = {0,}; - int ret = 0; - - frame = myframe; - - if (-1 == req->rpc_status) { - rsp.op_ret = -1; - rsp.op_errno = ENOTCONN; - goto out; - } - - ret = xdr_to_common_rsp (*iov, &rsp); - if (ret < 0) { - gf_log ("", GF_LOG_ERROR, "error"); - rsp.op_ret = -1; - rsp.op_errno = EINVAL; - goto out; - } - -out: - STACK_UNWIND_STRICT (removexattr, frame, rsp.op_ret, - gf_error_to_errno (rsp.op_errno)); - - return 0; -} - -int -client3_1_fsyncdir_cbk (struct rpc_req *req, struct iovec *iov, int count, - void *myframe) -{ - call_frame_t *frame = NULL; - gf_common_rsp rsp = {0,}; - int ret = 0; - - frame = myframe; - - if (-1 == req->rpc_status) { - rsp.op_ret = -1; - rsp.op_errno = ENOTCONN; - goto out; - } - ret = xdr_to_common_rsp (*iov, &rsp); - if (ret < 0) { - gf_log ("", GF_LOG_ERROR, "error"); - rsp.op_ret = -1; - rsp.op_errno = EINVAL; - goto out; - } - -out: - STACK_UNWIND_STRICT (fsyncdir, frame, rsp.op_ret, - gf_error_to_errno (rsp.op_errno)); - - return 0; -} - -int -client3_1_access_cbk (struct rpc_req *req, struct iovec *iov, int count, - void *myframe) -{ - call_frame_t *frame = NULL; - gf_common_rsp rsp = {0,}; - int ret = 0; - - frame = myframe; - - if (-1 == req->rpc_status) { - rsp.op_ret = -1; - rsp.op_errno = ENOTCONN; - goto out; - } - ret = xdr_to_common_rsp (*iov, &rsp); - if (ret < 0) { - gf_log ("", GF_LOG_ERROR, "error"); - rsp.op_ret = -1; - rsp.op_errno = EINVAL; - goto out; - } - -out: - STACK_UNWIND_STRICT (access, frame, rsp.op_ret, - gf_error_to_errno (rsp.op_errno)); - - return 0; -} - - -int -client3_1_ftruncate_cbk (struct rpc_req *req, struct iovec *iov, int count, - void *myframe) -{ - gfs3_ftruncate_rsp rsp = {0,}; - call_frame_t *frame = NULL; - struct iatt prestat = {0,}; - struct iatt poststat = {0,}; - int ret = 0; - - frame = myframe; - - if (-1 == req->rpc_status) { - rsp.op_ret = -1; - rsp.op_errno = ENOTCONN; - goto out; - } - ret = xdr_to_ftruncate_rsp (*iov, &rsp); - if (ret < 0) { - gf_log ("", GF_LOG_ERROR, "error"); - rsp.op_ret = -1; - rsp.op_errno = EINVAL; - goto out; - } - - if (-1 != rsp.op_ret) { - gf_stat_to_iatt (&rsp.prestat, &prestat); - gf_stat_to_iatt (&rsp.poststat, &poststat); - } - -out: - STACK_UNWIND_STRICT (ftruncate, frame, rsp.op_ret, - gf_error_to_errno (rsp.op_errno), &prestat, - &poststat); - - return 0; -} - -int -client3_1_fstat_cbk (struct rpc_req *req, struct iovec *iov, int count, - void *myframe) -{ - gfs3_fstat_rsp rsp = {0,}; - call_frame_t *frame = NULL; - struct iatt stat = {0,}; - int ret = 0; - - frame = myframe; - - if (-1 == req->rpc_status) { - rsp.op_ret = -1; - rsp.op_errno = ENOTCONN; - goto out; - } - ret = xdr_to_fstat_rsp (*iov, &rsp); - if (ret < 0) { - gf_log ("", GF_LOG_ERROR, "error"); - rsp.op_ret = -1; - rsp.op_errno = EINVAL; - goto out; - } - - if (-1 != rsp.op_ret) { - gf_stat_to_iatt (&rsp.stat, &stat); - } - -out: - STACK_UNWIND_STRICT (fstat, frame, rsp.op_ret, - gf_error_to_errno (rsp.op_errno), &stat); - - return 0; -} - - -int -client3_1_inodelk_cbk (struct rpc_req *req, struct iovec *iov, int count, - void *myframe) -{ - call_frame_t *frame = NULL; - gf_common_rsp rsp = {0,}; - int ret = 0; - - frame = myframe; - - if (-1 == req->rpc_status) { - rsp.op_ret = -1; - rsp.op_errno = ENOTCONN; - goto out; - } - ret = xdr_to_common_rsp (*iov, &rsp); - if (ret < 0) { - gf_log ("", GF_LOG_ERROR, "error"); - rsp.op_ret = -1; - rsp.op_errno = EINVAL; - goto out; - } - -out: - STACK_UNWIND_STRICT (inodelk, frame, rsp.op_ret, - gf_error_to_errno (rsp.op_errno)); - - return 0; -} - -int -client3_1_finodelk_cbk (struct rpc_req *req, struct iovec *iov, int count, - void *myframe) -{ - call_frame_t *frame = NULL; - gf_common_rsp rsp = {0,}; - int ret = 0; - - frame = myframe; - - if (-1 == req->rpc_status) { - rsp.op_ret = -1; - rsp.op_errno = ENOTCONN; - goto out; - } - ret = xdr_to_common_rsp (*iov, &rsp); - if (ret < 0) { - gf_log ("", GF_LOG_ERROR, "error"); - rsp.op_ret = -1; - rsp.op_errno = EINVAL; - goto out; - } - -out: - STACK_UNWIND_STRICT (finodelk, frame, rsp.op_ret, - gf_error_to_errno (rsp.op_errno)); - - return 0; -} - -int -client3_1_entrylk_cbk (struct rpc_req *req, struct iovec *iov, int count, - void *myframe) -{ - call_frame_t *frame = NULL; - gf_common_rsp rsp = {0,}; - int ret = 0; - - frame = myframe; - - if (-1 == req->rpc_status) { - rsp.op_ret = -1; - rsp.op_errno = ENOTCONN; - goto out; - } - ret = xdr_to_common_rsp (*iov, &rsp); - if (ret < 0) { - gf_log ("", GF_LOG_ERROR, "error"); - rsp.op_ret = -1; - rsp.op_errno = EINVAL; - goto out; - } - -out: - - STACK_UNWIND_STRICT (entrylk, frame, rsp.op_ret, - gf_error_to_errno (rsp.op_errno)); - - return 0; -} - -int -client3_1_fentrylk_cbk (struct rpc_req *req, struct iovec *iov, int count, - void *myframe) -{ - call_frame_t *frame = NULL; - gf_common_rsp rsp = {0,}; - int ret = 0; - - frame = myframe; - - if (-1 == req->rpc_status) { - rsp.op_ret = -1; - rsp.op_errno = ENOTCONN; - goto out; - } - ret = xdr_to_common_rsp (*iov, &rsp); - if (ret < 0) { - gf_log ("", GF_LOG_ERROR, "error"); - rsp.op_ret = -1; - rsp.op_errno = EINVAL; - goto out; - } - -out: - STACK_UNWIND_STRICT (fentrylk, frame, rsp.op_ret, - gf_error_to_errno (rsp.op_errno)); - - return 0; -} - -int -client3_1_xattrop_cbk (struct rpc_req *req, struct iovec *iov, int count, - void *myframe) -{ - call_frame_t *frame = NULL; - dict_t *dict = NULL; - char *buf = NULL; - gfs3_xattrop_rsp rsp = {0,}; - int ret = 0; - int op_ret = 0; - int dict_len = 0; - int op_errno = EINVAL; - - frame = myframe; - - if (-1 == req->rpc_status) { - op_ret = -1; - op_errno = ENOTCONN; - goto out; - } - ret = xdr_to_xattrop_rsp (*iov, &rsp); - if (ret < 0) { - gf_log ("", GF_LOG_ERROR, "error"); - op_ret = -1; - op_errno = EINVAL; - goto out; - } - - op_errno = rsp.op_errno; - op_ret = rsp.op_ret; - if (-1 != op_ret) { - op_ret = -1; - dict_len = rsp.dict.dict_len; - - if (dict_len > 0) { - dict = dict_new(); - GF_VALIDATE_OR_GOTO (frame->this->name, dict, out); - - buf = memdup (rsp.dict.dict_val, rsp.dict.dict_len); - GF_VALIDATE_OR_GOTO (frame->this->name, buf, out); - op_ret = dict_unserialize (buf, dict_len, &dict); - if (op_ret < 0) { - gf_log (frame->this->name, GF_LOG_DEBUG, - "failed to unserialize xattr dict"); - op_errno = EINVAL; - goto out; - } - dict->extra_free = buf; - buf = NULL; - } - op_ret = 0; - } - -out: - - STACK_UNWIND_STRICT (xattrop, frame, op_ret, - gf_error_to_errno (op_errno), dict); - - if (rsp.dict.dict_val) { - /* don't use GF_FREE, this memory was allocated by libc - */ - free (rsp.dict.dict_val); - rsp.dict.dict_val = NULL; - } - - if (buf) - GF_FREE (buf); - - if (dict) - dict_unref (dict); - - return 0; -} - -int -client3_1_fxattrop_cbk (struct rpc_req *req, struct iovec *iov, int count, - void *myframe) -{ - call_frame_t *frame = NULL; - dict_t *dict = NULL; - char *buf = NULL; - gfs3_fxattrop_rsp rsp = {0,}; - int ret = 0; - int op_ret = 0; - int dict_len = 0; - int op_errno = 0; - - frame = myframe; - - if (-1 == req->rpc_status) { - op_ret = -1; - op_errno = ENOTCONN; - goto out; - } - - ret = xdr_to_fxattrop_rsp (*iov, &rsp); - if (ret < 0) { - op_ret = -1; - op_errno = EINVAL; - gf_log ("", GF_LOG_ERROR, "error"); - goto out; - } - op_errno = rsp.op_errno; - op_ret = rsp.op_ret; - if (-1 != op_ret) { - op_ret = -1; - dict_len = rsp.dict.dict_len; - - if (dict_len > 0) { - dict = dict_new(); - GF_VALIDATE_OR_GOTO (frame->this->name, dict, out); - - buf = memdup (rsp.dict.dict_val, rsp.dict.dict_len); - GF_VALIDATE_OR_GOTO (frame->this->name, buf, out); - op_ret = dict_unserialize (buf, dict_len, &dict); - if (op_ret < 0) { - gf_log (frame->this->name, GF_LOG_DEBUG, - "failed to unserialize xattr dict"); - op_errno = EINVAL; - goto out; - } - dict->extra_free = buf; - buf = NULL; - } - op_ret = 0; - } - -out: - - STACK_UNWIND_STRICT (fxattrop, frame, op_ret, - gf_error_to_errno (op_errno), dict); - - if (rsp.dict.dict_val) { - /* don't use GF_FREE, this memory was allocated by libc - */ - free (rsp.dict.dict_val); - rsp.dict.dict_val = NULL; - } - - if (buf) - GF_FREE (buf); - - if (dict) - dict_unref (dict); - - return 0; -} - -int -client3_1_fsetxattr_cbk (struct rpc_req *req, struct iovec *iov, int count, - void *myframe) -{ - call_frame_t *frame = NULL; - gf_common_rsp rsp = {0,}; - int ret = 0; - - frame = myframe; - - if (-1 == req->rpc_status) { - rsp.op_ret = -1; - rsp.op_errno = ENOTCONN; - goto out; - } - ret = xdr_to_common_rsp (*iov, &rsp); - if (ret < 0) { - gf_log ("", GF_LOG_ERROR, "error"); - rsp.op_ret = -1; - rsp.op_errno = EINVAL; - goto out; - } - -out: - STACK_UNWIND_STRICT (fsetxattr, frame, rsp.op_ret, - gf_error_to_errno (rsp.op_errno)); - - return 0; -} - -int -client3_1_fsetattr_cbk (struct rpc_req *req, struct iovec *iov, int count, - void *myframe) -{ - call_frame_t *frame = NULL; - gfs3_fsetattr_rsp rsp = {0,}; - struct iatt prestat = {0,}; - struct iatt poststat = {0,}; - int ret = 0; - - frame = myframe; - - if (-1 == req->rpc_status) { - rsp.op_ret = -1; - rsp.op_errno = ENOTCONN; - goto out; - } - ret = xdr_to_fsetattr_rsp (*iov, &rsp); - if (ret < 0) { - gf_log ("", GF_LOG_ERROR, "error"); - rsp.op_ret = -1; - rsp.op_errno = EINVAL; - goto out; - } - - if (-1 != rsp.op_ret) { - gf_stat_to_iatt (&rsp.statpre, &prestat); - gf_stat_to_iatt (&rsp.statpost, &poststat); - } - -out: - STACK_UNWIND_STRICT (fsetattr, frame, rsp.op_ret, - gf_error_to_errno (rsp.op_errno), &prestat, - &poststat); - - return 0; -} - - -int -client3_1_setattr_cbk (struct rpc_req *req, struct iovec *iov, int count, - void *myframe) -{ - call_frame_t *frame = NULL; - gfs3_setattr_rsp rsp = {0,}; - struct iatt prestat = {0,}; - struct iatt poststat = {0,}; - int ret = 0; - - frame = myframe; - - if (-1 == req->rpc_status) { - rsp.op_ret = -1; - rsp.op_errno = ENOTCONN; - goto out; - } - - ret = xdr_to_setattr_rsp (*iov, &rsp); - if (ret < 0) { - gf_log ("", GF_LOG_ERROR, "error"); - rsp.op_ret = -1; - rsp.op_errno = EINVAL; - goto out; - } - - if (-1 != rsp.op_ret) { - gf_stat_to_iatt (&rsp.statpre, &prestat); - gf_stat_to_iatt (&rsp.statpost, &poststat); - } - -out: - STACK_UNWIND_STRICT (setattr, frame, rsp.op_ret, - gf_error_to_errno (rsp.op_errno), &prestat, - &poststat); - - return 0; -} - -int -client3_1_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; - clnt_conf_t *conf = NULL; - clnt_fd_ctx_t *fdctx = NULL; - gfs3_create_rsp rsp = {0,}; - - frame = myframe; - local = frame->local; frame->local = NULL; - conf = frame->this->private; - 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_create_rsp (*iov, &rsp); - if (ret < 0) { - gf_log ("", GF_LOG_ERROR, "error"); - rsp.op_ret = -1; - rsp.op_errno = EINVAL; - goto out; - } - - if (-1 != rsp.op_ret) { - gf_stat_to_iatt (&rsp.stat, &stbuf); - - gf_stat_to_iatt (&rsp.preparent, &preparent); - gf_stat_to_iatt (&rsp.postparent, &postparent); - - fdctx = GF_CALLOC (1, sizeof (*fdctx), - gf_client_mt_clnt_fdctx_t); - if (!fdctx) { - rsp.op_ret = -1; - rsp.op_errno = ENOMEM; - goto out; - } - - fdctx->remote_fd = rsp.fd; - fdctx->inode = inode_ref (inode); - fdctx->flags = local->flags; - - INIT_LIST_HEAD (&fdctx->sfd_pos); - - this_fd_set_ctx (fd, frame->this, &local->loc, fdctx); - - pthread_mutex_lock (&conf->lock); - { - list_add_tail (&fdctx->sfd_pos, &conf->saved_fds); - } - pthread_mutex_unlock (&conf->lock); - } - -out: - frame->local = NULL; - STACK_UNWIND_STRICT (create, frame, rsp.op_ret, - gf_error_to_errno (rsp.op_errno), fd, inode, - &stbuf, &preparent, &postparent); - - client_local_wipe (local); - return 0; -} - - -int -client3_1_rchecksum_cbk (struct rpc_req *req, struct iovec *iov, int count, - void *myframe) -{ - call_frame_t *frame = NULL; - gfs3_rchecksum_rsp rsp = {0,}; - int ret = 0; - - frame = myframe; - - if (-1 == req->rpc_status) { - rsp.op_ret = -1; - rsp.op_errno = ENOTCONN; - goto out; - } - - ret = xdr_to_rchecksum_rsp (*iov, &rsp); - if (ret < 0) { - gf_log ("", GF_LOG_ERROR, "error"); - rsp.op_ret = -1; - rsp.op_errno = EINVAL; - goto out; - } - -out: - STACK_UNWIND_STRICT (rchecksum, frame, rsp.op_ret, - gf_error_to_errno (rsp.op_errno), - rsp.weak_checksum, - (uint8_t *)rsp.strong_checksum.strong_checksum_val); - - 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); - } - - return 0; -} - -int -client3_1_lk_cbk (struct rpc_req *req, struct iovec *iov, int count, - void *myframe) -{ - call_frame_t *frame = NULL; - struct flock lock = {0,}; - gfs3_lk_rsp rsp = {0,}; - int ret = 0; - - frame = myframe; - - if (-1 == req->rpc_status) { - rsp.op_ret = -1; - rsp.op_errno = ENOTCONN; - goto out; - } - - ret = xdr_to_lk_rsp (*iov, &rsp); - if (ret < 0) { - gf_log ("", GF_LOG_ERROR, "error"); - rsp.op_ret = -1; - rsp.op_errno = EINVAL; - goto out; - } - - if (rsp.op_ret >= 0) { - gf_flock_to_flock (&rsp.flock, &lock); - } - -out: - STACK_UNWIND_STRICT (lk, frame, rsp.op_ret, - gf_error_to_errno (rsp.op_errno), &lock); - - return 0; -} - -int -client3_1_readdir_cbk (struct rpc_req *req, struct iovec *iov, int count, - void *myframe) -{ - call_frame_t *frame = NULL; - gfs3_readdir_rsp rsp = {0,}; - int32_t ret = 0; - gf_dirent_t entries; - - frame = myframe; - - if (-1 == req->rpc_status) { - rsp.op_ret = -1; - rsp.op_errno = ENOTCONN; - goto out; - } - - ret = xdr_to_readdir_rsp (*iov, &rsp); - if (ret < 0) { - gf_log ("", GF_LOG_ERROR, "error"); - rsp.op_ret = -1; - rsp.op_errno = EINVAL; - goto out; - } - - INIT_LIST_HEAD (&entries.list); - if (rsp.op_ret > 0) { - unserialize_rsp_dirent (&rsp, &entries); - } - -out: - STACK_UNWIND_STRICT (readdir, frame, rsp.op_ret, - gf_error_to_errno (rsp.op_errno), &entries); - - if (rsp.op_ret != -1) { - gf_dirent_free (&entries); - } - - clnt_readdir_rsp_cleanup (&rsp); - - return 0; -} - - -int -client3_1_readdirp_cbk (struct rpc_req *req, struct iovec *iov, int count, - void *myframe) -{ - call_frame_t *frame = NULL; - gfs3_readdirp_rsp rsp = {0,}; - int32_t ret = 0; - gf_dirent_t entries; - - frame = myframe; - - if (-1 == req->rpc_status) { - rsp.op_ret = -1; - rsp.op_errno = ENOTCONN; - goto out; - } - - ret = xdr_to_readdirp_rsp (*iov, &rsp); - if (ret < 0) { - gf_log ("", GF_LOG_ERROR, "error"); - rsp.op_ret = -1; - rsp.op_errno = EINVAL; - goto out; - } - - INIT_LIST_HEAD (&entries.list); - if (rsp.op_ret > 0) { - unserialize_rsp_direntp (&rsp, &entries); - } - -out: - STACK_UNWIND_STRICT (readdirp, frame, rsp.op_ret, - gf_error_to_errno (rsp.op_errno), &entries); - - if (rsp.op_ret != -1) { - gf_dirent_free (&entries); - } - - clnt_readdirp_rsp_cleanup (&rsp); - - return 0; -} - - -int -client3_1_rename_cbk (struct rpc_req *req, struct iovec *iov, int count, - void *myframe) -{ - call_frame_t *frame = NULL; - gfs3_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; - - frame = myframe; - - if (-1 == req->rpc_status) { - rsp.op_ret = -1; - rsp.op_errno = ENOTCONN; - goto out; - } - - ret = xdr_to_rename_rsp (*iov, &rsp); - if (ret < 0) { - gf_log ("", GF_LOG_ERROR, "error"); - rsp.op_ret = -1; - rsp.op_errno = EINVAL; - goto out; - } - - if (-1 != rsp.op_ret) { - gf_stat_to_iatt (&rsp.stat, &stbuf); - - gf_stat_to_iatt (&rsp.preoldparent, &preoldparent); - gf_stat_to_iatt (&rsp.postoldparent, &postoldparent); - - gf_stat_to_iatt (&rsp.prenewparent, &prenewparent); - gf_stat_to_iatt (&rsp.postnewparent, &postnewparent); - } - -out: - STACK_UNWIND_STRICT (rename, frame, rsp.op_ret, - gf_error_to_errno (rsp.op_errno), - &stbuf, &preoldparent, &postoldparent, - &preoldparent, &postoldparent); - - return 0; -} - -int -client3_1_link_cbk (struct rpc_req *req, struct iovec *iov, int count, - void *myframe) -{ - call_frame_t *frame = NULL; - gfs3_link_rsp rsp = {0,}; - struct iatt stbuf = {0,}; - struct iatt preparent = {0,}; - struct iatt postparent = {0,}; - int ret = 0; - clnt_local_t *local = NULL; - inode_t *inode = NULL; - - frame = myframe; - - local = frame->local; - frame->local = NULL; - inode = local->loc.inode; - - if (-1 == req->rpc_status) { - rsp.op_ret = -1; - rsp.op_errno = ENOTCONN; - goto out; - } - - ret = xdr_to_link_rsp (*iov, &rsp); - if (ret < 0) { - gf_log ("", GF_LOG_ERROR, "error"); - rsp.op_ret = -1; - rsp.op_errno = EINVAL; - goto out; - } - - if (-1 != rsp.op_ret) { - gf_stat_to_iatt (&rsp.stat, &stbuf); - - gf_stat_to_iatt (&rsp.preparent, &preparent); - gf_stat_to_iatt (&rsp.postparent, &postparent); - } - -out: - frame->local = NULL; - STACK_UNWIND_STRICT (link, frame, rsp.op_ret, - gf_error_to_errno (rsp.op_errno), inode, - &stbuf, &preparent, &postparent); - - client_local_wipe (local); - return 0; -} - - -int -client3_1_opendir_cbk (struct rpc_req *req, struct iovec *iov, int count, - void *myframe) -{ - clnt_local_t *local = NULL; - clnt_conf_t *conf = NULL; - clnt_fd_ctx_t *fdctx = NULL; - call_frame_t *frame = NULL; - fd_t *fd = NULL; - int ret = 0; - gfs3_opendir_rsp rsp = {0,}; - - frame = myframe; - local = frame->local; - - if (local->op) { - local->op (req, iov, 1, myframe); - return 0; - } - - frame->local = NULL; - conf = frame->this->private; - fd = local->fd; - - if (-1 == req->rpc_status) { - rsp.op_ret = -1; - rsp.op_errno = ENOTCONN; - goto out; - } - - ret = xdr_to_opendir_rsp (*iov, &rsp); - if (ret < 0) { - gf_log ("", GF_LOG_ERROR, "error"); - rsp.op_ret = -1; - rsp.op_errno = EINVAL; - goto out; - } - - if (-1 != rsp.op_ret) { - fdctx = GF_CALLOC (1, sizeof (*fdctx), - gf_client_mt_clnt_fdctx_t); - if (!fdctx) { - rsp.op_ret = -1; - rsp.op_errno = ENOMEM; - goto out; - } - - fdctx->remote_fd = rsp.fd; - fdctx->inode = inode_ref (fd->inode); - fdctx->is_dir = 1; - - INIT_LIST_HEAD (&fdctx->sfd_pos); - - this_fd_set_ctx (fd, frame->this, &local->loc, fdctx); - - pthread_mutex_lock (&conf->lock); - { - list_add_tail (&fdctx->sfd_pos, &conf->saved_fds); - } - pthread_mutex_unlock (&conf->lock); - } - -out: - frame->local = NULL; - STACK_UNWIND_STRICT (opendir, frame, rsp.op_ret, - gf_error_to_errno (rsp.op_errno), fd); - - client_local_wipe (local); - - return 0; -} - - -int -client3_1_lookup_cbk (struct rpc_req *req, struct iovec *iov, int count, - void *myframe) -{ - clnt_local_t *local = NULL; - call_frame_t *frame = NULL; - int ret = 0; - gfs3_lookup_rsp rsp = {0,}; - struct iatt stbuf = {0,}; - struct iatt postparent = {0,}; - int op_errno = EINVAL; - dict_t *xattr = NULL; - inode_t *inode = NULL; - char *buf = NULL; - - frame = myframe; - local = frame->local; - inode = local->loc.inode; - frame->local = NULL; - - if (-1 == req->rpc_status) { - rsp.op_ret = -1; - op_errno = ENOTCONN; - goto out; - } - - ret = xdr_to_lookup_rsp (*iov, &rsp); - if (ret < 0) { - gf_log ("", GF_LOG_ERROR, "error"); - rsp.op_ret = -1; - op_errno = EINVAL; - goto out; - } - - op_errno = gf_error_to_errno (rsp.op_errno); - gf_stat_to_iatt (&rsp.postparent, &postparent); - - if (rsp.op_ret == -1) - goto out; - - rsp.op_ret = -1; - gf_stat_to_iatt (&rsp.stat, &stbuf); - - if (rsp.dict.dict_len > 0) { - xattr = dict_new(); - GF_VALIDATE_OR_GOTO (frame->this->name, xattr, out); - - buf = memdup (rsp.dict.dict_val, rsp.dict.dict_len); - GF_VALIDATE_OR_GOTO (frame->this->name, buf, out); - - ret = dict_unserialize (buf, rsp.dict.dict_len, &xattr); - if (ret < 0) { - gf_log (frame->this->name, GF_LOG_DEBUG, - "%s (%"PRId64"): failed to " - "unserialize dictionary", - local->loc.path, inode->ino); - op_errno = EINVAL; - goto out; - } - - xattr->extra_free = buf; - buf = NULL; - } - - rsp.op_ret = 0; - -out: - rsp.op_errno = op_errno; - frame->local = NULL; - STACK_UNWIND_STRICT (lookup, frame, rsp.op_ret, rsp.op_errno, inode, - &stbuf, xattr, &postparent); - - client_local_wipe (local); - - if (xattr) - dict_unref (xattr); - - if (rsp.dict.dict_val) { - /* don't use GF_FREE, this memory was allocated by libc - */ - free (rsp.dict.dict_val); - rsp.dict.dict_val = NULL; - } - - if (buf) { - GF_FREE (buf); - } - - return 0; -} - -int -client3_1_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]; - struct iatt stat = {0,}; - gfs3_read_rsp rsp = {0,}; - int ret = 0, rspcount = 0; - clnt_local_t *local = NULL; - - memset (vector, 0, sizeof (vector)); - - frame = myframe; - local = frame->local; - frame->local = NULL; - - if (-1 == req->rpc_status) { - rsp.op_ret = -1; - rsp.op_errno = ENOTCONN; - goto out; - } - - ret = xdr_to_readv_rsp (*iov, &rsp); - if (ret < 0) { - gf_log ("", GF_LOG_ERROR, "error"); - rsp.op_ret = -1; - rsp.op_errno = EINVAL; - goto out; - } - - if (rsp.op_ret != -1) { - iobref = req->rsp_iobref; - gf_stat_to_iatt (&rsp.stat, &stat); - - vector[0].iov_len = rsp.op_ret; - if (rsp.op_ret > 0) - vector[0].iov_base = req->rsp[1].iov_base; - rspcount = 1; - } -out: - STACK_UNWIND_STRICT (readv, frame, rsp.op_ret, - gf_error_to_errno (rsp.op_errno), vector, rspcount, - &stat, iobref); - - if (local) { - client_local_wipe (local); - } - - return 0; -} - -int -client3_1_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 -client3_1_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 -client_fdctx_destroy (xlator_t *this, clnt_fd_ctx_t *fdctx) -{ - call_frame_t *fr = NULL; - int32_t ret = -1; - - if (!fdctx) - goto out; - - if (fdctx->remote_fd == -1) - goto out; - - fr = create_frame (this, this->ctx->pool); - - if (fdctx->is_dir) { - gfs3_releasedir_req req = {0,}; - req.fd = fdctx->remote_fd; - req.gfs_id = GFS3_OP_RELEASEDIR; - ret = client_submit_request (this, &req, fr, &clnt3_1_fop_prog, - GFS3_OP_RELEASEDIR, - client3_1_releasedir_cbk, - NULL, xdr_from_releasedir_req, - NULL, 0, NULL, 0, NULL); - } else { - gfs3_release_req req = {0,}; - req.fd = fdctx->remote_fd; - req.gfs_id = GFS3_OP_RELEASE; - ret = client_submit_request (this, &req, fr, &clnt3_1_fop_prog, - GFS3_OP_RELEASE, - client3_1_release_cbk, NULL, - xdr_from_release_req, NULL, 0, - NULL, 0, NULL); - } - -out: - if (!ret && fdctx) { - fdctx->remote_fd = -1; - inode_unref (fdctx->inode); - GF_FREE (fdctx); - } - - if (ret && fr) - STACK_DESTROY (fr->root); - - return ret; -} - -int -client3_1_reopen_cbk (struct rpc_req *req, struct iovec *iov, int count, - void *myframe) -{ - int32_t ret = -1; - gfs3_open_rsp rsp = {0,}; - clnt_local_t *local = NULL; - clnt_conf_t *conf = NULL; - clnt_fd_ctx_t *fdctx = NULL; - call_frame_t *frame = NULL; - - frame = myframe; - local = frame->local; - conf = frame->this->private; - - if (-1 == req->rpc_status) { - rsp.op_ret = -1; - rsp.op_errno = ENOTCONN; - goto out; - } - - ret = xdr_to_open_rsp (*iov, &rsp); - if (ret < 0) { - gf_log ("", GF_LOG_ERROR, "error"); - rsp.op_ret = -1; - rsp.op_errno = EINVAL; - goto out; - } - - gf_log (frame->this->name, GF_LOG_DEBUG, - "reopen on %s returned %d (%"PRId64")", - local->loc.path, rsp.op_ret, rsp.fd); - - if (-1 != rsp.op_ret) { - fdctx = local->fdctx; - if(fdctx) { - pthread_mutex_lock (&conf->lock); - { - fdctx->remote_fd = rsp.fd; - - if (!fdctx->released) { - list_add_tail (&fdctx->sfd_pos, &conf->saved_fds); - fdctx = NULL; - } - } - pthread_mutex_unlock (&conf->lock); - - } - } - -out: - if (fdctx) - client_fdctx_destroy (frame->this, fdctx); - - frame->local = NULL; - STACK_DESTROY (frame->root); - - client_local_wipe (local); - - return 0; -} - -int -client3_1_reopendir_cbk (struct rpc_req *req, struct iovec *iov, int count, - void *myframe) -{ - int32_t ret = -1; - gfs3_open_rsp rsp = {0,}; - clnt_local_t *local = NULL; - clnt_conf_t *conf = NULL; - clnt_fd_ctx_t *fdctx = NULL; - call_frame_t *frame = NULL; - - frame = myframe; - if (!frame || !frame->this) - goto out; - - local = frame->local; - frame->local = NULL; - conf = frame->this->private; - - if (-1 == req->rpc_status) { - rsp.op_ret = -1; - rsp.op_errno = ENOTCONN; - goto out; - } - - ret = xdr_to_opendir_rsp (*iov, &rsp); - if (ret < 0) { - gf_log ("", GF_LOG_ERROR, "error"); - rsp.op_ret = -1; - rsp.op_errno = EINVAL; - goto out; - } - - gf_log (frame->this->name, GF_LOG_DEBUG, - "reopendir on %s returned %d (%"PRId64")", - local->loc.path, rsp.op_ret, rsp.fd); - - if (-1 != rsp.op_ret) { - fdctx = local->fdctx; - if (fdctx) { - pthread_mutex_lock (&conf->lock); - { - fdctx->remote_fd = rsp.fd; - - if (!fdctx->released) { - list_add_tail (&fdctx->sfd_pos, &conf->saved_fds); - fdctx = NULL; - } - } - pthread_mutex_unlock (&conf->lock); - - } - } - -out: - if (fdctx) - client_fdctx_destroy (frame->this, fdctx); - - if (frame) { - frame->local = NULL; - STACK_DESTROY (frame->root); - } - - client_local_wipe (local); - - return 0; -} - -int -protocol_client_reopendir (xlator_t *this, clnt_fd_ctx_t *fdctx) -{ - int ret = -1; - gfs3_opendir_req req = {0,}; - clnt_local_t *local = NULL; - inode_t *inode = NULL; - char *path = NULL; - call_frame_t *frame = NULL; - clnt_conf_t *conf = NULL; - - if (!this || !fdctx) - goto out; - - inode = fdctx->inode; - conf = this->private; - - ret = inode_path (inode, NULL, &path); - if (ret < 0) { - goto out; - } - - local = GF_CALLOC (1, sizeof (*local), gf_client_mt_clnt_local_t); - if (!local) { - goto out; - } - - local->fdctx = fdctx; - local->op = client3_1_reopendir_cbk; - local->loc.path = path; - path = NULL; - - frame = create_frame (this, this->ctx->pool); - if (!frame) { - goto out; - } - - memcpy (req.gfid, inode->gfid, 16); - req.path = (char *)local->loc.path; - req.gfs_id = GFS3_OP_OPENDIR; - - gf_log (frame->this->name, GF_LOG_DEBUG, - "attempting reopen on %s", local->loc.path); - - frame->local = local; local = NULL; - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_OPENDIR, - client3_1_opendir_cbk, NULL, - xdr_from_opendir_req, NULL, 0, NULL, 0, - NULL); - if (ret) - goto out; - - return ret; - -out: - if (frame) { - frame->local = NULL; - STACK_DESTROY (frame->root); - } - - if (local) - client_local_wipe (local); - - if (path) - GF_FREE (path); - - return 0; - -} - -int -protocol_client_reopen (xlator_t *this, clnt_fd_ctx_t *fdctx) -{ - int ret = -1; - gfs3_open_req req = {0,}; - clnt_local_t *local = NULL; - inode_t *inode = NULL; - char *path = NULL; - call_frame_t *frame = NULL; - clnt_conf_t *conf = NULL; - - if (!this || !fdctx) - goto out; - - inode = fdctx->inode; - conf = this->private; - - ret = inode_path (inode, NULL, &path); - if (ret < 0) { - goto out; - } - - frame = create_frame (this, this->ctx->pool); - if (!frame) { - goto out; - } - - local = GF_CALLOC (1, sizeof (*local), gf_client_mt_clnt_local_t); - if (!local) { - goto out; - } - - local->fdctx = fdctx; - local->op = client3_1_reopen_cbk; - local->loc.path = path; - path = NULL; - frame->local = local; - - memcpy (req.gfid, inode->gfid, 16); - req.flags = gf_flags_from_flags (fdctx->flags); - req.wbflags = fdctx->wbflags; - req.path = (char *)local->loc.path; - req.gfs_id = GFS3_OP_OPEN; - - gf_log (frame->this->name, GF_LOG_DEBUG, - "attempting reopen on %s", local->loc.path); - - local = NULL; - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_OPEN, client3_1_open_cbk, NULL, - xdr_from_open_req, NULL, 0, NULL, 0, NULL); - if (ret) - goto out; - - return ret; - -out: - if (frame) { - frame->local = NULL; - STACK_DESTROY (frame->root); - } - - if (local) - client_local_wipe (local); - - if (path) - GF_FREE (path); - - return 0; - -} - - - -int32_t -client3_1_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; - gfs3_releasedir_req req = {0,}; - int64_t remote_fd = -1; - int ret = 0; - - if (!frame || !this || !data) - goto unwind; - - 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) - list_del_init (&fdctx->sfd_pos); - - fdctx->released = 1; - } - } - pthread_mutex_unlock (&conf->lock); - - if (remote_fd != -1) { - req.fd = remote_fd; - req.gfs_id = GFS3_OP_RELEASEDIR; - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_RELEASEDIR, - client3_1_releasedir_cbk, - NULL, xdr_from_releasedir_req, - NULL, 0, NULL, 0, NULL); - inode_unref (fdctx->inode); - GF_FREE (fdctx); - } - -unwind: - if (ret) - STACK_DESTROY (frame->root); - - return 0; -} - -int32_t -client3_1_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; - gfs3_release_req req = {0,}; - int ret = 0; - - if (!frame || !this || !data) - goto unwind; - - 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) - list_del_init (&fdctx->sfd_pos); - - fdctx->released = 1; - } - } - pthread_mutex_unlock (&conf->lock); - - if (remote_fd != -1) { - req.fd = remote_fd; - req.gfs_id = GFS3_OP_RELEASE; - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_RELEASE, - client3_1_release_cbk, NULL, - xdr_from_release_req, NULL, 0, - NULL, 0, NULL); - inode_unref (fdctx->inode); - GF_FREE (fdctx); - } -unwind: - if (ret) - STACK_DESTROY (frame->root); - - return 0; -} - - -int32_t -client3_1_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; - gfs3_lookup_req req = {0,}; - int ret = 0; - size_t dict_len = 0; - int op_errno = ESTALE; - data_t *content = NULL; - struct iovec vector[MAX_IOVEC]; - 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 = GF_CALLOC (1, sizeof (*local), gf_client_mt_clnt_local_t); - if (!local) { - op_errno = ENOMEM; - goto unwind; - } - - if (!(args->loc && args->loc->inode)) - goto unwind; - - loc_copy (&local->loc, args->loc); - frame->local = local; - - if (args->loc->parent) - memcpy (req.pargfid, args->loc->parent->gfid, 16); - else - memcpy (req.gfid, args->loc->inode->gfid, 16); - - if (args->dict) { - content = dict_get (args->dict, GF_CONTENT_KEY); - if (content != NULL) { - rsp_iobref = iobref_new (); - if (rsp_iobref == NULL) { - gf_log (this->name, GF_LOG_ERROR, - "out of memory"); - goto unwind; - } - - rsp_iobuf = iobuf_get (this->ctx->iobuf_pool); - if (rsp_iobuf == NULL) { - gf_log (this->name, GF_LOG_ERROR, - "out of memory"); - 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 - = rsp_iobuf->iobuf_arena->iobuf_pool->page_size; - count = 1; - rsp_iobuf = NULL; - local->iobref = rsp_iobref; - rsp_iobref = NULL; - } - - ret = dict_allocate_and_serialize (args->dict, - &req.dict.dict_val, - &dict_len); - if (ret < 0) { - gf_log (this->name, GF_LOG_DEBUG, - "failed to get serialized length of dict"); - op_errno = EINVAL; - goto unwind; - } - } - - req.path = (char *)args->loc->path; - req.bname = (char *)args->loc->name; - req.dict.dict_len = dict_len; - req.gfs_id = GFS3_OP_LOOKUP; - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_LOOKUP, client3_1_lookup_cbk, - NULL, xdr_from_lookup_req, rsphdr, count, - NULL, 0, rsp_iobref); - - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - - if (req.dict.dict_val) { - GF_FREE (req.dict.dict_val); - } - - if (rsp_iobref != NULL) { - iobref_unref (rsp_iobref); - } - - return 0; - -unwind: - if (frame) - frame->local = NULL; - - STACK_UNWIND_STRICT (lookup, frame, -1, op_errno, NULL, NULL, NULL, - NULL); - - if (local) - client_local_wipe (local); - - if (req.dict.dict_val) - GF_FREE (req.dict.dict_val); - - if (rsp_iobref != NULL) { - iobref_unref (rsp_iobref); - } - - if (rsp_iobuf != NULL) { - iobuf_unref (rsp_iobuf); - } - - return 0; -} - - - -int32_t -client3_1_stat (call_frame_t *frame, xlator_t *this, - void *data) -{ - clnt_conf_t *conf = NULL; - clnt_args_t *args = NULL; - gfs3_stat_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; - - memcpy (req.gfid, args->loc->inode->gfid, 16); - req.path = (char *)args->loc->path; - req.gfs_id = GFS3_OP_STAT; - conf = this->private; - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_STAT, client3_1_stat_cbk, NULL, - xdr_from_stat_req, NULL, 0, NULL, 0, NULL); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - - return 0; -unwind: - STACK_UNWIND_STRICT (stat, frame, -1, op_errno, NULL); - return 0; -} - - -int32_t -client3_1_truncate (call_frame_t *frame, xlator_t *this, - void *data) -{ - clnt_conf_t *conf = NULL; - clnt_args_t *args = NULL; - gfs3_truncate_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; - - memcpy (req.gfid, args->loc->inode->gfid, 16); - req.path = (char *)args->loc->path; - req.offset = args->offset; - req.gfs_id = GFS3_OP_TRUNCATE; - - conf = this->private; - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_TRUNCATE, - client3_1_truncate_cbk, NULL, - xdr_from_truncate_req, NULL, 0, NULL, 0, - NULL); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - return 0; -unwind: - STACK_UNWIND_STRICT (truncate, frame, -1, op_errno, NULL, NULL); - return 0; -} - - -int32_t -client3_1_ftruncate (call_frame_t *frame, xlator_t *this, - void *data) -{ - clnt_args_t *args = NULL; - clnt_fd_ctx_t *fdctx = NULL; - clnt_conf_t *conf = NULL; - gfs3_ftruncate_req req = {0,}; - int op_errno = EINVAL; - int ret = 0; - - if (!frame || !this || !data) - goto unwind; - - args = data; - - conf = this->private; - - pthread_mutex_lock (&conf->lock); - { - fdctx = this_fd_get_ctx (args->fd, this); - } - pthread_mutex_unlock (&conf->lock); - - if (fdctx == NULL) { - gf_log (this->name, GF_LOG_DEBUG, - "(%"PRId64"): failed to get fd ctx. EBADFD", - args->fd->inode->ino); - op_errno = EBADFD; - goto unwind; - } - - if (fdctx->remote_fd == -1) { - gf_log (this->name, GF_LOG_DEBUG, "(%"PRId64"): failed to get" - " fd ctx. EBADFD", args->fd->inode->ino); - op_errno = EBADFD; - goto unwind; - } - - req.offset = args->offset; - req.fd = fdctx->remote_fd; - req.gfs_id = GFS3_OP_FTRUNCATE; - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_FTRUNCATE, - client3_1_ftruncate_cbk, NULL, - xdr_from_ftruncate_req, NULL, 0, NULL, 0, - NULL); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - return 0; -unwind: - STACK_UNWIND_STRICT (ftruncate, frame, -1, op_errno, NULL, NULL); - return 0; -} - - - -int32_t -client3_1_access (call_frame_t *frame, xlator_t *this, - void *data) -{ - clnt_conf_t *conf = NULL; - clnt_args_t *args = NULL; - gfs3_access_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; - - memcpy (req.gfid, args->loc->inode->gfid, 16); - req.path = (char *)args->loc->path; - req.mask = args->mask; - req.gfs_id = GFS3_OP_ACCESS; - - conf = this->private; - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_ACCESS, - client3_1_access_cbk, NULL, - xdr_from_access_req, NULL, 0, NULL, 0, - NULL); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - - return 0; -unwind: - STACK_UNWIND_STRICT (access, frame, -1, op_errno); - return 0; -} - -int32_t -client3_1_readlink (call_frame_t *frame, xlator_t *this, - void *data) -{ - clnt_conf_t *conf = NULL; - clnt_args_t *args = NULL; - gfs3_readlink_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; - - memcpy (req.gfid, args->loc->inode->gfid, 16); - req.path = (char *)args->loc->path; - req.size = args->size; - req.gfs_id = GFS3_OP_READLINK; - conf = this->private; - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_READLINK, - client3_1_readlink_cbk, NULL, - xdr_from_readlink_req, NULL, 0, NULL, 0, - NULL); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - - return 0; -unwind: - STACK_UNWIND_STRICT (readlink, frame, -1, op_errno, NULL, NULL); - return 0; -} - - - - -int32_t -client3_1_unlink (call_frame_t *frame, xlator_t *this, - void *data) -{ - clnt_conf_t *conf = NULL; - clnt_args_t *args = NULL; - gfs3_unlink_req req = {0,}; - int ret = 0; - int op_errno = 0; - - if (!frame || !this || !data) - goto unwind; - - args = data; - - if (!(args->loc && args->loc->parent)) - goto unwind; - - memcpy (req.pargfid, args->loc->parent->gfid, 16); - req.path = (char *)args->loc->path; - req.bname = (char *)args->loc->name; - req.gfs_id = GFS3_OP_UNLINK; - conf = this->private; - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_UNLINK, - client3_1_unlink_cbk, NULL, - xdr_from_unlink_req, NULL, 0, NULL, 0, - NULL); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - return 0; -unwind: - STACK_UNWIND_STRICT (unlink, frame, -1, op_errno, NULL, NULL); - return 0; -} - - - -int32_t -client3_1_rmdir (call_frame_t *frame, xlator_t *this, - void *data) -{ - clnt_conf_t *conf = NULL; - clnt_args_t *args = NULL; - gfs3_rmdir_req req = {0,}; - int ret = 0; - int op_errno = ESTALE; - - if (!frame || !this || !data) - goto unwind; - - args = data; - - if (!(args->loc && args->loc->parent)) - goto unwind; - - memcpy (req.pargfid, args->loc->parent->gfid, 16); - req.path = (char *)args->loc->path; - req.bname = (char *)args->loc->name; - req.gfs_id = GFS3_OP_RMDIR; - conf = this->private; - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_RMDIR, client3_1_rmdir_cbk, NULL, - xdr_from_rmdir_req, NULL, 0, NULL, 0, - NULL); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - return 0; -unwind: - STACK_UNWIND_STRICT (rmdir, frame, -1, op_errno, NULL, NULL); - return 0; -} - - - -int32_t -client3_1_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; - gfs3_symlink_req req = {0,}; - size_t dict_len = 0; - int ret = 0; - int op_errno = ESTALE; - - if (!frame || !this || !data) - goto unwind; - - args = data; - local = GF_CALLOC (1, sizeof (*local), gf_client_mt_clnt_local_t); - if (!local) { - op_errno = ENOMEM; - goto unwind; - } - - if (!(args->loc && args->loc->parent)) - goto unwind; - - loc_copy (&local->loc, args->loc); - frame->local = local; - - memcpy (req.pargfid, args->loc->parent->gfid, 16); - req.path = (char *)args->loc->path; - req.linkname = (char *)args->linkname; - req.bname = (char *)args->loc->name; - req.gfs_id = GFS3_OP_SYMLINK; - if (args->dict) { - ret = dict_allocate_and_serialize (args->dict, - &req.dict.dict_val, - &dict_len); - if (ret < 0) { - gf_log (this->name, GF_LOG_DEBUG, - "failed to get serialized length of dict"); - op_errno = EINVAL; - goto unwind; - } - } - req.dict.dict_len = dict_len; - - conf = this->private; - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_SYMLINK, client3_1_symlink_cbk, - NULL, xdr_from_symlink_req, NULL, 0, NULL, - 0, NULL); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - if (req.dict.dict_val) { - GF_FREE (req.dict.dict_val); - } - return 0; -unwind: - if (frame) - frame->local = NULL; - - STACK_UNWIND_STRICT (symlink, frame, -1, op_errno, NULL, NULL, NULL, NULL); - - if (local) - client_local_wipe (local); - if (req.dict.dict_val) { - GF_FREE (req.dict.dict_val); - } - return 0; -} - - - -int32_t -client3_1_rename (call_frame_t *frame, xlator_t *this, - void *data) -{ - clnt_conf_t *conf = NULL; - clnt_args_t *args = NULL; - gfs3_rename_req req = {0,}; - int ret = 0; - int op_errno = ESTALE; - - if (!frame || !this || !data) - goto unwind; - - args = data; - - if (!(args->oldloc && args->newloc && args->oldloc->parent && - args->newloc->parent)) - goto unwind; - - memcpy (req.oldgfid, args->oldloc->parent->gfid, 16); - memcpy (req.newgfid, args->newloc->parent->gfid, 16); - - req.oldpath = (char *)args->oldloc->path; - req.oldbname = (char *)args->oldloc->name; - req.newpath = (char *)args->newloc->path; - req.newbname = (char *)args->newloc->name; - req.gfs_id = GFS3_OP_RENAME; - conf = this->private; - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_RENAME, client3_1_rename_cbk, NULL, - xdr_from_rename_req, NULL, 0, NULL, 0, - NULL); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - return 0; -unwind: - STACK_UNWIND_STRICT (rename, frame, -1, op_errno, NULL, NULL, NULL, NULL, NULL); - return 0; -} - - - -int32_t -client3_1_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; - gfs3_link_req req = {0,}; - int ret = 0; - int op_errno = ESTALE; - - if (!frame || !this || !data) - goto unwind; - - args = data; - - if (!(args->oldloc && args->oldloc->inode && args->newloc && - args->newloc->parent)) - goto unwind; - - memcpy (req.oldgfid, args->oldloc->inode->gfid, 16); - memcpy (req.newgfid, args->newloc->parent->gfid, 16); - - local = GF_CALLOC (1, sizeof (*local), gf_client_mt_clnt_local_t); - if (!local) { - op_errno = ENOMEM; - goto unwind; - } - - loc_copy (&local->loc, args->oldloc); - frame->local = local; - - req.oldpath = (char *)args->oldloc->path; - req.newpath = (char *)args->newloc->path; - req.newbname = (char *)args->newloc->name; - req.gfs_id = GFS3_OP_LINK; - conf = this->private; - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_LINK, client3_1_link_cbk, NULL, - xdr_from_link_req, NULL, 0, NULL, 0, NULL); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - return 0; -unwind: - STACK_UNWIND_STRICT (link, frame, -1, op_errno, NULL, NULL, NULL, NULL); - return 0; -} - - - -int32_t -client3_1_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; - gfs3_mknod_req req = {0,}; - size_t dict_len = 0; - int ret = 0; - int op_errno = ESTALE; - - if (!frame || !this || !data) - goto unwind; - - args = data; - - local = GF_CALLOC (1, sizeof (*local), gf_client_mt_clnt_local_t); - if (!local) { - op_errno = ENOMEM; - goto unwind; - } - - if (!(args->loc && args->loc->parent)) - goto unwind; - - loc_copy (&local->loc, args->loc); - frame->local = local; - - memcpy (req.pargfid, args->loc->parent->gfid, 16); - req.path = (char *)args->loc->path; - req.bname = (char *)args->loc->name; - req.mode = args->mode; - req.dev = args->rdev; - req.gfs_id = GFS3_OP_MKNOD; - if (args->dict) { - ret = dict_allocate_and_serialize (args->dict, - &req.dict.dict_val, - &dict_len); - if (ret < 0) { - gf_log (this->name, GF_LOG_DEBUG, - "failed to get serialized length of dict"); - op_errno = EINVAL; - goto unwind; - } - } - req.dict.dict_len = dict_len; - - conf = this->private; - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_MKNOD, client3_1_mknod_cbk, NULL, - xdr_from_mknod_req, NULL, 0, NULL, 0, - NULL); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - if (req.dict.dict_val) { - GF_FREE (req.dict.dict_val); - } - return 0; -unwind: - if (frame) - frame->local = NULL; - - STACK_UNWIND_STRICT (mknod, frame, -1, op_errno, NULL, NULL, NULL, NULL); - - if (local) - client_local_wipe (local); - if (req.dict.dict_val) { - GF_FREE (req.dict.dict_val); - } - return 0; -} - - - -int32_t -client3_1_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; - gfs3_mkdir_req req = {0,}; - size_t dict_len = 0; - int ret = 0; - int op_errno = ESTALE; - - if (!frame || !this || !data) - goto unwind; - - args = data; - - local = GF_CALLOC (1, sizeof (*local), gf_client_mt_clnt_local_t); - if (!local) { - op_errno = ENOMEM; - goto unwind; - } - - if (!(args->loc && args->loc->parent)) - goto unwind; - - loc_copy (&local->loc, args->loc); - frame->local = local; - - memcpy (req.pargfid, args->loc->parent->gfid, 16); - req.path = (char *)args->loc->path; - req.bname = (char *)args->loc->name; - req.mode = args->mode; - req.gfs_id = GFS3_OP_MKDIR; - if (args->dict) { - ret = dict_allocate_and_serialize (args->dict, - &req.dict.dict_val, - &dict_len); - if (ret < 0) { - gf_log (this->name, GF_LOG_DEBUG, - "failed to get serialized length of dict"); - op_errno = EINVAL; - goto unwind; - } - } - req.dict.dict_len = dict_len; - - conf = this->private; - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_MKDIR, client3_1_mkdir_cbk, NULL, - xdr_from_mkdir_req, NULL, 0, NULL, 0, - NULL); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - if (req.dict.dict_val) { - GF_FREE (req.dict.dict_val); - } - return 0; -unwind: - if (frame) - frame->local = NULL; - - STACK_UNWIND_STRICT (mkdir, frame, -1, op_errno, NULL, NULL, NULL, NULL); - - if (local) - client_local_wipe (local); - if (req.dict.dict_val) { - GF_FREE (req.dict.dict_val); - } - return 0; -} - - -int32_t -client3_1_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; - gfs3_create_req req = {0,}; - size_t dict_len = 0; - int ret = 0; - int op_errno = ESTALE; - - if (!frame || !this || !data) - goto unwind; - - args = data; - - local = GF_CALLOC (1, sizeof (*local), gf_client_mt_clnt_local_t); - if (!local) { - op_errno = ENOMEM; - goto unwind; - } - if (!(args->loc && args->loc->parent)) - goto unwind; - - local->fd = fd_ref (args->fd); - local->flags = args->flags; - - loc_copy (&local->loc, args->loc); - frame->local = local; - - memcpy (req.pargfid, args->loc->parent->gfid, 16); - req.path = (char *)args->loc->path; - req.bname = (char *)args->loc->name; - req.mode = args->mode; - req.flags = gf_flags_from_flags (args->flags); - req.gfs_id = GFS3_OP_CREATE; - if (args->dict) { - ret = dict_allocate_and_serialize (args->dict, - &req.dict.dict_val, - &dict_len); - if (ret < 0) { - gf_log (this->name, GF_LOG_DEBUG, - "failed to get serialized length of dict"); - op_errno = EINVAL; - goto unwind; - } - } - req.dict.dict_len = dict_len; - - conf = this->private; - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_CREATE, client3_1_create_cbk, NULL, - xdr_from_create_req, NULL, 0, NULL, 0, - NULL); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - if (req.dict.dict_val) { - GF_FREE (req.dict.dict_val); - } - return 0; -unwind: - if (frame) - frame->local = NULL; - - STACK_UNWIND_STRICT (create, frame, -1, op_errno, NULL, NULL, NULL, - NULL, NULL); - if (local) - client_local_wipe (local); - if (req.dict.dict_val) { - GF_FREE (req.dict.dict_val); - } - return 0; -} - - - -int32_t -client3_1_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; - gfs3_open_req req = {0,}; - int ret = 0; - int op_errno = ESTALE; - - if (!frame || !this || !data) - goto unwind; - - args = data; - - local = GF_CALLOC (1, sizeof (*local), gf_client_mt_clnt_local_t); - if (!local) { - op_errno = ENOMEM; - goto unwind; - } - if (!(args->loc && args->loc->inode)) - goto unwind; - - local->fd = fd_ref (args->fd); - local->flags = args->flags; - local->wbflags = args->wbflags; - loc_copy (&local->loc, args->loc); - frame->local = local; - - memcpy (req.gfid, args->loc->inode->gfid, 16); - req.flags = gf_flags_from_flags (args->flags); - req.wbflags = args->wbflags; - req.path = (char *)args->loc->path; - req.gfs_id = GFS3_OP_OPEN; - - conf = this->private; - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_OPEN, client3_1_open_cbk, NULL, - xdr_from_open_req, NULL, 0, NULL, 0, NULL); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - return 0; -unwind: - if (frame) - frame->local = NULL; - - STACK_UNWIND_STRICT (open, frame, -1, op_errno, NULL); - - if (local) - client_local_wipe (local); - return 0; -} - - - -int32_t -client3_1_readv (call_frame_t *frame, xlator_t *this, - void *data) -{ - clnt_args_t *args = NULL; - clnt_fd_ctx_t *fdctx = NULL; - clnt_conf_t *conf = NULL; - int op_errno = ESTALE; - gfs3_read_req req = {0,}; - int ret = 0; - struct iovec rsp_vec = {0, }; - struct iobuf *rsp_iobuf = NULL; - struct iobref *rsp_iobref = NULL; - clnt_local_t *local = NULL; - - if (!frame || !this || !data) - goto unwind; - - args = data; - conf = this->private; - - pthread_mutex_lock (&conf->lock); - { - fdctx = this_fd_get_ctx (args->fd, this); - } - pthread_mutex_unlock (&conf->lock); - - if (fdctx == NULL) { - gf_log (this->name, GF_LOG_DEBUG, - "(%"PRId64"): failed to get fd ctx. EBADFD", - args->fd->inode->ino); - op_errno = EBADFD; - goto unwind; - } - - if (fdctx->remote_fd == -1) { - gf_log (this->name, GF_LOG_DEBUG, "(%"PRId64"): failed to get" - " fd ctx. EBADFD", args->fd->inode->ino); - op_errno = EBADFD; - goto unwind; - } - - req.size = args->size; - req.offset = args->offset; - req.fd = fdctx->remote_fd; - req.gfs_id = GFS3_OP_READ; - - rsp_iobuf = iobuf_get (this->ctx->iobuf_pool); - if (rsp_iobuf == NULL) { - gf_log (this->name, GF_LOG_ERROR, "out of memory"); - op_errno = ENOMEM; - goto unwind; - } - - rsp_iobref = iobref_new (); - if (rsp_iobref == NULL) { - gf_log (this->name, GF_LOG_ERROR, "out of memory"); - op_errno = ENOMEM; - goto unwind; - } - - iobref_add (rsp_iobref, rsp_iobuf); - iobuf_unref (rsp_iobuf); - rsp_vec.iov_base = iobuf_ptr (rsp_iobuf); - rsp_vec.iov_len = rsp_iobuf->iobuf_arena->iobuf_pool->page_size; - - rsp_iobuf = NULL; - - if (args->size > rsp_vec.iov_len) { - gf_log (this->name, GF_LOG_DEBUG, - "read-size (%lu) is bigger than iobuf size (%lu)", - (unsigned long)args->size, - (unsigned long)rsp_vec.iov_len); - op_errno = EINVAL; - goto unwind; - } - - local = GF_CALLOC (1, sizeof (*local), gf_client_mt_clnt_local_t); - if (local == NULL) { - gf_log (this->name, GF_LOG_ERROR, - "out of memory"); - op_errno = ENOMEM; - goto unwind; - } - - local->iobref = rsp_iobref; - rsp_iobref = NULL; - frame->local = local; - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_READ, client3_1_readv_cbk, NULL, - xdr_from_readv_req, NULL, 0, &rsp_vec, 1, - local->iobref); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - - return 0; -unwind: - if (rsp_iobuf) { - iobuf_unref (rsp_iobuf); - } - - if (rsp_iobref) { - iobref_unref (rsp_iobref); - } - - STACK_UNWIND_STRICT (readv, frame, -1, op_errno, NULL, 0, NULL, NULL); - return 0; -} - - -int32_t -client3_1_writev (call_frame_t *frame, xlator_t *this, void *data) -{ - clnt_args_t *args = NULL; - clnt_fd_ctx_t *fdctx = NULL; - clnt_conf_t *conf = NULL; - gfs3_write_req req = {0,}; - int op_errno = ESTALE; - int ret = 0; - - if (!frame || !this || !data) - goto unwind; - - args = data; - conf = this->private; - - pthread_mutex_lock (&conf->lock); - { - fdctx = this_fd_get_ctx (args->fd, this); - } - pthread_mutex_unlock (&conf->lock); - - if (fdctx == NULL) { - gf_log (this->name, GF_LOG_DEBUG, - "(%"PRId64"): failed to get fd ctx. EBADFD", - args->fd->inode->ino); - op_errno = EBADFD; - goto unwind; - } - - if (fdctx->remote_fd == -1) { - gf_log (this->name, GF_LOG_DEBUG, "(%"PRId64"): failed to get" - " fd ctx. EBADFD", args->fd->inode->ino); - op_errno = EBADFD; - goto unwind; - } - - req.size = args->size; - req.offset = args->offset; - req.fd = fdctx->remote_fd; - req.gfs_id = GFS3_OP_WRITE; - - ret = client_submit_vec_request (this, &req, frame, conf->fops, GFS3_OP_WRITE, - client3_1_writev_cbk, - args->vector, args->count, - args->iobref, xdr_from_writev_req); - if (ret) - goto unwind; - - return 0; -unwind: - STACK_UNWIND_STRICT (writev, frame, -1, op_errno, NULL, NULL); - return 0; -} - - - -int32_t -client3_1_flush (call_frame_t *frame, xlator_t *this, - void *data) -{ - clnt_args_t *args = NULL; - gfs3_flush_req req = {0,}; - clnt_fd_ctx_t *fdctx = NULL; - clnt_conf_t *conf = NULL; - int op_errno = ESTALE; - int ret = 0; - - if (!frame || !this || !data) - goto unwind; - - args = data; - conf = this->private; - - pthread_mutex_lock (&conf->lock); - { - fdctx = this_fd_get_ctx (args->fd, this); - } - pthread_mutex_unlock (&conf->lock); - - if (fdctx == NULL) { - gf_log (this->name, GF_LOG_DEBUG, - "(%"PRId64"): failed to get fd ctx. EBADFD", - args->fd->inode->ino); - op_errno = EBADFD; - goto unwind; - } - - if (fdctx->remote_fd == -1) { - gf_log (this->name, GF_LOG_DEBUG, "(%"PRId64"): failed to get" - " fd ctx. EBADFD", args->fd->inode->ino); - op_errno = EBADFD; - goto unwind; - } - - req.fd = fdctx->remote_fd; - req.gfs_id = GFS3_OP_FLUSH; - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_FLUSH, client3_1_flush_cbk, NULL, - xdr_from_flush_req, NULL, 0, NULL, 0, - NULL); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - return 0; -unwind: - STACK_UNWIND_STRICT (flush, frame, -1, op_errno); - return 0; -} - - - -int32_t -client3_1_fsync (call_frame_t *frame, xlator_t *this, - void *data) -{ - clnt_args_t *args = NULL; - gfs3_fsync_req req = {0,}; - clnt_fd_ctx_t *fdctx = NULL; - clnt_conf_t *conf = NULL; - int op_errno = 0; - int ret = 0; - - if (!frame || !this || !data) - goto unwind; - - args = data; - conf = this->private; - - pthread_mutex_lock (&conf->lock); - { - fdctx = this_fd_get_ctx (args->fd, this); - } - pthread_mutex_unlock (&conf->lock); - - if (fdctx == NULL) { - gf_log (this->name, GF_LOG_DEBUG, - "(%"PRId64"): failed to get fd ctx. EBADFD", - args->fd->inode->ino); - op_errno = EBADFD; - goto unwind; - } - - if (fdctx->remote_fd == -1) { - gf_log (this->name, GF_LOG_DEBUG, "(%"PRId64"): failed to get" - " fd ctx. EBADFD", args->fd->inode->ino); - op_errno = EBADFD; - goto unwind; - } - - req.fd = fdctx->remote_fd; - req.data = args->flags; - req.gfs_id = GFS3_OP_FSYNC; - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_FSYNC, client3_1_fsync_cbk, NULL, - xdr_from_fsync_req, NULL, 0, NULL, 0, - NULL); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - return 0; -unwind: - STACK_UNWIND_STRICT (fsync, frame, -1, op_errno, NULL, NULL); - return 0; -} - - - -int32_t -client3_1_fstat (call_frame_t *frame, xlator_t *this, - void *data) -{ - clnt_args_t *args = NULL; - gfs3_fstat_req req = {0,}; - clnt_fd_ctx_t *fdctx = NULL; - clnt_conf_t *conf = NULL; - int op_errno = ESTALE; - int ret = 0; - - if (!frame || !this || !data) - goto unwind; - - args = data; - conf = this->private; - - pthread_mutex_lock (&conf->lock); - { - fdctx = this_fd_get_ctx (args->fd, this); - } - pthread_mutex_unlock (&conf->lock); - - if (fdctx == NULL) { - gf_log (this->name, GF_LOG_DEBUG, - "(%"PRId64"): failed to get fd ctx. EBADFD", - args->fd->inode->ino); - op_errno = EBADFD; - goto unwind; - } - - if (fdctx->remote_fd == -1) { - gf_log (this->name, GF_LOG_DEBUG, "(%"PRId64"): failed to get" - " fd ctx. EBADFD", args->fd->inode->ino); - op_errno = EBADFD; - goto unwind; - } - - req.fd = fdctx->remote_fd; - req.gfs_id = GFS3_OP_FSTAT; - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_FSTAT, client3_1_fstat_cbk, NULL, - xdr_from_fstat_req, NULL, 0, NULL, 0, - NULL); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - return 0; -unwind: - STACK_UNWIND_STRICT (fstat, frame, -1, op_errno, NULL); - return 0; -} - - - -int32_t -client3_1_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; - gfs3_opendir_req req = {0,}; - int ret = 0; - int op_errno = ESTALE; - - if (!frame || !this || !data) - goto unwind; - - args = data; - - local = GF_CALLOC (1, sizeof (*local), gf_client_mt_clnt_local_t); - if (!local) { - op_errno = ENOMEM; - goto unwind; - } - if (!(args->loc && args->loc->inode)) - goto unwind; - - local->fd = fd_ref (args->fd); - loc_copy (&local->loc, args->loc); - frame->local = local; - - memcpy (req.gfid, args->loc->inode->gfid, 16); - req.path = (char *)args->loc->path; - req.gfs_id = GFS3_OP_OPENDIR; - - conf = this->private; - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_OPENDIR, client3_1_opendir_cbk, - NULL, xdr_from_opendir_req, - NULL, 0, NULL, 0, NULL); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - return 0; -unwind: - if (frame) - frame->local = NULL; - STACK_UNWIND_STRICT (opendir, frame, -1, op_errno, NULL); - if (local) - client_local_wipe (local); - return 0; -} - - - -int32_t -client3_1_fsyncdir (call_frame_t *frame, xlator_t *this, void *data) -{ - clnt_args_t *args = NULL; - clnt_fd_ctx_t *fdctx = NULL; - clnt_conf_t *conf = NULL; - int op_errno = ESTALE; - gfs3_fsyncdir_req req = {0,}; - int ret = 0; - - if (!frame || !this || !data) - goto unwind; - - args = data; - conf = this->private; - - pthread_mutex_lock (&conf->lock); - { - fdctx = this_fd_get_ctx (args->fd, this); - } - pthread_mutex_unlock (&conf->lock); - - if (fdctx == NULL) { - gf_log (this->name, GF_LOG_DEBUG, - "(%"PRId64"): failed to get fd ctx. EBADFD", - args->fd->inode->ino); - op_errno = EBADFD; - goto unwind; - } - - if (fdctx->remote_fd == -1) { - gf_log (this->name, GF_LOG_DEBUG, "(%"PRId64"): failed to get" - " fd ctx. EBADFD", args->fd->inode->ino); - op_errno = EBADFD; - goto unwind; - } - - req.fd = fdctx->remote_fd; - req.data = args->flags; - req.gfs_id = GFS3_OP_FSYNCDIR; - - conf = this->private; - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_FSYNCDIR, client3_1_fsyncdir_cbk, - NULL, xdr_from_fsyncdir_req, NULL, 0, - NULL, 0, NULL); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - return 0; -unwind: - STACK_UNWIND_STRICT (fsyncdir, frame, -1, op_errno); - return 0; -} - - - -int32_t -client3_1_statfs (call_frame_t *frame, xlator_t *this, - void *data) -{ - clnt_conf_t *conf = NULL; - clnt_args_t *args = NULL; - gfs3_statfs_req req = {0,}; - int ret = 0; - int op_errno = ESTALE; - - if (!frame || !this || !data) - goto unwind; - - args = data; - - if (!args->loc) - goto unwind; - - if (args->loc->inode) - memcpy (req.gfid, args->loc->inode->gfid, 16); - else - req.gfid[15] = 1; - - req.path = (char *)args->loc->path; - req.gfs_id = GFS3_OP_STATFS; - - conf = this->private; - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_STATFS, client3_1_statfs_cbk, NULL, - xdr_from_statfs_req, NULL, 0, NULL, 0, - NULL); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - return 0; -unwind: - STACK_UNWIND_STRICT (statfs, frame, -1, op_errno, NULL); - return 0; -} - - - -int32_t -client3_1_setxattr (call_frame_t *frame, xlator_t *this, - void *data) -{ - clnt_conf_t *conf = NULL; - clnt_args_t *args = NULL; - gfs3_setxattr_req req = {0,}; - int ret = 0; - size_t dict_len = 0; - int op_errno = ESTALE; - - if (!frame || !this || !data) - goto unwind; - - args = data; - - if (!(args->loc && args->loc->inode)) - goto unwind; - - memcpy (req.gfid, args->loc->inode->gfid, 16); - if (args->dict) { - ret = dict_allocate_and_serialize (args->dict, - &req.dict.dict_val, - &dict_len); - if (ret < 0) { - gf_log (this->name, GF_LOG_DEBUG, - "failed to get serialized dict"); - op_errno = EINVAL; - goto unwind; - } - req.dict.dict_len = dict_len; - } - req.flags = args->flags; - req.path = (char *)args->loc->path; - req.gfs_id = GFS3_OP_SETXATTR; - - conf = this->private; - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_SETXATTR, client3_1_setxattr_cbk, - NULL, xdr_from_setxattr_req, NULL, 0, - NULL, 0, NULL); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - if (req.dict.dict_val) { - GF_FREE (req.dict.dict_val); - } - - return 0; -unwind: - STACK_UNWIND_STRICT (setxattr, frame, -1, op_errno); - if (req.dict.dict_val) { - GF_FREE (req.dict.dict_val); - } - return 0; -} - - - -int32_t -client3_1_fsetxattr (call_frame_t *frame, xlator_t *this, - void *data) -{ - clnt_args_t *args = NULL; - clnt_fd_ctx_t *fdctx = NULL; - clnt_conf_t *conf = NULL; - gfs3_fsetxattr_req req = {0,}; - int op_errno = ESTALE; - int ret = 0; - size_t dict_len = 0; - - if (!frame || !this || !data) - goto unwind; - - args = data; - conf = this->private; - - pthread_mutex_lock (&conf->lock); - { - fdctx = this_fd_get_ctx (args->fd, this); - } - pthread_mutex_unlock (&conf->lock); - - if (fdctx == NULL) { - gf_log (this->name, GF_LOG_DEBUG, - "(%"PRId64"): failed to get fd ctx. EBADFD", - args->fd->inode->ino); - op_errno = EBADFD; - goto unwind; - } - - if (fdctx->remote_fd == -1) { - gf_log (this->name, GF_LOG_DEBUG, "(%"PRId64"): failed to get" - " fd ctx. EBADFD", args->fd->inode->ino); - op_errno = EBADFD; - goto unwind; - } - - req.fd = fdctx->remote_fd; - req.flags = args->flags; - memcpy (req.gfid, args->fd->inode->gfid, 16); - req.gfs_id = GFS3_OP_FSETXATTR; - - if (args->dict) { - ret = dict_allocate_and_serialize (args->dict, - &req.dict.dict_val, - &dict_len); - if (ret < 0) { - gf_log (this->name, GF_LOG_DEBUG, - "failed to get serialized dict"); - goto unwind; - } - req.dict.dict_len = dict_len; - } - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_FSETXATTR, client3_1_fsetxattr_cbk, - NULL, xdr_from_fsetxattr_req, NULL, 0, - NULL, 0, NULL); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - - if (req.dict.dict_val) { - GF_FREE (req.dict.dict_val); - } - - return 0; -unwind: - STACK_UNWIND_STRICT (fsetxattr, frame, -1, op_errno); - if (req.dict.dict_val) { - GF_FREE (req.dict.dict_val); - } - return 0; -} - - - - -int32_t -client3_1_fgetxattr (call_frame_t *frame, xlator_t *this, - void *data) -{ - clnt_args_t *args = NULL; - clnt_fd_ctx_t *fdctx = NULL; - clnt_conf_t *conf = NULL; - gfs3_fgetxattr_req req = {0,}; - int op_errno = ESTALE; - int ret = 0; - - if (!frame || !this || !data) - goto unwind; - - args = data; - conf = this->private; - - pthread_mutex_lock (&conf->lock); - { - fdctx = this_fd_get_ctx (args->fd, this); - } - pthread_mutex_unlock (&conf->lock); - - if (fdctx == NULL) { - gf_log (this->name, GF_LOG_DEBUG, - "(%"PRId64"): failed to get fd ctx. EBADFD", - args->fd->inode->ino); - op_errno = EBADFD; - goto unwind; - } - - if (fdctx->remote_fd == -1) { - gf_log (this->name, GF_LOG_DEBUG, "(%"PRId64"): failed to get" - " fd ctx. EBADFD", args->fd->inode->ino); - op_errno = EBADFD; - goto unwind; - } - - req.namelen = 1; /* Use it as a flag */ - req.fd = fdctx->remote_fd; - req.name = (char *)args->name; - if (!req.name) { - req.name = ""; - req.namelen = 0; - } - req.gfs_id = GFS3_OP_FGETXATTR; - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_FGETXATTR, - client3_1_fgetxattr_cbk, NULL, - xdr_from_fgetxattr_req, NULL, 0, - NULL, 0, NULL); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - - return 0; -unwind: - STACK_UNWIND_STRICT (fgetxattr, frame, -1, op_errno, NULL); - return 0; -} - - - -int32_t -client3_1_getxattr (call_frame_t *frame, xlator_t *this, - void *data) -{ - clnt_conf_t *conf = NULL; - clnt_args_t *args = NULL; - gfs3_getxattr_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; - - memcpy (req.gfid, args->loc->inode->gfid, 16); - req.namelen = 1; /* Use it as a flag */ - req.path = (char *)args->loc->path; - req.name = (char *)args->name; - if (!req.name) { - req.name = ""; - req.namelen = 0; - } - req.gfs_id = GFS3_OP_GETXATTR; - - conf = this->private; - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_GETXATTR, - client3_1_getxattr_cbk, NULL, - xdr_from_getxattr_req, NULL, 0, - NULL, 0, NULL); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - - return 0; -unwind: - STACK_UNWIND_STRICT (getxattr, frame, -1, op_errno, NULL); - return 0; -} - - - -int32_t -client3_1_xattrop (call_frame_t *frame, xlator_t *this, - void *data) -{ - clnt_conf_t *conf = NULL; - clnt_args_t *args = NULL; - gfs3_xattrop_req req = {0,}; - int ret = 0; - size_t dict_len = 0; - int op_errno = ESTALE; - - if (!frame || !this || !data) - goto unwind; - - args = data; - - if (!(args->loc && args->loc->inode)) - goto unwind; - - memcpy (req.gfid, args->loc->inode->gfid, 16); - if (args->dict) { - ret = dict_allocate_and_serialize (args->dict, - &req.dict.dict_val, - &dict_len); - if (ret < 0) { - gf_log (this->name, GF_LOG_DEBUG, - "failed to get serialized dict"); - op_errno = EINVAL; - goto unwind; - } - req.dict.dict_len = dict_len; - } - req.flags = args->flags; - req.path = (char *)args->loc->path; - req.gfs_id = GFS3_OP_XATTROP; - - conf = this->private; - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_XATTROP, - client3_1_xattrop_cbk, NULL, - xdr_from_xattrop_req, NULL, 0, - NULL, 0, NULL); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - - if (req.dict.dict_val) { - GF_FREE (req.dict.dict_val); - } - return 0; -unwind: - STACK_UNWIND_STRICT (xattrop, frame, -1, op_errno, NULL); - if (req.dict.dict_val) { - GF_FREE (req.dict.dict_val); - } - return 0; -} - - - -int32_t -client3_1_fxattrop (call_frame_t *frame, xlator_t *this, - void *data) -{ - clnt_args_t *args = NULL; - clnt_fd_ctx_t *fdctx = NULL; - clnt_conf_t *conf = NULL; - gfs3_fxattrop_req req = {0,}; - int op_errno = ESTALE; - int ret = 0; - size_t dict_len = 0; - - if (!frame || !this || !data) - goto unwind; - - args = data; - conf = this->private; - - pthread_mutex_lock (&conf->lock); - { - fdctx = this_fd_get_ctx (args->fd, this); - } - pthread_mutex_unlock (&conf->lock); - - if (fdctx == NULL) { - gf_log (this->name, GF_LOG_DEBUG, - "(%"PRId64"): failed to get fd ctx. EBADFD", - args->fd->inode->ino); - op_errno = EBADFD; - goto unwind; - } - - if (fdctx->remote_fd == -1) { - gf_log (this->name, GF_LOG_DEBUG, "(%"PRId64"): failed to get" - " fd ctx. EBADFD", args->fd->inode->ino); - op_errno = EBADFD; - goto unwind; - } - - req.fd = fdctx->remote_fd; - req.flags = args->flags; - memcpy (req.gfid, args->fd->inode->gfid, 16); - req.gfs_id = GFS3_OP_FXATTROP; - - if (args->dict) { - ret = dict_allocate_and_serialize (args->dict, - &req.dict.dict_val, - &dict_len); - if (ret < 0) { - gf_log (this->name, GF_LOG_DEBUG, - "failed to get serialized dict"); - goto unwind; - } - req.dict.dict_len = dict_len; - } - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_FXATTROP, - client3_1_fxattrop_cbk, NULL, - xdr_from_fxattrop_req, NULL, 0, NULL, 0, - NULL); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - - if (req.dict.dict_val) { - GF_FREE (req.dict.dict_val); - } - - return 0; -unwind: - STACK_UNWIND_STRICT (fxattrop, frame, -1, op_errno, NULL); - if (req.dict.dict_val) { - GF_FREE (req.dict.dict_val); - } - return 0; -} - - - -int32_t -client3_1_removexattr (call_frame_t *frame, xlator_t *this, - void *data) -{ - clnt_conf_t *conf = NULL; - clnt_args_t *args = NULL; - gfs3_removexattr_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; - - memcpy (req.gfid, args->loc->inode->gfid, 16); - req.path = (char *)args->loc->path; - req.name = (char *)args->name; - req.gfs_id = GFS3_OP_REMOVEXATTR; - - conf = this->private; - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_REMOVEXATTR, - client3_1_removexattr_cbk, NULL, - xdr_from_removexattr_req, NULL, 0, NULL, - 0, NULL); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - - return 0; -unwind: - STACK_UNWIND_STRICT (removexattr, frame, -1, op_errno); - return 0; -} - - -int32_t -client3_1_lk (call_frame_t *frame, xlator_t *this, - void *data) -{ - clnt_args_t *args = NULL; - gfs3_lk_req req = {0,}; - int32_t gf_cmd = 0; - int32_t gf_type = 0; - clnt_fd_ctx_t *fdctx = NULL; - clnt_conf_t *conf = NULL; - int op_errno = ESTALE; - int ret = 0; - - if (!frame || !this || !data) - goto unwind; - - args = data; - conf = this->private; - - pthread_mutex_lock (&conf->lock); - { - fdctx = this_fd_get_ctx (args->fd, this); - } - pthread_mutex_unlock (&conf->lock); - - if (fdctx == NULL) { - gf_log (this->name, GF_LOG_DEBUG, - "(%"PRId64"): failed to get fd ctx. EBADFD", - args->fd->inode->ino); - op_errno = EBADFD; - goto unwind; - } - - if (fdctx->remote_fd == -1) { - gf_log (this->name, GF_LOG_DEBUG, "(%"PRId64"): failed to get" - " fd ctx. EBADFD", args->fd->inode->ino); - op_errno = EBADFD; - goto unwind; - } - - if (args->cmd == F_GETLK || args->cmd == F_GETLK64) - gf_cmd = GF_LK_GETLK; - else if (args->cmd == F_SETLK || args->cmd == F_SETLK64) - gf_cmd = GF_LK_SETLK; - else if (args->cmd == F_SETLKW || args->cmd == F_SETLKW64) - gf_cmd = GF_LK_SETLKW; - else { - gf_log (this->name, GF_LOG_DEBUG, - "Unknown cmd (%d)!", gf_cmd); - goto unwind; - } - - switch (args->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 = fdctx->remote_fd; - req.cmd = gf_cmd; - req.type = gf_type; - gf_flock_from_flock (&req.flock, args->flock); - req.gfs_id = GFS3_OP_LK; - - ret = client_submit_request (this, &req, frame, conf->fops, GFS3_OP_LK, - client3_1_lk_cbk, NULL, xdr_from_lk_req, - NULL, 0, NULL, 0, NULL); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - - return 0; -unwind: - STACK_UNWIND_STRICT (lk, frame, -1, op_errno, NULL); - return 0; -} - - -int32_t -client3_1_inodelk (call_frame_t *frame, xlator_t *this, - void *data) -{ - clnt_conf_t *conf = NULL; - clnt_args_t *args = NULL; - gfs3_inodelk_req req = {0,}; - int ret = 0; - int32_t gf_cmd = 0; - int32_t gf_type = 0; - int op_errno = ESTALE; - - if (!frame || !this || !data) - goto unwind; - - args = data; - if (!(args->loc && args->loc->inode)) - goto unwind; - - memcpy (req.gfid, args->loc->inode->gfid, 16); - if (args->cmd == F_GETLK || args->cmd == F_GETLK64) - gf_cmd = GF_LK_GETLK; - else if (args->cmd == F_SETLK || args->cmd == F_SETLK64) - gf_cmd = GF_LK_SETLK; - else if (args->cmd == F_SETLKW || args->cmd == F_SETLKW64) - gf_cmd = GF_LK_SETLKW; - else { - gf_log (this->name, GF_LOG_DEBUG, - "Unknown cmd (%d)!", gf_cmd); - op_errno = EINVAL; - goto unwind; - } - - switch (args->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.path = (char *)args->loc->path; - req.volume = (char *)args->volume; - req.cmd = gf_cmd; - req.type = gf_type; - gf_flock_from_flock (&req.flock, args->flock); - req.gfs_id = GFS3_OP_INODELK; - - conf = this->private; - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_INODELK, - client3_1_inodelk_cbk, NULL, - xdr_from_inodelk_req, NULL, 0, NULL, 0, - NULL); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - - return 0; -unwind: - STACK_UNWIND_STRICT (inodelk, frame, -1, op_errno); - return 0; -} - - - -int32_t -client3_1_finodelk (call_frame_t *frame, xlator_t *this, - void *data) -{ - clnt_args_t *args = NULL; - gfs3_finodelk_req req = {0,}; - int32_t gf_cmd = 0; - int32_t gf_type = 0; - clnt_fd_ctx_t *fdctx = NULL; - clnt_conf_t *conf = NULL; - int op_errno = ESTALE; - int ret = 0; - - if (!frame || !this || !data) - goto unwind; - - args = data; - conf = this->private; - - pthread_mutex_lock (&conf->lock); - { - fdctx = this_fd_get_ctx (args->fd, this); - } - pthread_mutex_unlock (&conf->lock); - - if (fdctx == NULL) { - gf_log (this->name, GF_LOG_DEBUG, - "(%"PRId64"): failed to get fd ctx. EBADFD", - args->fd->inode->ino); - op_errno = EBADFD; - goto unwind; - } - - if (fdctx->remote_fd == -1) { - gf_log (this->name, GF_LOG_DEBUG, "(%"PRId64"): failed to get" - " fd ctx. EBADFD", args->fd->inode->ino); - op_errno = EBADFD; - goto unwind; - } - - if (args->cmd == F_GETLK || args->cmd == F_GETLK64) - gf_cmd = GF_LK_GETLK; - else if (args->cmd == F_SETLK || args->cmd == F_SETLK64) - gf_cmd = GF_LK_SETLK; - else if (args->cmd == F_SETLKW || args->cmd == F_SETLKW64) - gf_cmd = GF_LK_SETLKW; - else { - gf_log (this->name, GF_LOG_DEBUG, - "Unknown cmd (%d)!", gf_cmd); - goto unwind; - } - - switch (args->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 *)args->volume; - req.fd = fdctx->remote_fd; - req.cmd = gf_cmd; - req.type = gf_type; - gf_flock_from_flock (&req.flock, args->flock); - req.gfs_id = GFS3_OP_FINODELK; - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_FINODELK, - client3_1_finodelk_cbk, NULL, - xdr_from_finodelk_req, NULL, 0, NULL, 0, - NULL); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - - return 0; -unwind: - STACK_UNWIND_STRICT (finodelk, frame, -1, op_errno); - return 0; -} - - -int32_t -client3_1_entrylk (call_frame_t *frame, xlator_t *this, - void *data) -{ - clnt_conf_t *conf = NULL; - clnt_args_t *args = NULL; - gfs3_entrylk_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; - - memcpy (req.gfid, args->loc->inode->gfid, 16); - req.path = (char *)args->loc->path; - req.cmd = args->cmd_entrylk; - req.type = args->type; - req.volume = (char *)args->volume; - req.name = ""; - if (args->basename) { - req.name = (char *)args->basename; - req.namelen = 1; - } - req.gfs_id = GFS3_OP_ENTRYLK; - - conf = this->private; - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_ENTRYLK, - client3_1_entrylk_cbk, NULL, - xdr_from_entrylk_req, NULL, 0, NULL, 0, - NULL); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - - return 0; -unwind: - STACK_UNWIND_STRICT (entrylk, frame, -1, op_errno); - return 0; -} - - - -int32_t -client3_1_fentrylk (call_frame_t *frame, xlator_t *this, - void *data) -{ - clnt_args_t *args = NULL; - gfs3_fentrylk_req req = {0,}; - clnt_fd_ctx_t *fdctx = NULL; - clnt_conf_t *conf = NULL; - int op_errno = ESTALE; - int ret = 0; - - if (!frame || !this || !data) - goto unwind; - - args = data; - conf = this->private; - - pthread_mutex_lock (&conf->lock); - { - fdctx = this_fd_get_ctx (args->fd, this); - } - pthread_mutex_unlock (&conf->lock); - - if (fdctx == NULL) { - gf_log (this->name, GF_LOG_DEBUG, - "(%"PRId64"): failed to get fd ctx. EBADFD", - args->fd->inode->ino); - op_errno = EBADFD; - goto unwind; - } - - if (fdctx->remote_fd == -1) { - gf_log (this->name, GF_LOG_DEBUG, "(%"PRId64"): failed to get" - " fd ctx. EBADFD", args->fd->inode->ino); - op_errno = EBADFD; - goto unwind; - } - - req.fd = fdctx->remote_fd; - req.cmd = args->cmd_entrylk; - req.type = args->type; - req.volume = (char *)args->volume; - req.name = ""; - if (args->basename) { - req.name = (char *)args->basename; - req.namelen = 1; - } - req.gfs_id = GFS3_OP_FENTRYLK; - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_FENTRYLK, - client3_1_fentrylk_cbk, NULL, - xdr_from_fentrylk_req, NULL, 0, NULL, 0, - NULL); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - - return 0; -unwind: - STACK_UNWIND_STRICT (fentrylk, frame, -1, op_errno); - return 0; -} - - -int32_t -client3_1_rchecksum (call_frame_t *frame, xlator_t *this, - void *data) -{ - clnt_args_t *args = NULL; - clnt_fd_ctx_t *fdctx = NULL; - clnt_conf_t *conf = NULL; - gfs3_rchecksum_req req = {0,}; - int op_errno = ESTALE; - int ret = 0; - - if (!frame || !this || !data) - goto unwind; - - args = data; - conf = this->private; - - pthread_mutex_lock (&conf->lock); - { - fdctx = this_fd_get_ctx (args->fd, this); - } - pthread_mutex_unlock (&conf->lock); - - if (fdctx == NULL) { - gf_log (this->name, GF_LOG_DEBUG, - "(%"PRId64"): failed to get fd ctx. EBADFD", - args->fd->inode->ino); - op_errno = EBADFD; - goto unwind; - } - - if (fdctx->remote_fd == -1) { - gf_log (this->name, GF_LOG_DEBUG, "(%"PRId64"): failed to get" - " fd ctx. EBADFD", args->fd->inode->ino); - op_errno = EBADFD; - goto unwind; - } - - req.len = args->len; - req.offset = args->offset; - req.fd = fdctx->remote_fd; - req.gfs_id = GFS3_OP_RCHECKSUM; - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_RCHECKSUM, - client3_1_rchecksum_cbk, NULL, - xdr_from_rchecksum_req, NULL, 0, NULL, - 0, NULL); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - - return 0; -unwind: - STACK_UNWIND_STRICT (rchecksum, frame, -1, op_errno, 0, NULL); - return 0; -} - - - -int32_t -client3_1_readdir (call_frame_t *frame, xlator_t *this, - void *data) -{ - clnt_args_t *args = NULL; - clnt_fd_ctx_t *fdctx = NULL; - clnt_conf_t *conf = NULL; - gfs3_readdir_req req = {0,}; - int op_errno = ESTALE; - int ret = 0; - - if (!frame || !this || !data) - goto unwind; - - args = data; - conf = this->private; - - pthread_mutex_lock (&conf->lock); - { - fdctx = this_fd_get_ctx (args->fd, this); - } - pthread_mutex_unlock (&conf->lock); - - if (fdctx == NULL) { - gf_log (this->name, GF_LOG_DEBUG, - "(%"PRId64"): failed to get fd ctx. EBADFD", - args->fd->inode->ino); - op_errno = EBADFD; - goto unwind; - } - - if (fdctx->remote_fd == -1) { - gf_log (this->name, GF_LOG_DEBUG, "(%"PRId64"): failed to get" - " fd ctx. EBADFD", args->fd->inode->ino); - op_errno = EBADFD; - goto unwind; - } - - req.size = args->size; - req.offset = args->offset; - req.fd = fdctx->remote_fd; - req.gfs_id = GFS3_OP_READDIR; - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_READDIR, - client3_1_readdir_cbk, NULL, - xdr_from_readdir_req, NULL, 0, NULL, 0, - NULL); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - - return 0; -unwind: - STACK_UNWIND_STRICT (readdir, frame, -1, op_errno, NULL); - return 0; -} - - -int32_t -client3_1_readdirp (call_frame_t *frame, xlator_t *this, - void *data) -{ - clnt_args_t *args = NULL; - gfs3_readdirp_req req = {0,}; - clnt_fd_ctx_t *fdctx = NULL; - clnt_conf_t *conf = NULL; - int op_errno = ESTALE; - int ret = 0; - - if (!frame || !this || !data) - goto unwind; - - args = data; - conf = this->private; - - pthread_mutex_lock (&conf->lock); - { - fdctx = this_fd_get_ctx (args->fd, this); - } - pthread_mutex_unlock (&conf->lock); - - if (fdctx == NULL) { - gf_log (this->name, GF_LOG_DEBUG, - "(%"PRId64"): failed to get fd ctx. EBADFD", - args->fd->inode->ino); - op_errno = EBADFD; - goto unwind; - } - - if (fdctx->remote_fd == -1) { - gf_log (this->name, GF_LOG_DEBUG, "(%"PRId64"): failed to get" - " fd ctx. EBADFD", args->fd->inode->ino); - op_errno = EBADFD; - goto unwind; - } - - req.size = args->size; - req.offset = args->offset; - req.fd = fdctx->remote_fd; - req.gfs_id = GFS3_OP_READDIRP; - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_READDIRP, - client3_1_readdirp_cbk, NULL, - xdr_from_readdirp_req, NULL, 0, NULL, 0, - NULL); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - - return 0; -unwind: - STACK_UNWIND_STRICT (readdirp, frame, -1, op_errno, NULL); - return 0; -} - - -int32_t -client3_1_setattr (call_frame_t *frame, xlator_t *this, - void *data) -{ - clnt_conf_t *conf = NULL; - clnt_args_t *args = NULL; - gfs3_setattr_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; - - memcpy (req.gfid, args->loc->inode->gfid, 16); - req.path = (char *)args->loc->path; - req.valid = args->valid; - gf_stat_from_iatt (&req.stbuf, args->stbuf); - req.gfs_id = GFS3_OP_SETATTR; - - conf = this->private; - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_SETATTR, - client3_1_setattr_cbk, NULL, - xdr_from_setattr_req, NULL, 0, NULL, 0, - NULL); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - - return 0; -unwind: - STACK_UNWIND_STRICT (setattr, frame, -1, op_errno, NULL, NULL); - return 0; -} - -int32_t -client3_1_fsetattr (call_frame_t *frame, xlator_t *this, void *data) -{ - clnt_args_t *args = NULL; - clnt_fd_ctx_t *fdctx = NULL; - clnt_conf_t *conf = NULL; - gfs3_fsetattr_req req = {0,}; - int op_errno = ESTALE; - int ret = 0; - - if (!frame || !this || !data) - goto unwind; - - args = data; - conf = this->private; - - pthread_mutex_lock (&conf->lock); - { - fdctx = this_fd_get_ctx (args->fd, this); - } - pthread_mutex_unlock (&conf->lock); - - if (fdctx == NULL) { - gf_log (this->name, GF_LOG_DEBUG, - "(%"PRId64"): failed to get fd ctx. EBADFD", - args->fd->inode->ino); - op_errno = EBADFD; - goto unwind; - } - - if (fdctx->remote_fd == -1) { - gf_log (this->name, GF_LOG_DEBUG, "(%"PRId64"): failed to get" - " fd ctx. EBADFD", args->fd->inode->ino); - op_errno = EBADFD; - goto unwind; - } - - req.fd = fdctx->remote_fd; - req.valid = args->valid; - gf_stat_from_iatt (&req.stbuf, args->stbuf); - req.gfs_id = GFS3_OP_FSETATTR; - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_FSETATTR, - client3_1_fsetattr_cbk, NULL, - xdr_from_fsetattr_req, NULL, 0, NULL, 0, - NULL); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - - return 0; -unwind: - STACK_UNWIND_STRICT (fsetattr, frame, -1, op_errno, NULL, NULL); - return 0; -} - - - -/* Table Specific to FOPS */ - - -rpc_clnt_procedure_t clnt3_1_fop_actors[GF_FOP_MAXVALUE] = { - [GF_FOP_NULL] = { "NULL", NULL}, - [GF_FOP_STAT] = { "STAT", client3_1_stat }, - [GF_FOP_READLINK] = { "READLINK", client3_1_readlink }, - [GF_FOP_MKNOD] = { "MKNOD", client3_1_mknod }, - [GF_FOP_MKDIR] = { "MKDIR", client3_1_mkdir }, - [GF_FOP_UNLINK] = { "UNLINK", client3_1_unlink }, - [GF_FOP_RMDIR] = { "RMDIR", client3_1_rmdir }, - [GF_FOP_SYMLINK] = { "SYMLINK", client3_1_symlink }, - [GF_FOP_RENAME] = { "RENAME", client3_1_rename }, - [GF_FOP_LINK] = { "LINK", client3_1_link }, - [GF_FOP_TRUNCATE] = { "TRUNCATE", client3_1_truncate }, - [GF_FOP_OPEN] = { "OPEN", client3_1_open }, - [GF_FOP_READ] = { "READ", client3_1_readv }, - [GF_FOP_WRITE] = { "WRITE", client3_1_writev }, - [GF_FOP_STATFS] = { "STATFS", client3_1_statfs }, - [GF_FOP_FLUSH] = { "FLUSH", client3_1_flush }, - [GF_FOP_FSYNC] = { "FSYNC", client3_1_fsync }, - [GF_FOP_SETXATTR] = { "SETXATTR", client3_1_setxattr }, - [GF_FOP_GETXATTR] = { "GETXATTR", client3_1_getxattr }, - [GF_FOP_REMOVEXATTR] = { "REMOVEXATTR", client3_1_removexattr }, - [GF_FOP_OPENDIR] = { "OPENDIR", client3_1_opendir }, - [GF_FOP_FSYNCDIR] = { "FSYNCDIR", client3_1_fsyncdir }, - [GF_FOP_ACCESS] = { "ACCESS", client3_1_access }, - [GF_FOP_CREATE] = { "CREATE", client3_1_create }, - [GF_FOP_FTRUNCATE] = { "FTRUNCATE", client3_1_ftruncate }, - [GF_FOP_FSTAT] = { "FSTAT", client3_1_fstat }, - [GF_FOP_LK] = { "LK", client3_1_lk }, - [GF_FOP_LOOKUP] = { "LOOKUP", client3_1_lookup }, - [GF_FOP_READDIR] = { "READDIR", client3_1_readdir }, - [GF_FOP_INODELK] = { "INODELK", client3_1_inodelk }, - [GF_FOP_FINODELK] = { "FINODELK", client3_1_finodelk }, - [GF_FOP_ENTRYLK] = { "ENTRYLK", client3_1_entrylk }, - [GF_FOP_FENTRYLK] = { "FENTRYLK", client3_1_fentrylk }, - [GF_FOP_XATTROP] = { "XATTROP", client3_1_xattrop }, - [GF_FOP_FXATTROP] = { "FXATTROP", client3_1_fxattrop }, - [GF_FOP_FGETXATTR] = { "FGETXATTR", client3_1_fgetxattr }, - [GF_FOP_FSETXATTR] = { "FSETXATTR", client3_1_fsetxattr }, - [GF_FOP_RCHECKSUM] = { "RCHECKSUM", client3_1_rchecksum }, - [GF_FOP_SETATTR] = { "SETATTR", client3_1_setattr }, - [GF_FOP_FSETATTR] = { "FSETATTR", client3_1_fsetattr }, - [GF_FOP_READDIRP] = { "READDIRP", client3_1_readdirp }, - [GF_FOP_RELEASE] = { "RELEASE", client3_1_release }, - [GF_FOP_RELEASEDIR] = { "RELEASEDIR", client3_1_releasedir }, - [GF_FOP_GETSPEC] = { "GETSPEC", client3_getspec }, -}; - -/* Used From RPC-CLNT library to log proper name of procedure based on number */ -char *clnt3_1_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", -}; - -rpc_clnt_prog_t clnt3_1_fop_prog = { - .progname = "GlusterFS 3.1", - .prognum = GLUSTER3_1_FOP_PROGRAM, - .progver = GLUSTER3_1_FOP_VERSION, - .numproc = GLUSTER3_1_FOP_PROCCNT, - .proctable = clnt3_1_fop_actors, - .procnames = clnt3_1_fop_names, -}; - - diff --git a/xlators/protocol/legacy/Makefile.am b/xlators/protocol/legacy/Makefile.am deleted file mode 100644 index 9914863021c..00000000000 --- a/xlators/protocol/legacy/Makefile.am +++ /dev/null @@ -1,3 +0,0 @@ -SUBDIRS = lib transport client server - -CLEANFILES = diff --git a/xlators/protocol/legacy/client/Makefile.am b/xlators/protocol/legacy/client/Makefile.am deleted file mode 100644 index d471a3f9243..00000000000 --- a/xlators/protocol/legacy/client/Makefile.am +++ /dev/null @@ -1,3 +0,0 @@ -SUBDIRS = src - -CLEANFILES = diff --git a/xlators/protocol/legacy/client/src/Makefile.am b/xlators/protocol/legacy/client/src/Makefile.am deleted file mode 100644 index 2ae64ebd0fd..00000000000 --- a/xlators/protocol/legacy/client/src/Makefile.am +++ /dev/null @@ -1,21 +0,0 @@ - -xlator_LTLIBRARIES = client-old.la -xlatordir = $(libdir)/glusterfs/$(PACKAGE_VERSION)/xlator/legacy/protocol - -client_old_la_LDFLAGS = -module -avoidversion - -client_old_la_SOURCES = client-protocol.c saved-frames.c - -client_old_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la \ - $(top_builddir)/xlators/protocol/legacy/lib/src/libgfproto.la - -noinst_HEADERS = client-protocol.h saved-frames.h client-mem-types.h - -AM_CFLAGS = -fPIC -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -Wall -D$(GF_HOST_OS) \ - -I$(top_srcdir)/libglusterfs/src -shared -nostartfiles $(GF_CFLAGS) \ - -I$(top_srcdir)/xlators/protocol/legacy/lib/src - -CLEANFILES = - -install-data-hook: - ln -sf client-old.so $(DESTDIR)$(xlatordir)/client.so diff --git a/xlators/protocol/legacy/client/src/client-mem-types.h b/xlators/protocol/legacy/client/src/client-mem-types.h deleted file mode 100644 index 1eee8d93159..00000000000 --- a/xlators/protocol/legacy/client/src/client-mem-types.h +++ /dev/null @@ -1,43 +0,0 @@ - -/* - Copyright (c) 2008-2009 Gluster, Inc. <http://www.gluster.com> - This file is part of GlusterFS. - - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. -*/ - - -#ifndef __CLIENT_MEM_TYPES_H__ -#define __CLIENT_MEM_TYPES_H__ - -#include "mem-types.h" - -enum gf_client_mem_types_ { - gf_client_mt_dir_entry_t = gf_common_mt_end + 1, - gf_client_mt_volfile_ctx, - gf_client_mt_client_state_t, - gf_client_mt_client_conf_t, - gf_client_mt_locker, - gf_client_mt_lock_table, - gf_client_mt_char, - gf_client_mt_client_connection_t, - gf_client_mt_client_fd_ctx_t, - gf_client_mt_client_local_t, - gf_client_mt_saved_frames, - gf_client_mt_saved_frame, - gf_client_mt_end -}; -#endif - diff --git a/xlators/protocol/legacy/client/src/client-protocol.c b/xlators/protocol/legacy/client/src/client-protocol.c deleted file mode 100644 index 57cfbc73e33..00000000000 --- a/xlators/protocol/legacy/client/src/client-protocol.c +++ /dev/null @@ -1,6673 +0,0 @@ -/* - Copyright (c) 2006-2009 Gluster, Inc. <http://www.gluster.com> - This file is part of GlusterFS. - - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. -*/ - -#ifndef _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif -#include <inttypes.h> - - -#include "glusterfs.h" -#include "client-protocol.h" -#include "compat.h" -#include "dict.h" -#include "protocol.h" -#include "transport.h" -#include "xlator.h" -#include "logging.h" -#include "timer.h" -#include "defaults.h" -#include "compat.h" -#include "compat-errno.h" -#include "statedump.h" -#include "client-mem-types.h" - -#include <sys/resource.h> -#include <inttypes.h> - -/* for default_*_cbk functions */ -#include "defaults.c" -#include "saved-frames.h" -#include "common-utils.h" - -int protocol_client_cleanup (transport_t *trans); -int protocol_client_interpret (xlator_t *this, transport_t *trans, - char *hdr_p, size_t hdrlen, - struct iobuf *iobuf); -int -protocol_client_xfer (call_frame_t *frame, xlator_t *this, transport_t *trans, - int type, int op, - gf_hdr_common_t *hdr, size_t hdrlen, - struct iovec *vector, int count, - struct iobref *iobref); - -int -protocol_client_post_handshake (call_frame_t *frame, xlator_t *this); - -static gf_op_t gf_fops[GF_PROTO_FOP_MAXVALUE]; -static gf_op_t gf_mops[GF_MOP_MAXVALUE]; -static gf_op_t gf_cbks[GF_CBK_MAXVALUE]; - - -transport_t * -client_channel (xlator_t *this, int id) -{ - transport_t *trans = NULL; - client_conf_t *conf = NULL; - int i = 0; - struct client_connection *conn = NULL; - - conf = this->private; - - trans = conf->transport[id]; - conn = trans->xl_private; - - if (conn->connected == 1) - goto ret; - - for (i = 0; i < CHANNEL_MAX; i++) { - trans = conf->transport[i]; - conn = trans->xl_private; - if (conn->connected == 1) - break; - } - -ret: - return trans; -} - - -client_fd_ctx_t * -this_fd_del_ctx (fd_t *file, xlator_t *this) -{ - int dict_ret = -1; - uint64_t ctxaddr = 0; - - GF_VALIDATE_OR_GOTO ("client", this, out); - GF_VALIDATE_OR_GOTO (this->name, file, out); - - dict_ret = fd_ctx_del (file, this, &ctxaddr); - - if (dict_ret < 0) { - ctxaddr = 0; - } - -out: - return (client_fd_ctx_t *)(unsigned long)ctxaddr; -} - - -client_fd_ctx_t * -this_fd_get_ctx (fd_t *file, xlator_t *this) -{ - int dict_ret = -1; - uint64_t ctxaddr = 0; - - GF_VALIDATE_OR_GOTO ("client", this, out); - GF_VALIDATE_OR_GOTO (this->name, file, out); - - dict_ret = fd_ctx_get (file, this, &ctxaddr); - - if (dict_ret < 0) { - ctxaddr = 0; - } - -out: - return (client_fd_ctx_t *)(unsigned long)ctxaddr; -} - - -static void -this_fd_set_ctx (fd_t *file, xlator_t *this, loc_t *loc, client_fd_ctx_t *ctx) -{ - uint64_t oldaddr = 0; - int32_t ret = -1; - - GF_VALIDATE_OR_GOTO ("client", this, out); - GF_VALIDATE_OR_GOTO (this->name, file, out); - - ret = fd_ctx_get (file, this, &oldaddr); - if (ret >= 0) { - gf_log (this->name, GF_LOG_DEBUG, - "%s (%"PRId64"): trying duplicate remote fd set. ", - loc->path, loc->inode->ino); - } - - ret = fd_ctx_set (file, this, (uint64_t)(unsigned long)ctx); - if (ret < 0) { - gf_log (this->name, GF_LOG_DEBUG, - "%s (%"PRId64"): failed to set remote fd", - loc->path, loc->inode->ino); - } -out: - return; -} - - -static int -client_local_wipe (client_local_t *local) -{ - if (local) { - loc_wipe (&local->loc); - - if (local->fd) - fd_unref (local->fd); - - GF_FREE (local); - } - - return 0; -} - -/* - * lookup_frame - lookup call frame corresponding to a given callid - * @trans: transport object - * @callid: call id of the frame - * - * not for external reference - */ - -static call_frame_t * -lookup_frame (transport_t *trans, int32_t op, int8_t type, int64_t callid) -{ - client_connection_t *conn = NULL; - call_frame_t *frame = NULL; - - conn = trans->xl_private; - - pthread_mutex_lock (&conn->lock); - { - frame = saved_frames_get (conn->saved_frames, - op, type, callid); - } - pthread_mutex_unlock (&conn->lock); - - return frame; -} - - -static void -call_bail (void *data) -{ - client_connection_t *conn = NULL; - struct timeval current; - transport_t *trans = NULL; - struct list_head list; - struct saved_frame *saved_frame = NULL; - struct saved_frame *trav = NULL; - struct saved_frame *tmp = NULL; - call_frame_t *frame = NULL; - gf_hdr_common_t hdr = {0, }; - char **gf_op_list = NULL; - gf_op_t *gf_ops = NULL; - struct tm frame_sent_tm; - char frame_sent[32] = {0,}; - struct timeval timeout = {0,}; - gf_timer_cbk_t timer_cbk = NULL; - - GF_VALIDATE_OR_GOTO ("client", data, out); - trans = data; - - conn = trans->xl_private; - - gettimeofday (¤t, NULL); - INIT_LIST_HEAD (&list); - - pthread_mutex_lock (&conn->lock); - { - /* Chaining to get call-always functionality from - call-once timer */ - if (conn->timer) { - timer_cbk = conn->timer->callbk; - - timeout.tv_sec = 10; - timeout.tv_usec = 0; - - gf_timer_call_cancel (trans->xl->ctx, conn->timer); - conn->timer = gf_timer_call_after (trans->xl->ctx, - timeout, - timer_cbk, - trans); - if (conn->timer == NULL) { - gf_log (trans->xl->name, GF_LOG_DEBUG, - "Cannot create bailout timer"); - } - } - - do { - saved_frame = - saved_frames_get_timedout (conn->saved_frames, - GF_OP_TYPE_MOP_REQUEST, - conn->frame_timeout, - ¤t); - if (saved_frame) - list_add (&saved_frame->list, &list); - - } while (saved_frame); - - do { - saved_frame = - saved_frames_get_timedout (conn->saved_frames, - GF_OP_TYPE_FOP_REQUEST, - conn->frame_timeout, - ¤t); - if (saved_frame) - list_add (&saved_frame->list, &list); - } while (saved_frame); - - do { - saved_frame = - saved_frames_get_timedout (conn->saved_frames, - GF_OP_TYPE_CBK_REQUEST, - conn->frame_timeout, - ¤t); - if (saved_frame) - list_add (&saved_frame->list, &list); - } while (saved_frame); - } - pthread_mutex_unlock (&conn->lock); - - hdr.rsp.op_ret = hton32 (-1); - hdr.rsp.op_errno = hton32 (ENOTCONN); - - list_for_each_entry_safe (trav, tmp, &list, list) { - switch (trav->type) - { - case GF_OP_TYPE_FOP_REQUEST: - gf_ops = gf_fops; - gf_op_list = gf_fop_list; - break; - case GF_OP_TYPE_MOP_REQUEST: - gf_ops = gf_mops; - gf_op_list = gf_mop_list; - break; - case GF_OP_TYPE_CBK_REQUEST: - gf_ops = gf_cbks; - gf_op_list = gf_cbk_list; - break; - default: - goto out; - } - - localtime_r (&trav->saved_at.tv_sec, &frame_sent_tm); - strftime (frame_sent, 32, "%Y-%m-%d %H:%M:%S", &frame_sent_tm); - - gf_log (trans->xl->name, GF_LOG_ERROR, - "bailing out frame %s(%d) " - "frame sent = %s. frame-timeout = %d", - gf_op_list[trav->op], trav->op, - frame_sent, conn->frame_timeout); - - hdr.type = hton32 (trav->type); - hdr.op = hton32 (trav->op); - - frame = trav->frame; - - gf_ops[trav->op] (frame, &hdr, sizeof (hdr), NULL); - - list_del_init (&trav->list); - GF_FREE (trav); - } -out: - return; -} - - -void -save_frame (transport_t *trans, call_frame_t *frame, - int32_t op, int8_t type, uint64_t callid) -{ - client_connection_t *conn = NULL; - struct timeval timeout = {0, }; - - - conn = trans->xl_private; - - saved_frames_put (conn->saved_frames, frame, op, type, callid); - - if (conn->timer == NULL && conn->frame_timeout) { - timeout.tv_sec = 10; - timeout.tv_usec = 0; - conn->timer = gf_timer_call_after (trans->xl->ctx, timeout, - call_bail, (void *) trans); - } -} - - - -void -client_ping_timer_expired (void *data) -{ - xlator_t *this = NULL; - transport_t *trans = NULL; - client_conf_t *conf = NULL; - client_connection_t *conn = NULL; - int disconnect = 0; - int transport_activity = 0; - struct timeval timeout = {0, }; - struct timeval current = {0, }; - - trans = data; - this = trans->xl; - conf = this->private; - conn = trans->xl_private; - - pthread_mutex_lock (&conn->lock); - { - if (conn->ping_timer) - gf_timer_call_cancel (trans->xl->ctx, - conn->ping_timer); - gettimeofday (¤t, NULL); - - pthread_mutex_lock (&conf->mutex); - { - if (((current.tv_sec - conf->last_received.tv_sec) < - conn->ping_timeout) - || ((current.tv_sec - conf->last_sent.tv_sec) < - conn->ping_timeout)) { - transport_activity = 1; - } - } - pthread_mutex_unlock (&conf->mutex); - - if (transport_activity) { - gf_log (this->name, GF_LOG_TRACE, - "ping timer expired but transport activity " - "detected - not bailing transport"); - conn->transport_activity = 0; - timeout.tv_sec = conn->ping_timeout; - timeout.tv_usec = 0; - - conn->ping_timer = - gf_timer_call_after (trans->xl->ctx, timeout, - client_ping_timer_expired, - (void *) trans); - if (conn->ping_timer == NULL) - gf_log (this->name, GF_LOG_DEBUG, - "unable to setup timer"); - - } else { - conn->ping_started = 0; - conn->ping_timer = NULL; - disconnect = 1; - } - } - pthread_mutex_unlock (&conn->lock); - if (disconnect) { - gf_log (this->name, GF_LOG_ERROR, - "Server %s has not responded in the last %d " - "seconds, disconnecting.", - conf->transport[0]->peerinfo.identifier, - conn->ping_timeout); - - transport_disconnect (conf->transport[0]); - transport_disconnect (conf->transport[1]); - } -} - - -void -client_start_ping (void *data) -{ - xlator_t *this = NULL; - transport_t *trans = NULL; - client_conf_t *conf = NULL; - client_connection_t *conn = NULL; - int32_t ret = -1; - gf_hdr_common_t *hdr = NULL; - struct timeval timeout = {0, }; - call_frame_t *dummy_frame = NULL; - size_t hdrlen = -1; - gf_mop_ping_req_t *req = NULL; - int frame_count = 0; - - - trans = data; - this = trans->xl; - conf = this->private; - conn = trans->xl_private; - - if (!conn->ping_timeout) - return; - - pthread_mutex_lock (&conn->lock); - { - if (conn->ping_timer) - gf_timer_call_cancel (trans->xl->ctx, conn->ping_timer); - - conn->ping_timer = NULL; - conn->ping_started = 0; - - if (conn->saved_frames) - /* treat the case where conn->saved_frames is NULL - as no pending frames */ - frame_count = conn->saved_frames->count; - - if ((frame_count == 0) || !conn->connected) { - /* using goto looked ugly here, - * hence getting out this way */ - /* unlock */ - pthread_mutex_unlock (&conn->lock); - return; - } - - if (frame_count < 0) { - gf_log (this->name, GF_LOG_DEBUG, - "saved_frames->count is %"PRId64, - conn->saved_frames->count); - conn->saved_frames->count = 0; - } - - timeout.tv_sec = conn->ping_timeout; - timeout.tv_usec = 0; - - conn->ping_timer = - gf_timer_call_after (trans->xl->ctx, timeout, - client_ping_timer_expired, - (void *) trans); - - if (conn->ping_timer == NULL) { - gf_log (this->name, GF_LOG_DEBUG, - "unable to setup timer"); - } else { - conn->ping_started = 1; - } - } - pthread_mutex_unlock (&conn->lock); - - hdrlen = gf_hdr_len (req, 0); - hdr = gf_hdr_new (req, 0); - if (!hdr) - goto err; - - dummy_frame = create_frame (this, this->ctx->pool); - - if (!dummy_frame) - goto err; - - dummy_frame->local = trans; - - ret = protocol_client_xfer (dummy_frame, this, trans, - GF_OP_TYPE_MOP_REQUEST, GF_MOP_PING, - hdr, hdrlen, NULL, 0, NULL); - return; -err: - if (hdr) - GF_FREE (hdr); - - if (dummy_frame) - STACK_DESTROY (dummy_frame->root); - - return; -} - - -int -client_ping_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - xlator_t *this = NULL; - transport_t *trans = NULL; - client_connection_t *conn = NULL; - struct timeval timeout = {0, }; - int op_ret = 0; - - trans = frame->local; frame->local = NULL; - this = trans->xl; - conn = trans->xl_private; - - op_ret = ntoh32 (hdr->rsp.op_ret); - - if (op_ret == -1) { - /* timer expired and transport bailed out */ - gf_log (this->name, GF_LOG_DEBUG, "timer must have expired"); - goto out; - } - - pthread_mutex_lock (&conn->lock); - { - timeout.tv_sec = conn->ping_timeout; - timeout.tv_usec = 0; - - gf_timer_call_cancel (trans->xl->ctx, - conn->ping_timer); - - conn->ping_timer = - gf_timer_call_after (trans->xl->ctx, timeout, - client_start_ping, (void *)trans); - if (conn->ping_timer == NULL) - gf_log (this->name, GF_LOG_DEBUG, - "gf_timer_call_after() returned NULL"); - } - pthread_mutex_unlock (&conn->lock); -out: - STACK_DESTROY (frame->root); - return 0; -} - -int -client_encode_groups (call_frame_t *frame, gf_hdr_common_t *hdr) -{ - int i = 0; - if ((!frame) || (!hdr)) - return -1; - - hdr->req.ngrps = hton32 (frame->root->ngrps); - if (frame->root->ngrps == 0) - return 0; - - for (; i < frame->root->ngrps; ++i) - hdr->req.groups[i] = hton32 (frame->root->groups[i]); - - return 0; -} - - -int -protocol_client_xfer (call_frame_t *frame, xlator_t *this, transport_t *trans, - int type, int op, - gf_hdr_common_t *hdr, size_t hdrlen, - struct iovec *vector, int count, - struct iobref *iobref) -{ - client_conf_t *conf = NULL; - client_connection_t *conn = NULL; - uint64_t callid = 0; - int32_t ret = -1; - int start_ping = 0; - gf_hdr_common_t rsphdr = {0, }; - - conf = this->private; - - if (!trans) { - /* default to bulk op since it is 'safer' */ - trans = conf->transport[CHANNEL_BULK]; - } - conn = trans->xl_private; - - pthread_mutex_lock (&conn->lock); - { - callid = ++conn->callid; - - hdr->callid = hton64 (callid); - hdr->op = hton32 (op); - hdr->type = hton32 (type); - - if (frame) { - hdr->req.uid = hton32 (frame->root->uid); - hdr->req.gid = hton32 (frame->root->gid); - hdr->req.pid = hton32 (frame->root->pid); - hdr->req.lk_owner = hton64 (frame->root->lk_owner); - client_encode_groups (frame, hdr); - } - - if (conn->connected == 0) - transport_connect (trans); - - ret = -1; - - if (conn->connected || - ((type == GF_OP_TYPE_MOP_REQUEST) && - (op == GF_MOP_SETVOLUME))) { - ret = transport_submit (trans, (char *)hdr, hdrlen, - vector, count, iobref); - } - - if ((ret >= 0) && frame) { - pthread_mutex_lock (&conf->mutex); - { - gettimeofday (&conf->last_sent, NULL); - } - pthread_mutex_unlock (&conf->mutex); - save_frame (trans, frame, op, type, callid); - } - - if (!conn->ping_started && (ret >= 0)) { - start_ping = 1; - } - } - pthread_mutex_unlock (&conn->lock); - - if (start_ping) - client_start_ping ((void *) trans); - - if (frame && (ret < 0)) { - rsphdr.op = op; - rsphdr.rsp.op_ret = hton32 (-1); - rsphdr.rsp.op_errno = hton32 (ENOTCONN); - - if (type == GF_OP_TYPE_FOP_REQUEST) { - rsphdr.type = GF_OP_TYPE_FOP_REPLY; - gf_fops[op] (frame, &rsphdr, sizeof (rsphdr), NULL); - } else if (type == GF_OP_TYPE_MOP_REQUEST) { - rsphdr.type = GF_OP_TYPE_MOP_REPLY; - gf_mops[op] (frame, &rsphdr, sizeof (rsphdr), NULL); - } else { - rsphdr.type = GF_OP_TYPE_CBK_REPLY; - gf_cbks[op] (frame, &rsphdr, sizeof (rsphdr), NULL); - } - - GF_FREE (hdr); - } - - return ret; -} - - - -/** - * client_create - create function for client protocol - * @frame: call frame - * @this: this translator structure - * @path: complete path to file - * @flags: create flags - * @mode: create mode - * - * external reference through client_protocol_xlator->fops->create - */ - -int -client_create (call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags, - mode_t mode, fd_t *fd, dict_t *params) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_create_req_t *req = NULL; - size_t hdrlen = 0; - size_t pathlen = 0; - size_t baselen = 0; - int32_t ret = -1; - ino_t par = 0; - uint64_t gen = 0; - client_local_t *local = NULL; - - - local = GF_CALLOC (1, sizeof (*local), gf_client_mt_client_local_t); - GF_VALIDATE_OR_GOTO (this->name, local, unwind); - - local->fd = fd_ref (fd); - loc_copy (&local->loc, loc); - local->flags = flags; - - frame->local = local; - - pathlen = STRLEN_0 (loc->path); - baselen = STRLEN_0 (loc->name); - - ret = inode_ctx_get2 (loc->parent, this, &par, &gen); - if (loc->parent->ino && ret < 0) { - gf_log (this->name, GF_LOG_DEBUG, - "CREATE %"PRId64"/%s (%s): failed to get remote inode " - "number for parent inode", - loc->parent->ino, loc->name, loc->path); - goto unwind; - } - - hdrlen = gf_hdr_len (req, pathlen + baselen); - hdr = gf_hdr_new (req, pathlen + baselen); - GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - - req = gf_param (hdr); - - req->flags = hton32 (gf_flags_from_flags (flags)); - req->mode = hton32 (mode); - req->par = hton64 (par); - req->gen = hton64 (gen); - strcpy (req->path, loc->path); - strcpy (req->bname + pathlen, loc->name); - - ret = protocol_client_xfer (frame, this, - CLIENT_CHANNEL (this, CHANNEL_LOWLAT), - GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_CREATE, - hdr, hdrlen, NULL, 0, NULL); - return ret; -unwind: - if (hdr) - GF_FREE (hdr); - STACK_UNWIND (frame, -1, EINVAL, fd, NULL, NULL); - return 0; - -} - -/** - * client_open - open function for client protocol - * @frame: call frame - * @this: this translator structure - * @loc: location of file - * @flags: open flags - * @mode: open modes - * - * external reference through client_protocol_xlator->fops->open - */ - -int -client_open (call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags, - fd_t *fd, int32_t wbflags) -{ - int ret = -1; - gf_hdr_common_t *hdr = NULL; - size_t hdrlen = 0; - gf_fop_open_req_t *req = NULL; - size_t pathlen = 0; - ino_t ino = 0; - uint64_t gen = 0; - client_local_t *local = NULL; - - local = GF_CALLOC (1, sizeof (*local), gf_client_mt_client_local_t); - GF_VALIDATE_OR_GOTO (this->name, local, unwind); - - local->fd = fd_ref (fd); - loc_copy (&local->loc, loc); - local->flags = flags; - local->wbflags = wbflags; - - frame->local = local; - - pathlen = STRLEN_0 (loc->path); - - ret = inode_ctx_get2 (loc->inode, this, &ino, &gen); - if (loc->inode->ino && ret < 0) { - gf_log (this->name, GF_LOG_DEBUG, - "OPEN %"PRId64" (%s): " - "failed to get remote inode number", - loc->inode->ino, loc->path); - goto unwind; - } - - hdrlen = gf_hdr_len (req, pathlen); - hdr = gf_hdr_new (req, pathlen); - GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - - req = gf_param (hdr); - - req->ino = hton64 (ino); - req->gen = hton64 (gen); - req->flags = hton32 (gf_flags_from_flags (flags)); - req->wbflags = hton32 (wbflags); - strcpy (req->path, loc->path); - - ret = protocol_client_xfer (frame, this, - CLIENT_CHANNEL (this, CHANNEL_LOWLAT), - GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_OPEN, - hdr, hdrlen, NULL, 0, NULL); - - return ret; -unwind: - if (hdr) - GF_FREE (hdr); - STACK_UNWIND (frame, -1, EINVAL, fd); - return 0; - -} - - -/** - * client_stat - stat function for client protocol - * @frame: call frame - * @this: this translator structure - * @loc: location - * - * external reference through client_protocol_xlator->fops->stat - */ - -int -client_stat (call_frame_t *frame, xlator_t *this, loc_t *loc) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_stat_req_t *req = NULL; - size_t hdrlen = -1; - int32_t ret = -1; - size_t pathlen = 0; - ino_t ino = 0; - ino_t gen = 0; - - pathlen = STRLEN_0 (loc->path); - - ret = inode_ctx_get2 (loc->inode, this, &ino, &gen); - if (loc->inode->ino && ret < 0) { - gf_log (this->name, GF_LOG_TRACE, - "STAT %"PRId64" (%s): " - "failed to get remote inode number", - loc->inode->ino, loc->path); - goto unwind; - } - - hdrlen = gf_hdr_len (req, pathlen); - hdr = gf_hdr_new (req, pathlen); - GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - - req = gf_param (hdr); - - req->ino = hton64 (ino); - req->gen = hton64 (gen); - strcpy (req->path, loc->path); - - ret = protocol_client_xfer (frame, this, - CLIENT_CHANNEL (this, CHANNEL_LOWLAT), - GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_STAT, - hdr, hdrlen, NULL, 0, NULL); - - return ret; -unwind: - if (hdr) - GF_FREE (hdr); - STACK_UNWIND (frame, -1, EINVAL, NULL); - return 0; - -} - - -/** - * client_readlink - readlink function for client protocol - * @frame: call frame - * @this: this translator structure - * @loc: location - * @size: - * - * external reference through client_protocol_xlator->fops->readlink - */ -int -client_readlink (call_frame_t *frame, xlator_t *this, loc_t *loc, size_t size) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_readlink_req_t *req = NULL; - size_t hdrlen = -1; - int ret = -1; - size_t pathlen = 0; - ino_t ino = 0; - uint64_t gen = 0; - - pathlen = STRLEN_0 (loc->path); - - ret = inode_ctx_get2 (loc->inode, this, &ino, &gen); - if (loc->inode->ino && ret < 0) { - gf_log (this->name, GF_LOG_DEBUG, - "READLINK %"PRId64" (%s): " - "failed to get remote inode number", - loc->inode->ino, loc->path); - goto unwind; - } - - hdrlen = gf_hdr_len (req, pathlen); - hdr = gf_hdr_new (req, pathlen); - GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - - req = gf_param (hdr); - - req->ino = hton64 (ino); - req->gen = hton64 (gen); - req->size = hton32 (size); - strcpy (req->path, loc->path); - - ret = protocol_client_xfer (frame, this, - CLIENT_CHANNEL (this, CHANNEL_LOWLAT), - GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_READLINK, - hdr, hdrlen, NULL, 0, NULL); - - return ret; -unwind: - if (hdr) - GF_FREE (hdr); - STACK_UNWIND_STRICT (readlink, frame, -1, EINVAL, - NULL, NULL); - return 0; - -} - - -/** - * client_mknod - mknod function for client protocol - * @frame: call frame - * @this: this translator structure - * @path: pathname of node - * @mode: - * @dev: - * - * external reference through client_protocol_xlator->fops->mknod - */ -int -client_mknod (call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode, - dev_t dev, dict_t *params) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_mknod_req_t *req = NULL; - size_t hdrlen = -1; - int ret = -1; - size_t pathlen = 0; - size_t baselen = 0; - ino_t par = 0; - uint64_t gen = 0; - client_local_t *local = NULL; - - local = GF_CALLOC (1, sizeof (*local), gf_client_mt_client_local_t); - GF_VALIDATE_OR_GOTO (this->name, local, unwind); - - loc_copy (&local->loc, loc); - - frame->local = local; - - pathlen = STRLEN_0 (loc->path); - baselen = STRLEN_0 (loc->name); - ret = inode_ctx_get2 (loc->parent, this, &par, &gen); - if (loc->parent->ino && ret < 0) { - gf_log (this->name, GF_LOG_DEBUG, - "MKNOD %"PRId64"/%s (%s): failed to get remote inode " - "number for parent", - loc->parent->ino, loc->name, loc->path); - goto unwind; - } - - hdrlen = gf_hdr_len (req, pathlen + baselen); - hdr = gf_hdr_new (req, pathlen + baselen); - GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - - req = gf_param (hdr); - - req->par = hton64 (par); - req->gen = hton64 (gen); - req->mode = hton32 (mode); - req->dev = hton64 (dev); - strcpy (req->path, loc->path); - strcpy (req->bname + pathlen, loc->name); - - ret = protocol_client_xfer (frame, this, - CLIENT_CHANNEL (this, CHANNEL_LOWLAT), - GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_MKNOD, - hdr, hdrlen, NULL, 0, NULL); - - return ret; -unwind: - if (hdr) - GF_FREE (hdr); - STACK_UNWIND (frame, -1, EINVAL, loc->inode, NULL); - return 0; - -} - - -/** - * client_mkdir - mkdir function for client protocol - * @frame: call frame - * @this: this translator structure - * @path: pathname of directory - * @mode: - * - * external reference through client_protocol_xlator->fops->mkdir - */ -int -client_mkdir (call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode, - dict_t *params) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_mkdir_req_t *req = NULL; - size_t hdrlen = -1; - int ret = -1; - size_t pathlen = 0; - size_t baselen = 0; - ino_t par = 0; - uint64_t gen = 0; - client_local_t *local = NULL; - - local = GF_CALLOC (1, sizeof (*local), gf_client_mt_client_local_t); - GF_VALIDATE_OR_GOTO (this->name, local, unwind); - - loc_copy (&local->loc, loc); - - frame->local = local; - - pathlen = STRLEN_0 (loc->path); - baselen = STRLEN_0 (loc->name); - ret = inode_ctx_get2 (loc->parent, this, &par, &gen); - if (loc->parent->ino && ret < 0) { - gf_log (this->name, GF_LOG_DEBUG, - "MKDIR %"PRId64"/%s (%s): failed to get remote inode " - "number for parent", - loc->parent->ino, loc->name, loc->path); - goto unwind; - } - - hdrlen = gf_hdr_len (req, pathlen + baselen); - hdr = gf_hdr_new (req, pathlen + baselen); - GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - - req = gf_param (hdr); - - req->par = hton64 (par); - req->gen = hton64 (gen); - req->mode = hton32 (mode); - strcpy (req->path, loc->path); - strcpy (req->bname + pathlen, loc->name); - - ret = protocol_client_xfer (frame, this, - CLIENT_CHANNEL (this, CHANNEL_LOWLAT), - GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_MKDIR, - hdr, hdrlen, NULL, 0, NULL); - - return ret; -unwind: - if (hdr) - GF_FREE (hdr); - STACK_UNWIND (frame, -1, EINVAL, loc->inode, NULL); - return 0; - -} - -/** - * client_unlink - unlink function for client protocol - * @frame: call frame - * @this: this translator structure - * @loc: location of file - * - * external reference through client_protocol_xlator->fops->unlink - */ - -int -client_unlink (call_frame_t *frame, xlator_t *this, loc_t *loc) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_unlink_req_t *req = NULL; - size_t hdrlen = -1; - int ret = -1; - size_t pathlen = 0; - size_t baselen = 0; - ino_t par = 0; - uint64_t gen = 0; - - pathlen = STRLEN_0 (loc->path); - baselen = STRLEN_0 (loc->name); - ret = inode_ctx_get2 (loc->parent, this, &par, &gen); - if (loc->parent->ino && ret < 0) { - gf_log (this->name, GF_LOG_DEBUG, - "UNLINK %"PRId64"/%s (%s): failed to get remote inode " - "number for parent", - loc->parent->ino, loc->name, loc->path); - goto unwind; - } - - hdrlen = gf_hdr_len (req, pathlen + baselen); - hdr = gf_hdr_new (req, pathlen + baselen); - GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - - req = gf_param (hdr); - - req->par = hton64 (par); - req->gen = hton64 (gen); - strcpy (req->path, loc->path); - strcpy (req->bname + pathlen, loc->name); - - ret = protocol_client_xfer (frame, this, - CLIENT_CHANNEL (this, CHANNEL_BULK), - GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_UNLINK, - hdr, hdrlen, NULL, 0, NULL); - - return ret; -unwind: - if (hdr) - GF_FREE (hdr); - STACK_UNWIND (frame, -1, EINVAL); - return 0; - -} - -/** - * client_rmdir - rmdir function for client protocol - * @frame: call frame - * @this: this translator structure - * @loc: location - * - * external reference through client_protocol_xlator->fops->rmdir - */ - -int -client_rmdir (call_frame_t *frame, xlator_t *this, loc_t *loc) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_rmdir_req_t *req = NULL; - size_t hdrlen = -1; - int ret = -1; - size_t pathlen = 0; - size_t baselen = 0; - ino_t par = 0; - uint64_t gen = 0; - - pathlen = STRLEN_0 (loc->path); - baselen = STRLEN_0 (loc->name); - ret = inode_ctx_get2 (loc->parent, this, &par, &gen); - if (loc->parent->ino && ret < 0) { - gf_log (this->name, GF_LOG_DEBUG, - "RMDIR %"PRId64"/%s (%s): failed to get remote inode " - "number for parent", - loc->parent->ino, loc->name, loc->path); - goto unwind; - } - - hdrlen = gf_hdr_len (req, pathlen + baselen); - hdr = gf_hdr_new (req, pathlen + baselen); - GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - - req = gf_param (hdr); - - req->par = hton64 (par); - req->gen = hton64 (gen); - strcpy (req->path, loc->path); - strcpy (req->bname + pathlen, loc->name); - - ret = protocol_client_xfer (frame, this, - CLIENT_CHANNEL (this, CHANNEL_BULK), - GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_RMDIR, - hdr, hdrlen, NULL, 0, NULL); - - return ret; -unwind: - if (hdr) - GF_FREE (hdr); - STACK_UNWIND (frame, -1, EINVAL); - return 0; - -} - - -/** - * client_symlink - symlink function for client protocol - * @frame: call frame - * @this: this translator structure - * @oldpath: pathname of target - * @newpath: pathname of symlink - * - * external reference through client_protocol_xlator->fops->symlink - */ - -int -client_symlink (call_frame_t *frame, xlator_t *this, const char *linkname, - loc_t *loc, dict_t *params) -{ - int ret = -1; - gf_hdr_common_t *hdr = NULL; - gf_fop_symlink_req_t *req = NULL; - size_t hdrlen = 0; - size_t pathlen = 0; - size_t newlen = 0; - size_t baselen = 0; - ino_t par = 0; - uint64_t gen = 0; - client_local_t *local = NULL; - - local = GF_CALLOC (1, sizeof (*local), gf_client_mt_client_local_t); - GF_VALIDATE_OR_GOTO (this->name, local, unwind); - - loc_copy (&local->loc, loc); - - frame->local = local; - - pathlen = STRLEN_0 (loc->path); - baselen = STRLEN_0 (loc->name); - newlen = STRLEN_0 (linkname); - ret = inode_ctx_get2 (loc->parent, this, &par, &gen); - if (loc->parent->ino && ret < 0) { - gf_log (this->name, GF_LOG_DEBUG, - "SYMLINK %"PRId64"/%s (%s): failed to get remote inode" - " number parent", - loc->parent->ino, loc->name, loc->path); - goto unwind; - } - - hdrlen = gf_hdr_len (req, pathlen + baselen + newlen); - hdr = gf_hdr_new (req, pathlen + baselen + newlen); - GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - - req = gf_param (hdr); - - req->par = hton64 (par); - req->gen = hton64 (gen); - strcpy (req->path, loc->path); - strcpy (req->bname + pathlen, loc->name); - strcpy (req->linkname + pathlen + baselen, linkname); - - ret = protocol_client_xfer (frame, this, - CLIENT_CHANNEL (this, CHANNEL_LOWLAT), - GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_SYMLINK, - hdr, hdrlen, NULL, 0, NULL); - return ret; -unwind: - if (hdr) - GF_FREE (hdr); - STACK_UNWIND (frame, -1, EINVAL, loc->inode, NULL); - return 0; - -} - -/** - * client_rename - rename function for client protocol - * @frame: call frame - * @this: this translator structure - * @oldloc: location of old pathname - * @newloc: location of new pathname - * - * external reference through client_protocol_xlator->fops->rename - */ - -int -client_rename (call_frame_t *frame, xlator_t *this, loc_t *oldloc, - loc_t *newloc) -{ - int ret = -1; - gf_hdr_common_t *hdr = NULL; - gf_fop_rename_req_t *req = NULL; - size_t hdrlen = 0; - size_t oldpathlen = 0; - size_t oldbaselen = 0; - size_t newpathlen = 0; - size_t newbaselen = 0; - ino_t oldpar = 0; - uint64_t oldgen = 0; - ino_t newpar = 0; - uint64_t newgen = 0; - - oldpathlen = STRLEN_0 (oldloc->path); - oldbaselen = STRLEN_0 (oldloc->name); - newpathlen = STRLEN_0 (newloc->path); - newbaselen = STRLEN_0 (newloc->name); - ret = inode_ctx_get2 (oldloc->parent, this, &oldpar, &oldgen); - if (oldloc->parent->ino && ret < 0) { - gf_log (this->name, GF_LOG_DEBUG, - "RENAME %"PRId64"/%s (%s): failed to get remote inode " - "number for source parent", - oldloc->parent->ino, oldloc->name, oldloc->path); - goto unwind; - } - - ret = inode_ctx_get2 (newloc->parent, this, &newpar, &newgen); - if (newloc->parent->ino && ret < 0) { - gf_log (this->name, GF_LOG_DEBUG, - "CREATE %"PRId64"/%s (%s): failed to get remote inode " - "number for destination parent", - newloc->parent->ino, newloc->name, newloc->path); - goto unwind; - } - - hdrlen = gf_hdr_len (req, (oldpathlen + oldbaselen + - newpathlen + newbaselen)); - hdr = gf_hdr_new (req, (oldpathlen + oldbaselen + - newpathlen + newbaselen)); - - GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - - req = gf_param (hdr); - - req->oldpar = hton64 (oldpar); - req->oldgen = hton64 (oldgen); - req->newpar = hton64 (newpar); - req->newgen = hton64 (newgen); - - strcpy (req->oldpath, oldloc->path); - strcpy (req->oldbname + oldpathlen, oldloc->name); - strcpy (req->newpath + oldpathlen + oldbaselen, newloc->path); - strcpy (req->newbname + oldpathlen + oldbaselen + newpathlen, - newloc->name); - - ret = protocol_client_xfer (frame, this, - CLIENT_CHANNEL (this, CHANNEL_LOWLAT), - GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_RENAME, - hdr, hdrlen, NULL, 0, NULL); - return ret; -unwind: - if (hdr) - GF_FREE (hdr); - STACK_UNWIND (frame, -1, EINVAL, NULL); - return 0; - -} - -/** - * client_link - link function for client protocol - * @frame: call frame - * @this: this translator structure - * @oldloc: location of old pathname - * @newpath: new pathname - * - * external reference through client_protocol_xlator->fops->link - */ - -int -client_link (call_frame_t *frame, xlator_t *this, loc_t *oldloc, loc_t *newloc) -{ - int ret = -1; - gf_hdr_common_t *hdr = NULL; - gf_fop_link_req_t *req = NULL; - size_t hdrlen = 0; - size_t oldpathlen = 0; - size_t newpathlen = 0; - size_t newbaselen = 0; - ino_t oldino = 0; - uint64_t oldgen = 0; - ino_t newpar = 0; - uint64_t newgen = 0; - client_local_t *local = NULL; - - local = GF_CALLOC (1, sizeof (*local), gf_client_mt_client_local_t); - GF_VALIDATE_OR_GOTO (this->name, local, unwind); - - loc_copy (&local->loc, oldloc); - - frame->local = local; - - oldpathlen = STRLEN_0 (oldloc->path); - newpathlen = STRLEN_0 (newloc->path); - newbaselen = STRLEN_0 (newloc->name); - - ret = inode_ctx_get2 (oldloc->inode, this, &oldino, &oldgen); - if (oldloc->inode->ino && ret < 0) { - gf_log (this->name, GF_LOG_DEBUG, - "LINK %"PRId64"/%s (%s) ==> %"PRId64" (%s): " - "failed to get remote inode number for source inode", - newloc->parent->ino, newloc->name, newloc->path, - oldloc->ino, oldloc->path); - goto unwind; - } - - ret = inode_ctx_get2 (newloc->parent, this, &newpar, &newgen); - if (newloc->parent->ino && ret < 0) { - gf_log (this->name, GF_LOG_DEBUG, - "LINK %"PRId64"/%s (%s) ==> %"PRId64" (%s): " - "failed to get remote inode number destination parent", - newloc->parent->ino, newloc->name, newloc->path, - oldloc->ino, oldloc->path); - goto unwind; - } - - hdrlen = gf_hdr_len (req, oldpathlen + newpathlen + newbaselen); - hdr = gf_hdr_new (req, oldpathlen + newpathlen + newbaselen); - GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - - req = gf_param (hdr); - - strcpy (req->oldpath, oldloc->path); - strcpy (req->newpath + oldpathlen, newloc->path); - strcpy (req->newbname + oldpathlen + newpathlen, newloc->name); - - req->oldino = hton64 (oldino); - req->oldgen = hton64 (oldgen); - req->newpar = hton64 (newpar); - req->newgen = hton64 (newgen); - - ret = protocol_client_xfer (frame, this, - CLIENT_CHANNEL (this, CHANNEL_LOWLAT), - GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_LINK, - hdr, hdrlen, NULL, 0, NULL); - return ret; -unwind: - if (hdr) - GF_FREE (hdr); - STACK_UNWIND (frame, -1, EINVAL, oldloc->inode, NULL); - return 0; -} - - -/** - * client_truncate - truncate function for client protocol - * @frame: call frame - * @this: this translator structure - * @loc: location - * @offset: - * - * external reference through client_protocol_xlator->fops->truncate - */ - -int -client_truncate (call_frame_t *frame, xlator_t *this, loc_t *loc, off_t offset) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_truncate_req_t *req = NULL; - size_t hdrlen = -1; - int ret = -1; - size_t pathlen = 0; - ino_t ino = 0; - uint64_t gen = 0; - - pathlen = STRLEN_0 (loc->path); - ret = inode_ctx_get2 (loc->inode, this, &ino, &gen); - if (loc->inode->ino && ret < 0) { - gf_log (this->name, GF_LOG_DEBUG, - "TRUNCATE %"PRId64" (%s): " - "failed to get remote inode number", - loc->inode->ino, loc->path); - goto unwind; - } - - hdrlen = gf_hdr_len (req, pathlen); - hdr = gf_hdr_new (req, pathlen); - GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - - req = gf_param (hdr); - - req->ino = hton64 (ino); - req->gen = hton64 (gen); - req->offset = hton64 (offset); - strcpy (req->path, loc->path); - - ret = protocol_client_xfer (frame, this, - CLIENT_CHANNEL (this, CHANNEL_BULK), - GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_TRUNCATE, - hdr, hdrlen, NULL, 0, NULL); - - return ret; -unwind: - if (hdr) - GF_FREE (hdr); - STACK_UNWIND (frame, -1, EINVAL, NULL); - return 0; - -} - - -/** - * client_readv - readv function for client protocol - * @frame: call frame - * @this: this translator structure - * @fd: file descriptor structure - * @size: - * @offset: - * - * external reference through client_protocol_xlator->fops->readv - */ - -int -client_readv (call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size, - off_t offset) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_read_req_t *req = NULL; - size_t hdrlen = 0; - int64_t remote_fd = -1; - int ret = -1; - client_fd_ctx_t *fdctx = NULL; - client_conf_t *conf = NULL; - - conf = this->private; - - pthread_mutex_lock (&conf->mutex); - { - fdctx = this_fd_get_ctx (fd, this); - } - pthread_mutex_unlock (&conf->mutex); - - if (fdctx == NULL) { - gf_log (this->name, GF_LOG_TRACE, - "(%"PRId64"): failed to get fd ctx, EBADFD", - fd->inode->ino); - STACK_UNWIND (frame, -1, EBADFD, NULL, 0, NULL); - return 0; - } - - if (fdctx->remote_fd == -1) { - gf_log (this->name, GF_LOG_TRACE, - "(%"PRId64"): failed to get fd ctx, EBADFD", - fd->inode->ino); - STACK_UNWIND (frame, -1, EBADFD, NULL, 0, NULL); - return 0; - } - - remote_fd = fdctx->remote_fd; - hdrlen = gf_hdr_len (req, 0); - hdr = gf_hdr_new (req, 0); - GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - - req = gf_param (hdr); - - req->fd = hton64 (remote_fd); - req->size = hton32 (size); - req->offset = hton64 (offset); - - ret = protocol_client_xfer (frame, this, - CLIENT_CHANNEL (this, CHANNEL_BULK), - GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_READ, - hdr, hdrlen, NULL, 0, NULL); - - return 0; -unwind: - if (hdr) - GF_FREE (hdr); - STACK_UNWIND (frame, -1, EINVAL, NULL, 0, NULL); - return 0; - -} - -/** - * client_writev - writev function for client protocol - * @frame: call frame - * @this: this translator structure - * @fd: file descriptor structure - * @vector: - * @count: - * @offset: - * - * external reference through client_protocol_xlator->fops->writev - */ - -int -client_writev (call_frame_t *frame, xlator_t *this, fd_t *fd, - struct iovec *vector, int32_t count, off_t offset, - struct iobref *iobref) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_write_req_t *req = NULL; - size_t hdrlen = 0; - int64_t remote_fd = -1; - int ret = -1; - client_fd_ctx_t *fdctx = NULL; - client_conf_t *conf = NULL; - - conf = this->private; - - pthread_mutex_lock (&conf->mutex); - { - fdctx = this_fd_get_ctx (fd, this); - } - pthread_mutex_unlock (&conf->mutex); - - if (fdctx == NULL) { - gf_log (this->name, GF_LOG_TRACE, - "(%"PRId64"): failed to get fd ctx. EBADFD", - fd->inode->ino); - STACK_UNWIND (frame, -1, EBADFD, NULL); - return 0; - } - - if (fdctx->remote_fd == -1) { - gf_log (this->name, GF_LOG_TRACE, - "(%"PRId64"): failed to get fd ctx. EBADFD", - fd->inode->ino); - STACK_UNWIND (frame, -1, EBADFD, NULL); - return 0; - } - - remote_fd = fdctx->remote_fd; - hdrlen = gf_hdr_len (req, 0); - hdr = gf_hdr_new (req, 0); - GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - - req = gf_param (hdr); - - req->fd = hton64 (remote_fd); - req->size = hton32 (iov_length (vector, count)); - req->offset = hton64 (offset); - - ret = protocol_client_xfer (frame, this, - CLIENT_CHANNEL (this, CHANNEL_BULK), - GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_WRITE, - hdr, hdrlen, vector, count, iobref); - return ret; -unwind: - if (hdr) - GF_FREE (hdr); - STACK_UNWIND (frame, -1, EINVAL, NULL); - return 0; - -} - - -/** - * client_statfs - statfs function for client protocol - * @frame: call frame - * @this: this translator structure - * @loc: location - * - * external reference through client_protocol_xlator->fops->statfs - */ - -int -client_statfs (call_frame_t *frame, xlator_t *this, loc_t *loc) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_statfs_req_t *req = NULL; - size_t hdrlen = -1; - int ret = -1; - size_t pathlen = 0; - ino_t ino = 0; - ino_t gen = 0; - - pathlen = STRLEN_0 (loc->path); - - if (loc->inode) { - ret = inode_ctx_get2 (loc->inode, this, &ino, &gen); - if (loc->inode->ino && ret < 0) { - gf_log (this->name, GF_LOG_DEBUG, - "STATFS %"PRId64" (%s): " - "failed to get remote inode number", - loc->inode->ino, loc->path); - goto unwind; - } - } - - hdrlen = gf_hdr_len (req, pathlen); - hdr = gf_hdr_new (req, pathlen); - GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - - req = gf_param (hdr); - - req->ino = hton64 (ino); - req->gen = hton64 (gen); - strcpy (req->path, loc->path); - - ret = protocol_client_xfer (frame, this, - CLIENT_CHANNEL (this, CHANNEL_LOWLAT), - GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_STATFS, - hdr, hdrlen, NULL, 0, NULL); - - return ret; -unwind: - if (hdr) - GF_FREE (hdr); - STACK_UNWIND (frame, -1, EINVAL, NULL); - return 0; - -} - - -/** - * client_flush - flush function for client protocol - * @frame: call frame - * @this: this translator structure - * @fd: file descriptor structure - * - * external reference through client_protocol_xlator->fops->flush - */ - -int -client_flush (call_frame_t *frame, xlator_t *this, fd_t *fd) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_flush_req_t *req = NULL; - size_t hdrlen = 0; - int64_t remote_fd = -1; - int ret = -1; - client_fd_ctx_t *fdctx = NULL; - client_conf_t *conf = NULL; - - conf = this->private; - - pthread_mutex_lock (&conf->mutex); - { - fdctx = this_fd_get_ctx (fd, this); - } - pthread_mutex_unlock (&conf->mutex); - - if (fdctx == NULL) { - gf_log (this->name, GF_LOG_TRACE, - "(%"PRId64"): failed to get fd ctx. EBADFD", - fd->inode->ino); - STACK_UNWIND (frame, -1, EBADFD); - return 0; - } - - if (fdctx->remote_fd == -1) { - gf_log (this->name, GF_LOG_TRACE, - "(%"PRId64"): failed to get fd ctx. EBADFD", - fd->inode->ino); - STACK_UNWIND (frame, -1, EBADFD); - return 0; - } - - remote_fd = fdctx->remote_fd; - hdrlen = gf_hdr_len (req, 0); - hdr = gf_hdr_new (req, 0); - GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - - req = gf_param (hdr); - - req->fd = hton64 (remote_fd); - - ret = protocol_client_xfer (frame, this, - CLIENT_CHANNEL (this, CHANNEL_BULK), - GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_FLUSH, - hdr, hdrlen, NULL, 0, NULL); - - return 0; -unwind: - if (hdr) - GF_FREE (hdr); - STACK_UNWIND (frame, -1, EINVAL); - return 0; - -} - -/** - * client_fsync - fsync function for client protocol - * @frame: call frame - * @this: this translator structure - * @fd: file descriptor structure - * @flags: - * - * external reference through client_protocol_xlator->fops->fsync - */ - -int -client_fsync (call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t flags) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_fsync_req_t *req = NULL; - size_t hdrlen = 0; - int64_t remote_fd = -1; - int32_t ret = -1; - client_fd_ctx_t *fdctx = NULL; - client_conf_t *conf = NULL; - - conf = this->private; - - pthread_mutex_lock (&conf->mutex); - { - fdctx = this_fd_get_ctx (fd, this); - } - pthread_mutex_unlock (&conf->mutex); - - if (fdctx == NULL) { - gf_log (this->name, GF_LOG_TRACE, - "(%"PRId64"): failed to get fd ctx. EBADFD", - fd->inode->ino); - STACK_UNWIND (frame, -1, EBADFD); - return 0; - } - - if (fdctx->remote_fd == -1) { - gf_log (this->name, GF_LOG_TRACE, - "(%"PRId64"): failed to get fd ctx. EBADFD", - fd->inode->ino); - STACK_UNWIND (frame, -1, EBADFD); - return 0; - } - - remote_fd = fdctx->remote_fd; - hdrlen = gf_hdr_len (req, 0); - hdr = gf_hdr_new (req, 0); - GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - - req = gf_param (hdr); - - req->fd = hton64 (remote_fd); - req->data = hton32 (flags); - - ret = protocol_client_xfer (frame, this, - CLIENT_CHANNEL (this, CHANNEL_BULK), - GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_FSYNC, - hdr, hdrlen, NULL, 0, NULL); - - return ret; -unwind: - if (hdr) - GF_FREE (hdr); - STACK_UNWIND (frame, -1, EINVAL); - return 0; - -} - -int -client_xattrop (call_frame_t *frame, xlator_t *this, loc_t *loc, - gf_xattrop_flags_t flags, dict_t *dict) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_xattrop_req_t *req = NULL; - size_t hdrlen = 0; - size_t dict_len = 0; - int32_t ret = -1; - size_t pathlen = 0; - ino_t ino = 0; - uint64_t gen = 0; - char *buf = NULL; - - GF_VALIDATE_OR_GOTO ("client", this, unwind); - - GF_VALIDATE_OR_GOTO (this->name, loc, unwind); - - if (dict) { - ret = dict_allocate_and_serialize (dict, &buf, &dict_len); - if (ret < 0) { - gf_log (this->name, GF_LOG_DEBUG, - "failed to get serialized length of dict(%p)", - dict); - goto unwind; - } - } - - pathlen = STRLEN_0 (loc->path); - - ret = inode_ctx_get2 (loc->inode, this, &ino, &gen); - if (loc->inode->ino && ret < 0) { - gf_log (this->name, GF_LOG_DEBUG, - "XATTROP %"PRId64" (%s): " - "failed to get remote inode number", - loc->inode->ino, loc->path); - goto unwind; - } - - hdrlen = gf_hdr_len (req, dict_len + pathlen); - hdr = gf_hdr_new (req, dict_len + pathlen); - GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - - req = gf_param (hdr); - - req->flags = hton32 (flags); - req->dict_len = hton32 (dict_len); - if (dict) { - memcpy (req->dict, buf, dict_len); - GF_FREE (buf); - } - - req->ino = hton64 (ino); - req->gen = hton64 (gen); - strcpy (req->path + dict_len, loc->path); - - ret = protocol_client_xfer (frame, this, - CLIENT_CHANNEL (this, CHANNEL_BULK), - GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_XATTROP, - hdr, hdrlen, NULL, 0, NULL); - return ret; -unwind: - if (hdr) - GF_FREE (hdr); - - STACK_UNWIND (frame, -1, EINVAL, NULL); - return 0; -} - - -int -client_fxattrop (call_frame_t *frame, xlator_t *this, fd_t *fd, - gf_xattrop_flags_t flags, dict_t *dict) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_fxattrop_req_t *req = NULL; - size_t hdrlen = 0; - size_t dict_len = 0; - int64_t remote_fd = -1; - int32_t ret = -1; - ino_t ino = 0; - client_fd_ctx_t *fdctx = NULL; - client_conf_t *conf = NULL; - - conf = this->private; - - if (dict) { - dict_len = dict_serialized_length (dict); - if (dict_len < 0) { - gf_log (this->name, GF_LOG_DEBUG, - "failed to get serialized length of dict(%p)", - dict); - goto unwind; - } - } - - pthread_mutex_lock (&conf->mutex); - { - fdctx = this_fd_get_ctx (fd, this); - } - pthread_mutex_unlock (&conf->mutex); - - if (fdctx == NULL) { - gf_log (this->name, GF_LOG_TRACE, - "(%"PRId64"): failed to get fd ctx. " - "returning EBADFD", - fd->inode->ino); - goto unwind; - } - - if (fdctx->remote_fd == -1) { - gf_log (this->name, GF_LOG_TRACE, - "(%"PRId64"): failed to get fd ctx. EBADFD", - fd->inode->ino); - goto unwind; - } - - ino = fd->inode->ino; - remote_fd = fdctx->remote_fd; - - hdrlen = gf_hdr_len (req, dict_len); - hdr = gf_hdr_new (req, dict_len); - GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - - req = gf_param (hdr); - - req->flags = hton32 (flags); - req->dict_len = hton32 (dict_len); - if (dict) { - ret = dict_serialize (dict, req->dict); - if (ret < 0) { - gf_log (this->name, GF_LOG_DEBUG, - "failed to serialize dictionary(%p)", - dict); - goto unwind; - } - } - req->fd = hton64 (remote_fd); - req->ino = hton64 (ino); - - ret = protocol_client_xfer (frame, this, - CLIENT_CHANNEL (this, CHANNEL_BULK), - GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_FXATTROP, - hdr, hdrlen, NULL, 0, NULL); - return ret; -unwind: - if (hdr) - GF_FREE (hdr); - - STACK_UNWIND (frame, -1, EBADFD, NULL); - return 0; - -} - -/** - * client_setxattr - setxattr function for client protocol - * @frame: call frame - * @this: this translator structure - * @loc: location - * @dict: dictionary which contains key:value to be set. - * @flags: - * - * external reference through client_protocol_xlator->fops->setxattr - */ - -int -client_setxattr (call_frame_t *frame, xlator_t *this, loc_t *loc, - dict_t *dict, int32_t flags) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_setxattr_req_t *req = NULL; - size_t hdrlen = 0; - size_t dict_len = 0; - int ret = -1; - size_t pathlen = 0; - ino_t ino = 0; - uint64_t gen = 0; - - dict_len = dict_serialized_length (dict); - if (dict_len < 0) { - gf_log (this->name, GF_LOG_DEBUG, - "failed to get serialized length of dict(%p)", - dict); - goto unwind; - } - - pathlen = STRLEN_0 (loc->path); - - ret = inode_ctx_get2 (loc->inode, this, &ino, &gen); - if (loc->inode->ino && ret < 0) { - gf_log (this->name, GF_LOG_DEBUG, - "SETXATTR %"PRId64" (%s): " - "failed to get remote inode number", - loc->inode->ino, loc->path); - goto unwind; - } - - hdrlen = gf_hdr_len (req, dict_len + pathlen); - hdr = gf_hdr_new (req, dict_len + pathlen); - GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - - req = gf_param (hdr); - - req->ino = hton64 (ino); - req->gen = hton64 (gen); - req->flags = hton32 (flags); - req->dict_len = hton32 (dict_len); - - ret = dict_serialize (dict, req->dict); - if (ret < 0) { - gf_log (this->name, GF_LOG_DEBUG, - "failed to serialize dictionary(%p)", - dict); - goto unwind; - } - - strcpy (req->path + dict_len, loc->path); - - ret = protocol_client_xfer (frame, this, - CLIENT_CHANNEL (this, CHANNEL_BULK), - GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_SETXATTR, - hdr, hdrlen, NULL, 0, NULL); - return ret; -unwind: - if (hdr) - GF_FREE (hdr); - - STACK_UNWIND (frame, -1, EINVAL); - return 0; -} - -/** - * client_fsetxattr - fsetxattr function for client protocol - * @frame: call frame - * @this: this translator structure - * @fd: fd - * @dict: dictionary which contains key:value to be set. - * @flags: - * - * external reference through client_protocol_xlator->fops->fsetxattr - */ - -int -client_fsetxattr (call_frame_t *frame, xlator_t *this, fd_t *fd, - dict_t *dict, int32_t flags) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_fsetxattr_req_t *req = NULL; - size_t hdrlen = 0; - size_t dict_len = 0; - ino_t ino; - int ret = -1; - int64_t remote_fd = -1; - client_fd_ctx_t *fdctx = NULL; - client_conf_t *conf = NULL; - - conf = this->private; - - dict_len = dict_serialized_length (dict); - if (dict_len < 0) { - gf_log (this->name, GF_LOG_DEBUG, - "failed to get serialized length of dict(%p)", - dict); - goto unwind; - } - - pthread_mutex_lock (&conf->mutex); - { - fdctx = this_fd_get_ctx (fd, this); - } - pthread_mutex_unlock (&conf->mutex); - - if (fdctx == NULL) { - gf_log (this->name, GF_LOG_TRACE, - "(%"PRId64"): failed to get fd ctx. EBADFD", - fd->inode->ino); - goto unwind; - } - - if (fdctx->remote_fd == -1) { - gf_log (this->name, GF_LOG_TRACE, - "(%"PRId64"): failed to get fd ctx. EBADFD", - fd->inode->ino); - goto unwind; - } - - ino = fd->inode->ino; - remote_fd = fdctx->remote_fd; - - hdrlen = gf_hdr_len (req, dict_len); - hdr = gf_hdr_new (req, dict_len); - - GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - - req = gf_param (hdr); - - req->ino = hton64 (ino); - req->fd = hton64 (remote_fd); - req->flags = hton32 (flags); - req->dict_len = hton32 (dict_len); - - ret = dict_serialize (dict, req->dict); - if (ret < 0) { - gf_log (this->name, GF_LOG_DEBUG, - "failed to serialize dictionary(%p)", - dict); - goto unwind; - } - - ret = protocol_client_xfer (frame, this, - CLIENT_CHANNEL (this, CHANNEL_BULK), - GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_FSETXATTR, - hdr, hdrlen, NULL, 0, NULL); - return ret; -unwind: - if (hdr) - GF_FREE (hdr); - - STACK_UNWIND (frame, -1, EINVAL); - return 0; -} - -/** - * client_getxattr - getxattr function for client protocol - * @frame: call frame - * @this: this translator structure - * @loc: location structure - * - * external reference through client_protocol_xlator->fops->getxattr - */ - -int -client_getxattr (call_frame_t *frame, xlator_t *this, loc_t *loc, - const char *name) -{ - int ret = -1; - gf_hdr_common_t *hdr = NULL; - gf_fop_getxattr_req_t *req = NULL; - size_t hdrlen = 0; - size_t pathlen = 0; - size_t namelen = 0; - ino_t ino = 0; - uint64_t gen = 0; - - pathlen = STRLEN_0 (loc->path); - if (name) - namelen = STRLEN_0 (name); - - ret = inode_ctx_get2 (loc->inode, this, &ino, &gen); - if (loc->inode->ino && ret < 0) { - gf_log (this->name, GF_LOG_DEBUG, - "GETXATTR %"PRId64" (%s): " - "failed to get remote inode number", - loc->inode->ino, loc->path); - goto unwind; - } - - hdrlen = gf_hdr_len (req, pathlen + namelen); - hdr = gf_hdr_new (req, pathlen + namelen); - GF_VALIDATE_OR_GOTO (frame->this->name, hdr, unwind); - - req = gf_param (hdr); - - req->ino = hton64 (ino); - req->gen = hton64 (gen); - req->namelen = hton32 (namelen); - strcpy (req->path, loc->path); - if (name) - strcpy (req->name + pathlen, name); - - ret = protocol_client_xfer (frame, this, - CLIENT_CHANNEL (this, CHANNEL_LOWLAT), - GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_GETXATTR, - hdr, hdrlen, NULL, 0, NULL); - return ret; -unwind: - if (hdr) - GF_FREE (hdr); - - STACK_UNWIND (frame, -1, EINVAL, NULL); - return 0; -} - - -/** - * client_fgetxattr - fgetxattr function for client protocol - * @frame: call frame - * @this: this translator structure - * @fd: fd - * - * external reference through client_protocol_xlator->fops->fgetxattr - */ - -int -client_fgetxattr (call_frame_t *frame, xlator_t *this, fd_t *fd, - const char *name) -{ - int ret = -1; - gf_hdr_common_t *hdr = NULL; - gf_fop_fgetxattr_req_t *req = NULL; - size_t hdrlen = 0; - int64_t remote_fd = -1; - size_t namelen = 0; - ino_t ino = 0; - client_fd_ctx_t *fdctx = NULL; - client_conf_t *conf = NULL; - - if (name) - namelen = STRLEN_0 (name); - - conf = this->private; - - pthread_mutex_lock (&conf->mutex); - { - fdctx = this_fd_get_ctx (fd, this); - } - pthread_mutex_unlock (&conf->mutex); - - if (fdctx == NULL) { - gf_log (this->name, GF_LOG_TRACE, - "(%"PRId64"): failed to get remote fd. EBADFD", - fd->inode->ino); - goto unwind; - } - - if (fdctx->remote_fd == -1) { - gf_log (this->name, GF_LOG_TRACE, - "(%"PRId64"): failed to get fd ctx. EBADFD", - fd->inode->ino); - goto unwind; - } - - ino = fd->inode->ino; - remote_fd = fdctx->remote_fd; - - hdrlen = gf_hdr_len (req, namelen); - hdr = gf_hdr_new (req, namelen); - - GF_VALIDATE_OR_GOTO (frame->this->name, hdr, unwind); - - req = gf_param (hdr); - - req->ino = hton64 (ino); - req->fd = hton64 (remote_fd); - req->namelen = hton32 (namelen); - - if (name) - strcpy (req->name, name); - - ret = protocol_client_xfer (frame, this, - CLIENT_CHANNEL (this, CHANNEL_LOWLAT), - GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_FGETXATTR, - hdr, hdrlen, NULL, 0, NULL); - return ret; -unwind: - if (hdr) - GF_FREE (hdr); - - STACK_UNWIND (frame, -1, EINVAL, NULL); - return 0; -} - - -/** - * client_removexattr - removexattr function for client protocol - * @frame: call frame - * @this: this translator structure - * @loc: location structure - * @name: - * - * external reference through client_protocol_xlator->fops->removexattr - */ - -int -client_removexattr (call_frame_t *frame, xlator_t *this, loc_t *loc, - const char *name) -{ - int ret = -1; - gf_hdr_common_t *hdr = NULL; - gf_fop_removexattr_req_t *req = NULL; - size_t hdrlen = 0; - size_t namelen = 0; - size_t pathlen = 0; - ino_t ino = 0; - uint64_t gen = 0; - - pathlen = STRLEN_0 (loc->path); - namelen = STRLEN_0 (name); - - ret = inode_ctx_get2 (loc->inode, this, &ino, &gen); - if (loc->inode->ino && ret < 0) { - gf_log (this->name, GF_LOG_DEBUG, - "REMOVEXATTR %"PRId64" (%s): " - "failed to get remote inode number", - loc->inode->ino, loc->path); - goto unwind; - } - - hdrlen = gf_hdr_len (req, pathlen + namelen); - hdr = gf_hdr_new (req, pathlen + namelen); - GF_VALIDATE_OR_GOTO (frame->this->name, hdr, unwind); - - req = gf_param (hdr); - - req->ino = hton64 (ino); - req->gen = hton64 (gen); - strcpy (req->path, loc->path); - strcpy (req->name + pathlen, name); - - ret = protocol_client_xfer (frame, this, - CLIENT_CHANNEL (this, CHANNEL_LOWLAT), - GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_REMOVEXATTR, - hdr, hdrlen, NULL, 0, NULL); - return ret; -unwind: - if (hdr) - GF_FREE (hdr); - STACK_UNWIND (frame, -1, EINVAL); - return 0; -} - -/** - * client_opendir - opendir function for client protocol - * @frame: call frame - * @this: this translator structure - * @loc: location structure - * - * external reference through client_protocol_xlator->fops->opendir - */ - -int -client_opendir (call_frame_t *frame, xlator_t *this, loc_t *loc, - fd_t *fd) -{ - gf_fop_opendir_req_t *req = NULL; - gf_hdr_common_t *hdr = NULL; - size_t hdrlen = 0; - int ret = -1; - ino_t ino = 0; - uint64_t gen = 0; - size_t pathlen = 0; - client_local_t *local = NULL; - - local = GF_CALLOC (1, sizeof (*local), gf_client_mt_client_local_t); - GF_VALIDATE_OR_GOTO (this->name, local, unwind); - - loc_copy (&local->loc, loc); - local->fd = fd_ref (fd); - - frame->local = local; - - ret = inode_ctx_get2 (loc->inode, this, &ino, &gen); - if (loc->inode->ino && ret < 0) { - gf_log (this->name, GF_LOG_DEBUG, - "OPENDIR %"PRId64" (%s): " - "failed to get remote inode number", - loc->inode->ino, loc->path); - goto unwind; - } - - pathlen = STRLEN_0 (loc->path); - - hdrlen = gf_hdr_len (req, pathlen); - hdr = gf_hdr_new (req, pathlen); - GF_VALIDATE_OR_GOTO (frame->this->name, hdr, unwind); - - req = gf_param (hdr); - - req->ino = hton64 (ino); - req->gen = hton64 (gen); - strcpy (req->path, loc->path); - - ret = protocol_client_xfer (frame, this, - CLIENT_CHANNEL (this, CHANNEL_LOWLAT), - GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_OPENDIR, - hdr, hdrlen, NULL, 0, NULL); - - return ret; -unwind: - if (hdr) - GF_FREE (hdr); - STACK_UNWIND (frame, -1, EINVAL, fd); - return 0; - -} - -/** - * client_readdirp - readdirp function for client protocol - * @frame: call frame - * @this: this translator structure - * - * external reference through client_protocol_xlator->fops->readdirp - */ - -int -client_readdirp (call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size, - off_t offset) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_readdirp_req_t *req = NULL; - size_t hdrlen = 0; - int64_t remote_fd = -1; - int ret = -1; - client_fd_ctx_t *fdctx = NULL; - client_conf_t *conf = NULL; - - conf = this->private; - - pthread_mutex_lock (&conf->mutex); - { - fdctx = this_fd_get_ctx (fd, this); - } - pthread_mutex_unlock (&conf->mutex); - - if (fdctx == NULL) { - gf_log (this->name, GF_LOG_TRACE, "(%"PRId64"): failed to get" - " fd ctx. EBADFD", fd->inode->ino); - goto unwind; - } - - if (fdctx->remote_fd == -1) { - gf_log (this->name, GF_LOG_TRACE, "(%"PRId64"): failed to get" - " fd ctx. EBADFD", fd->inode->ino); - goto unwind; - } - - remote_fd = fdctx->remote_fd; - hdrlen = gf_hdr_len (req, 0); - hdr = gf_hdr_new (req, 0); - GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - - req = gf_param (hdr); - GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - - req->fd = hton64 (remote_fd); - req->size = hton32 (size); - req->offset = hton64 (offset); - - ret = protocol_client_xfer (frame, this, - CLIENT_CHANNEL (this, CHANNEL_LOWLAT), - GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_READDIRP, - hdr, hdrlen, NULL, 0, NULL); - - return 0; -unwind: - if (hdr) - GF_FREE (hdr); - STACK_UNWIND (frame, -1, EBADFD, NULL); - return 0; - -} - - -/** - * client_readdir - readdir function for client protocol - * @frame: call frame - * @this: this translator structure - * - * external reference through client_protocol_xlator->fops->readdir - */ - -int -client_readdir (call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size, - off_t offset) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_readdir_req_t *req = NULL; - size_t hdrlen = 0; - int64_t remote_fd = -1; - int ret = -1; - client_fd_ctx_t *fdctx = NULL; - client_conf_t *conf = NULL; - - conf = this->private; - - pthread_mutex_lock (&conf->mutex); - { - fdctx = this_fd_get_ctx (fd, this); - } - pthread_mutex_unlock (&conf->mutex); - - if (fdctx == NULL) { - gf_log (this->name, GF_LOG_TRACE, - "(%"PRId64"): failed to get fd ctx. EBADFD", - fd->inode->ino); - goto unwind; - } - - if (fdctx->remote_fd == -1) { - gf_log (this->name, GF_LOG_TRACE, "(%"PRId64"): failed to get" - " fd ctx. EBADFD", fd->inode->ino); - goto unwind; - } - - remote_fd = fdctx->remote_fd; - hdrlen = gf_hdr_len (req, 0); - hdr = gf_hdr_new (req, 0); - GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - - req = gf_param (hdr); - GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - - req->fd = hton64 (remote_fd); - req->size = hton32 (size); - req->offset = hton64 (offset); - - ret = protocol_client_xfer (frame, this, - CLIENT_CHANNEL (this, CHANNEL_LOWLAT), - GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_READDIR, - hdr, hdrlen, NULL, 0, NULL); - - return 0; -unwind: - if (hdr) - GF_FREE (hdr); - STACK_UNWIND (frame, -1, EBADFD, NULL); - return 0; - -} - -/** - * client_fsyncdir - fsyncdir function for client protocol - * @frame: call frame - * @this: this translator structure - * @fd: file descriptor structure - * @flags: - * - * external reference through client_protocol_xlator->fops->fsyncdir - */ - -int -client_fsyncdir (call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t flags) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_fsyncdir_req_t *req = NULL; - size_t hdrlen = 0; - int64_t remote_fd = -1; - int32_t ret = -1; - client_fd_ctx_t *fdctx = NULL; - client_conf_t *conf = NULL; - - conf = this->private; - - pthread_mutex_lock (&conf->mutex); - { - fdctx = this_fd_get_ctx (fd, this); - } - pthread_mutex_unlock (&conf->mutex); - - if (fdctx == NULL) { - gf_log (this->name, GF_LOG_TRACE, - "(%"PRId64"): failed to get fd ctx. EBADFD", - fd->inode->ino); - goto unwind; - } - - if (fdctx->remote_fd == -1) { - gf_log (this->name, GF_LOG_TRACE, "(%"PRId64"): failed to get" - " fd ctx. EBADFD", fd->inode->ino); - goto unwind; - } - - remote_fd = fdctx->remote_fd; - hdrlen = gf_hdr_len (req, 0); - hdr = gf_hdr_new (req, 0); - GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - - req = gf_param (hdr); - - req->data = hton32 (flags); - req->fd = hton64 (remote_fd); - - ret = protocol_client_xfer (frame, this, - CLIENT_CHANNEL (this, CHANNEL_BULK), - GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_FSYNCDIR, - hdr, hdrlen, NULL, 0, NULL); - - return ret; -unwind: - STACK_UNWIND (frame, -1, EBADFD); - return 0; -} - -/** - * client_access - access function for client protocol - * @frame: call frame - * @this: this translator structure - * @loc: location structure - * @mode: - * - * external reference through client_protocol_xlator->fops->access - */ - -int -client_access (call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t mask) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_access_req_t *req = NULL; - size_t hdrlen = -1; - int ret = -1; - ino_t ino = 0; - uint64_t gen = 0; - size_t pathlen = 0; - - ret = inode_ctx_get2 (loc->inode, this, &ino, &gen); - if (loc->inode->ino && ret < 0) { - gf_log (this->name, GF_LOG_DEBUG, - "ACCESS %"PRId64" (%s): " - "failed to get remote inode number", - loc->inode->ino, loc->path); - goto unwind; - } - - pathlen = STRLEN_0 (loc->path); - - hdrlen = gf_hdr_len (req, pathlen); - hdr = gf_hdr_new (req, pathlen); - GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - - req = gf_param (hdr); - - req->ino = hton64 (ino); - req->gen = hton64 (gen); - req->mask = hton32 (mask); - strcpy (req->path, loc->path); - - ret = protocol_client_xfer (frame, this, - CLIENT_CHANNEL (this, CHANNEL_LOWLAT), - GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_ACCESS, - hdr, hdrlen, NULL, 0, NULL); - - return ret; -unwind: - if (hdr) - GF_FREE (hdr); - - STACK_UNWIND (frame, -1, EINVAL); - return 0; - -} - -/** - * client_ftrucate - ftruncate function for client protocol - * @frame: call frame - * @this: this translator structure - * @fd: file descriptor structure - * @offset: offset to truncate to - * - * external reference through client_protocol_xlator->fops->ftruncate - */ - -int -client_ftruncate (call_frame_t *frame, xlator_t *this, fd_t *fd, - off_t offset) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_ftruncate_req_t *req = NULL; - int64_t remote_fd = -1; - size_t hdrlen = -1; - int ret = -1; - client_fd_ctx_t *fdctx = NULL; - client_conf_t *conf = NULL; - - conf = this->private; - - pthread_mutex_lock (&conf->mutex); - { - fdctx = this_fd_get_ctx (fd, this); - } - pthread_mutex_unlock (&conf->mutex); - - if (fdctx == NULL) { - gf_log (this->name, GF_LOG_TRACE, - "(%"PRId64"): failed to get fd ctx. EBADFD", - fd->inode->ino); - STACK_UNWIND (frame, -1, EBADFD, NULL); - return 0; - } - - if (fdctx->remote_fd == -1) { - gf_log (this->name, GF_LOG_TRACE, "(%"PRId64"): failed to get" - " fd ctx. EBADFD", fd->inode->ino); - goto unwind; - } - - remote_fd = fdctx->remote_fd; - hdrlen = gf_hdr_len (req, 0); - hdr = gf_hdr_new (req, 0); - GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - - req = gf_param (hdr); - - req->fd = hton64 (remote_fd); - req->offset = hton64 (offset); - - ret = protocol_client_xfer (frame, this, - CLIENT_CHANNEL (this, CHANNEL_BULK), - GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_FTRUNCATE, - hdr, hdrlen, NULL, 0, NULL); - - return ret; -unwind: - if (hdr) - GF_FREE (hdr); - - STACK_UNWIND (frame, -1, EINVAL, NULL); - return 0; - -} - -/** - * client_fstat - fstat function for client protocol - * @frame: call frame - * @this: this translator structure - * @fd: file descriptor structure - * - * external reference through client_protocol_xlator->fops->fstat - */ - -int -client_fstat (call_frame_t *frame, xlator_t *this, fd_t *fd) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_fstat_req_t *req = NULL; - int64_t remote_fd = -1; - size_t hdrlen = -1; - int ret = -1; - client_fd_ctx_t *fdctx = NULL; - client_conf_t *conf = NULL; - - conf = this->private; - - pthread_mutex_lock (&conf->mutex); - { - fdctx = this_fd_get_ctx (fd, this); - } - pthread_mutex_unlock (&conf->mutex); - - if (fdctx == NULL) { - gf_log (this->name, GF_LOG_TRACE, - "(%"PRId64"): failed to get fd ctx. EBADFD", - fd->inode->ino); - STACK_UNWIND (frame, -1, EBADFD, NULL); - return 0; - } - - if (fdctx->remote_fd == -1) { - gf_log (this->name, GF_LOG_TRACE, "(%"PRId64"): failed to get" - " fd ctx. EBADFD", fd->inode->ino); - goto unwind; - } - - remote_fd = fdctx->remote_fd; - hdrlen = gf_hdr_len (req, 0); - hdr = gf_hdr_new (req, 0); - GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - - req = gf_param (hdr); - - req->fd = hton64 (remote_fd); - - ret = protocol_client_xfer (frame, this, - CLIENT_CHANNEL (this, CHANNEL_BULK), - GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_FSTAT, - hdr, hdrlen, NULL, 0, NULL); - - return ret; -unwind: - if (hdr) - GF_FREE (hdr); - - STACK_UNWIND (frame, -1, EINVAL, NULL); - return 0; - -} - -/** - * client_lk - lk function for client protocol - * @frame: call frame - * @this: this translator structure - * @fd: file descriptor structure - * @cmd: lock command - * @lock: - * - * external reference through client_protocol_xlator->fops->lk - */ - -int -client_lk (call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t cmd, - struct flock *flock) -{ - int ret = -1; - gf_hdr_common_t *hdr = NULL; - gf_fop_lk_req_t *req = NULL; - size_t hdrlen = 0; - int64_t remote_fd = -1; - int32_t gf_cmd = 0; - int32_t gf_type = 0; - client_fd_ctx_t *fdctx = NULL; - client_conf_t *conf = NULL; - - conf = this->private; - - pthread_mutex_lock (&conf->mutex); - { - fdctx = this_fd_get_ctx (fd, this); - } - pthread_mutex_unlock (&conf->mutex); - - if (fdctx == NULL) { - gf_log (this->name, GF_LOG_TRACE, - "(%"PRId64"): failed to get fd ctx. EBADFD", - fd->inode->ino); - STACK_UNWIND (frame, -1, EBADFD, NULL); - return 0; - } - - if (fdctx->remote_fd == -1) { - gf_log (this->name, GF_LOG_TRACE, "(%"PRId64"): failed to get" - " fd ctx. EBADFD", fd->inode->ino); - STACK_UNWIND (frame, -1, EBADFD, NULL); - return 0; - } - - remote_fd = fdctx->remote_fd; - 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_log (this->name, GF_LOG_DEBUG, - "Unknown cmd (%d)!", gf_cmd); - goto unwind; - } - - 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; - } - - hdrlen = gf_hdr_len (req, 0); - hdr = gf_hdr_new (req, 0); - GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - - req = gf_param (hdr); - - req->fd = hton64 (remote_fd); - req->cmd = hton32 (gf_cmd); - req->type = hton32 (gf_type); - gf_flock_from_flock (&req->flock, flock); - - ret = protocol_client_xfer (frame, this, - CLIENT_CHANNEL (this, CHANNEL_BULK), - GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_LK, - hdr, hdrlen, NULL, 0, NULL); - return ret; -unwind: - if (hdr) - GF_FREE (hdr); - - STACK_UNWIND (frame, -1, EINVAL, NULL); - return 0; -} - -/** - * client_inodelk - inodelk function for client protocol - * @frame: call frame - * @this: this translator structure - * @inode: inode structure - * @cmd: lock command - * @lock: flock struct - * - * external reference through client_protocol_xlator->fops->inodelk - */ - -int -client_inodelk (call_frame_t *frame, xlator_t *this, const char *volume, - loc_t *loc, int32_t cmd, struct flock *flock) -{ - int ret = -1; - gf_hdr_common_t *hdr = NULL; - gf_fop_inodelk_req_t *req = NULL; - size_t hdrlen = 0; - int32_t gf_cmd = 0; - int32_t gf_type = 0; - ino_t ino = 0; - uint64_t gen = 0; - size_t pathlen = 0; - size_t vollen = 0; - - pathlen = STRLEN_0 (loc->path); - vollen = STRLEN_0 (volume); - - ret = inode_ctx_get2 (loc->inode, this, &ino, &gen); - if (loc->inode->ino && ret < 0) { - gf_log (this->name, GF_LOG_DEBUG, - "INODELK %"PRId64" (%s): " - "failed to get remote inode number", - loc->inode->ino, loc->path); - goto unwind; - } - - 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_log (this->name, GF_LOG_DEBUG, - "Unknown cmd (%d)!", gf_cmd); - goto unwind; - } - - 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; - } - - hdrlen = gf_hdr_len (req, pathlen + vollen); - hdr = gf_hdr_new (req, pathlen + vollen); - GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - - req = gf_param (hdr); - - strcpy (req->path, loc->path); - strcpy (req->path + pathlen, volume); - - req->ino = hton64 (ino); - req->gen = hton64 (gen); - - req->cmd = hton32 (gf_cmd); - req->type = hton32 (gf_type); - gf_flock_from_flock (&req->flock, flock); - - - ret = protocol_client_xfer (frame, this, - CLIENT_CHANNEL (this, CHANNEL_BULK), - GF_OP_TYPE_FOP_REQUEST, - GF_PROTO_FOP_INODELK, - hdr, hdrlen, NULL, 0, NULL); - return ret; -unwind: - if (hdr) - GF_FREE (hdr); - - STACK_UNWIND (frame, -1, EINVAL); - return 0; - -} - - -/** - * client_finodelk - finodelk function for client protocol - * @frame: call frame - * @this: this translator structure - * @inode: inode structure - * @cmd: lock command - * @lock: flock struct - * - * external reference through client_protocol_xlator->fops->finodelk - */ - -int -client_finodelk (call_frame_t *frame, xlator_t *this, const char *volume, - fd_t *fd, int32_t cmd, struct flock *flock) -{ - int ret = -1; - gf_hdr_common_t *hdr = NULL; - gf_fop_finodelk_req_t *req = NULL; - size_t hdrlen = 0; - size_t vollen = 0; - int32_t gf_cmd = 0; - int32_t gf_type = 0; - int64_t remote_fd = -1; - client_fd_ctx_t *fdctx = NULL; - client_conf_t *conf = NULL; - - vollen = STRLEN_0 (volume); - - conf = this->private; - - pthread_mutex_lock (&conf->mutex); - { - fdctx = this_fd_get_ctx (fd, this); - } - pthread_mutex_unlock (&conf->mutex); - - if (fdctx == NULL) { - gf_log (this->name, GF_LOG_TRACE, - "(%"PRId64"): failed to get fd ctx. EBADFD", - fd->inode->ino); - STACK_UNWIND (frame, -1, EBADFD); - return 0; - } - - if (fdctx->remote_fd == -1) { - gf_log (this->name, GF_LOG_TRACE, - "(%"PRId64"): failed to get fd ctx. EBADFD", - fd->inode->ino); - STACK_UNWIND (frame, -1, EBADFD); - return 0; - } - - remote_fd = fdctx->remote_fd; - 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_log (this->name, GF_LOG_DEBUG, - "Unknown cmd (%d)!", gf_cmd); - goto unwind; - } - - 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; - } - - hdrlen = gf_hdr_len (req, vollen); - hdr = gf_hdr_new (req, vollen); - GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - - req = gf_param (hdr); - - strcpy (req->volume, volume); - - req->fd = hton64 (remote_fd); - - req->cmd = hton32 (gf_cmd); - req->type = hton32 (gf_type); - gf_flock_from_flock (&req->flock, flock); - - ret = protocol_client_xfer (frame, this, - CLIENT_CHANNEL (this, CHANNEL_BULK), - GF_OP_TYPE_FOP_REQUEST, - GF_PROTO_FOP_FINODELK, - hdr, hdrlen, NULL, 0, NULL); - return ret; -unwind: - if (hdr) - GF_FREE (hdr); - - STACK_UNWIND (frame, -1, EINVAL); - return 0; -} - - -int -client_entrylk (call_frame_t *frame, xlator_t *this, const char *volume, - loc_t *loc, const char *name, entrylk_cmd cmd, - entrylk_type type) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_entrylk_req_t *req = NULL; - size_t pathlen = 0; - size_t vollen = 0; - size_t hdrlen = -1; - int ret = -1; - ino_t ino = 0; - uint64_t gen = 0; - size_t namelen = 0; - - pathlen = STRLEN_0 (loc->path); - vollen = STRLEN_0 (volume); - - if (name) - namelen = STRLEN_0 (name); - - ret = inode_ctx_get2 (loc->inode, this, &ino, &gen); - if (loc->inode->ino && ret < 0) { - gf_log (this->name, GF_LOG_DEBUG, - "ENTRYLK %"PRId64" (%s): " - "failed to get remote inode number", - loc->inode->ino, loc->path); - goto unwind; - } - - hdrlen = gf_hdr_len (req, pathlen + vollen + namelen); - hdr = gf_hdr_new (req, pathlen + vollen + namelen); - GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - - req = gf_param (hdr); - - req->ino = hton64 (ino); - req->gen = hton64 (gen); - req->namelen = hton64 (namelen); - - strcpy (req->path, loc->path); - if (name) - strcpy (req->name + pathlen, name); - strcpy (req->volume + pathlen + namelen, volume); - - req->cmd = hton32 (cmd); - req->type = hton32 (type); - - ret = protocol_client_xfer (frame, this, - CLIENT_CHANNEL (this, CHANNEL_LOWLAT), - GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_ENTRYLK, - hdr, hdrlen, NULL, 0, NULL); - - return ret; -unwind: - if (hdr) - GF_FREE (hdr); - - STACK_UNWIND (frame, -1, EINVAL); - return 0; - -} - - -int -client_fentrylk (call_frame_t *frame, xlator_t *this, const char *volume, - fd_t *fd, const char *name, entrylk_cmd cmd, - entrylk_type type) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_fentrylk_req_t *req = NULL; - int64_t remote_fd = -1; - size_t vollen = 0; - size_t namelen = 0; - size_t hdrlen = -1; - int ret = -1; - client_fd_ctx_t *fdctx = NULL; - client_conf_t *conf = NULL; - - if (name) - namelen = STRLEN_0 (name); - - conf = this->private; - - vollen = STRLEN_0 (volume); - - pthread_mutex_lock (&conf->mutex); - { - fdctx = this_fd_get_ctx (fd, this); - } - pthread_mutex_unlock (&conf->mutex); - - if (fdctx == NULL) { - gf_log (this->name, GF_LOG_DEBUG, - "(%"PRId64"): failed to get fd ctx. EBADFD", - fd->inode->ino); - STACK_UNWIND (frame, -1, EBADFD); - return 0; - } - - if (fdctx->remote_fd == -1) { - gf_log (this->name, GF_LOG_DEBUG, - "(%"PRId64"): failed to get fd ctx. EBADFD", - fd->inode->ino); - STACK_UNWIND (frame, -1, EBADFD); - return 0; - } - - remote_fd = fdctx->remote_fd; - hdrlen = gf_hdr_len (req, namelen + vollen); - hdr = gf_hdr_new (req, namelen + vollen); - GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - - req = gf_param (hdr); - - req->fd = hton64 (remote_fd); - req->namelen = hton64 (namelen); - - if (name) - strcpy (req->name, name); - - strcpy (req->volume + namelen, volume); - - req->cmd = hton32 (cmd); - req->type = hton32 (type); - - ret = protocol_client_xfer (frame, this, - CLIENT_CHANNEL (this, CHANNEL_LOWLAT), - GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_FENTRYLK, - hdr, hdrlen, NULL, 0, NULL); - - return ret; -unwind: - if (hdr) - GF_FREE (hdr); - - STACK_UNWIND (frame, -1, EINVAL); - return 0; -} - -/* - * client_lookup - lookup function for client protocol - * @frame: call frame - * @this: - * @loc: location - * - * not for external reference - */ - -int -client_lookup (call_frame_t *frame, xlator_t *this, loc_t *loc, - dict_t *xattr_req) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_lookup_req_t *req = NULL; - size_t hdrlen = -1; - int ret = -1; - ino_t ino = 0; - ino_t par = 0; - uint64_t gen = 0; - size_t dictlen = 0; - size_t pathlen = 0; - size_t baselen = 0; - int32_t op_ret = -1; - int32_t op_errno = EINVAL; - client_local_t *local = NULL; - char *buf = NULL; - - GF_VALIDATE_OR_GOTO (this->name, loc, unwind); - GF_VALIDATE_OR_GOTO (this->name, loc->path, unwind); - - local = GF_CALLOC (1, sizeof (*local), gf_client_mt_client_local_t); - GF_VALIDATE_OR_GOTO (this->name, local, unwind); - - loc_copy (&local->loc, loc); - - frame->local = local; - - if (loc->ino != 1 && loc->parent) { - ret = inode_ctx_get2 (loc->parent, this, &par, &gen); - if (loc->parent->ino && ret < 0) { - gf_log (this->name, GF_LOG_TRACE, - "LOOKUP %"PRId64"/%s (%s): failed to get " - "remote inode number for parent", - loc->parent->ino, loc->name, loc->path); - goto unwind; - } - GF_VALIDATE_OR_GOTO (this->name, loc->name, unwind); - baselen = STRLEN_0 (loc->name); - } else { - ino = 1; - } - - pathlen = STRLEN_0 (loc->path); - - if (xattr_req) { - ret = dict_allocate_and_serialize (xattr_req, &buf, &dictlen); - if (ret < 0) { - gf_log (this->name, GF_LOG_DEBUG, - "failed to get serialized length of dict(%p)", - xattr_req); - goto unwind; - } - } - - hdrlen = gf_hdr_len (req, pathlen + baselen + dictlen); - hdr = gf_hdr_new (req, pathlen + baselen + dictlen); - GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - - req = gf_param (hdr); - - req->ino = hton64 (ino); - req->gen = hton64 (gen); - req->par = hton64 (par); - strcpy (req->path, loc->path); - if (baselen) - strcpy (req->path + pathlen, loc->name); - - if (dictlen > 0) { - memcpy (req->dict + pathlen + baselen, buf, dictlen); - GF_FREE (buf); - } - - req->dictlen = hton32 (dictlen); - - ret = protocol_client_xfer (frame, this, - CLIENT_CHANNEL (this, CHANNEL_LOWLAT), - GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_LOOKUP, - hdr, hdrlen, NULL, 0, NULL); - return ret; - -unwind: - STACK_UNWIND (frame, op_ret, op_errno, (loc)?loc->inode:NULL, NULL, NULL); - return ret; -} - - -int -client_setattr (call_frame_t *frame, xlator_t *this, loc_t *loc, - struct iatt *stbuf, int32_t valid) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_setattr_req_t *req = NULL; - size_t hdrlen = 0; - size_t pathlen = 0; - ino_t ino = 0; - uint64_t gen = 0; - int ret = -1; - - GF_VALIDATE_OR_GOTO ("client", this, unwind); - GF_VALIDATE_OR_GOTO (this->name, frame, unwind); - - pathlen = STRLEN_0 (loc->path); - - ret = inode_ctx_get2 (loc->inode, this, &ino, &gen); - if (loc->inode->ino && ret < 0) { - gf_log (this->name, GF_LOG_TRACE, - "SETATTR %"PRId64" (%s): " - "failed to get remote inode number", - loc->inode->ino, loc->path); - goto unwind; - } - - hdrlen = gf_hdr_len (req, pathlen); - hdr = gf_hdr_new (req, pathlen); - GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - - req = gf_param (hdr); - - req->ino = hton64 (ino); - req->gen = hton64 (gen); - strcpy (req->path, loc->path); - - gf_stat_from_iatt (&req->stbuf, stbuf); - req->valid = hton32 (valid); - - ret = protocol_client_xfer (frame, this, - CLIENT_CHANNEL (this, CHANNEL_BULK), - GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_SETATTR, - hdr, hdrlen, NULL, 0, NULL); - - return ret; -unwind: - STACK_UNWIND (frame, -1, EINVAL, NULL); - return 0; -} - - -int -client_fsetattr (call_frame_t *frame, xlator_t *this, fd_t *fd, - struct iatt *stbuf, int32_t valid) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_fsetattr_req_t *req = NULL; - size_t hdrlen = 0; - int ret = -1; - client_fd_ctx_t *fdctx = NULL; - int64_t remote_fd = -1; - client_conf_t *conf = NULL; - - GF_VALIDATE_OR_GOTO ("client", this, unwind); - GF_VALIDATE_OR_GOTO (this->name, frame, unwind); - - conf = this->private; - - pthread_mutex_lock (&conf->mutex); - { - fdctx = this_fd_get_ctx (fd, this); - } - pthread_mutex_unlock (&conf->mutex); - - if (fdctx == NULL) { - gf_log (this->name, GF_LOG_TRACE, - "(%"PRId64"): failed to get fd ctx. EBADFD", - fd->inode->ino); - STACK_UNWIND (frame, -1, EBADFD, NULL, NULL); - return 0; - } - - if (fdctx->remote_fd == -1) { - gf_log (this->name, GF_LOG_TRACE, - "(%"PRId64"): failed to get fd ctx. EBADFD", - fd->inode->ino); - STACK_UNWIND (frame, -1, EBADFD, NULL, NULL); - return 0; - } - - remote_fd = fdctx->remote_fd; - hdrlen = gf_hdr_len (req, 0); - hdr = gf_hdr_new (req, 0); - GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - - req = gf_param (hdr); - - req->fd = hton64 (remote_fd); - - gf_stat_from_iatt (&req->stbuf, stbuf); - req->valid = hton32 (valid); - - ret = protocol_client_xfer (frame, this, - CLIENT_CHANNEL (this, CHANNEL_BULK), - GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_FSETATTR, - hdr, hdrlen, NULL, 0, NULL); - - return ret; -unwind: - STACK_UNWIND (frame, -1, EINVAL, NULL, NULL); - return 0; -} - - -int -client_fdctx_destroy (xlator_t *this, client_fd_ctx_t *fdctx) -{ - call_frame_t *fr = NULL; - int32_t ret = -1; - gf_hdr_common_t *hdr = NULL; - size_t hdrlen = 0; - gf_cbk_release_req_t *req = NULL; - gf_cbk_releasedir_req_t *reqdir = NULL; - int64_t remote_fd = -1; - int op = 0; - - remote_fd = fdctx->remote_fd; - - if (remote_fd == -1) - goto out; - - if (fdctx->is_dir) { - hdrlen = gf_hdr_len (reqdir, 0); - hdr = gf_hdr_new (reqdir, 0); - op = GF_CBK_RELEASEDIR; - reqdir = gf_param (hdr); - reqdir->fd = hton64 (remote_fd); - } else { - hdrlen = gf_hdr_len (req, 0); - hdr = gf_hdr_new (req, 0); - op = GF_CBK_RELEASE; - req = gf_param (hdr); - req->fd = hton64 (remote_fd); - } - - fr = create_frame (this, this->ctx->pool); - - ret = protocol_client_xfer (fr, this, - CLIENT_CHANNEL (this, CHANNEL_BULK), - GF_OP_TYPE_CBK_REQUEST, op, - hdr, hdrlen, NULL, 0, NULL); - -out: - inode_unref (fdctx->inode); - GF_FREE (fdctx); - - return ret; -} - - -/** - * client_releasedir - releasedir function for client protocol - * @this: this translator structure - * @fd: file descriptor structure - * - * external reference through client_protocol_xlator->cbks->releasedir - */ - -int -client_releasedir (xlator_t *this, fd_t *fd) -{ - int64_t remote_fd = -1; - client_conf_t *conf = NULL; - client_fd_ctx_t *fdctx = NULL; - - conf = this->private; - - pthread_mutex_lock (&conf->mutex); - { - fdctx = this_fd_del_ctx (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) - list_del_init (&fdctx->sfd_pos); - - fdctx->released = 1; - } - } - pthread_mutex_unlock (&conf->mutex); - - if (remote_fd != -1) - client_fdctx_destroy (this, fdctx); - - return 0; -} - - -/** - * client_release - release function for client protocol - * @this: this translator structure - * @fd: file descriptor structure - * - * external reference through client_protocol_xlator->cbks->release - * - */ -int -client_release (xlator_t *this, fd_t *fd) -{ - int64_t remote_fd = -1; - client_conf_t *conf = NULL; - client_fd_ctx_t *fdctx = NULL; - - conf = this->private; - - pthread_mutex_lock (&conf->mutex); - { - fdctx = this_fd_del_ctx (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) - list_del_init (&fdctx->sfd_pos); - - fdctx->released = 1; - } - } - pthread_mutex_unlock (&conf->mutex); - - if (remote_fd != -1) - client_fdctx_destroy (this, fdctx); - - return 0; -} - -/* - * MGMT_OPS - */ - -/* Callbacks */ - -int -client_fxattrop_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_fop_xattrop_rsp_t *rsp = NULL; - int32_t op_ret = 0; - int32_t gf_errno = 0; - int32_t op_errno = 0; - int32_t dict_len = 0; - dict_t *dict = NULL; - int32_t ret = -1; - char *dictbuf = NULL; - - rsp = gf_param (hdr); - GF_VALIDATE_OR_GOTO (frame->this->name, rsp, fail); - - op_ret = ntoh32 (hdr->rsp.op_ret); - - if (op_ret >= 0) { - op_ret = -1; - dict_len = ntoh32 (rsp->dict_len); - - if (dict_len > 0) { - dictbuf = memdup (rsp->dict, dict_len); - GF_VALIDATE_OR_GOTO (frame->this->name, dictbuf, fail); - - dict = dict_new(); - GF_VALIDATE_OR_GOTO (frame->this->name, dict, fail); - - ret = dict_unserialize (dictbuf, dict_len, &dict); - if (ret < 0) { - gf_log (frame->this->name, GF_LOG_DEBUG, - "failed to serialize dictionary(%p)", - dict); - op_errno = -ret; - goto fail; - } else { - dict->extra_free = dictbuf; - dictbuf = NULL; - } - } - op_ret = 0; - } - gf_errno = ntoh32 (hdr->rsp.op_errno); - op_errno = gf_error_to_errno (gf_errno); - -fail: - STACK_UNWIND (frame, op_ret, op_errno, dict); - - if (dictbuf) - GF_FREE (dictbuf); - - if (dict) - dict_unref (dict); - - return 0; -} - - -int -client_xattrop_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_fop_xattrop_rsp_t *rsp = NULL; - int32_t op_ret = -1; - int32_t gf_errno = EINVAL; - int32_t op_errno = 0; - int32_t dict_len = 0; - dict_t *dict = NULL; - int32_t ret = -1; - char *dictbuf = NULL; - - rsp = gf_param (hdr); - GF_VALIDATE_OR_GOTO (frame->this->name, rsp, fail); - - op_ret = ntoh32 (hdr->rsp.op_ret); - if (op_ret >= 0) { - op_ret = -1; - dict_len = ntoh32 (rsp->dict_len); - - if (dict_len > 0) { - dictbuf = memdup (rsp->dict, dict_len); - GF_VALIDATE_OR_GOTO (frame->this->name, dictbuf, fail); - - dict = get_new_dict(); - GF_VALIDATE_OR_GOTO (frame->this->name, dict, fail); - dict_ref (dict); - - ret = dict_unserialize (dictbuf, dict_len, &dict); - if (ret < 0) { - gf_log (frame->this->name, GF_LOG_DEBUG, - "failed to serialize dictionary(%p)", - dict); - goto fail; - } else { - dict->extra_free = dictbuf; - dictbuf = NULL; - } - } - op_ret = 0; - } - gf_errno = ntoh32 (hdr->rsp.op_errno); - op_errno = gf_error_to_errno (gf_errno); - - -fail: - STACK_UNWIND (frame, op_ret, op_errno, dict); - - if (dictbuf) - GF_FREE (dictbuf); - if (dict) - dict_unref (dict); - - return 0; -} - -/* - * client_create_cbk - create callback function for client protocol - * @frame: call frame - * @args: arguments in dictionary - * - * not for external reference - */ - -int -client_create_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_fop_create_rsp_t *rsp = NULL; - int32_t op_ret = 0; - int32_t op_errno = 0; - fd_t *fd = NULL; - inode_t *inode = NULL; - struct iatt stbuf = {0, }; - struct iatt preparent = {0, }; - struct iatt postparent = {0, }; - int64_t remote_fd = 0; - int32_t ret = -1; - client_local_t *local = NULL; - client_conf_t *conf = NULL; - client_fd_ctx_t *fdctx = NULL; - ino_t ino = 0; - uint64_t gen = 0; - - local = frame->local; frame->local = NULL; - conf = frame->this->private; - fd = local->fd; - inode = local->loc.inode; - - rsp = gf_param (hdr); - - op_ret = ntoh32 (hdr->rsp.op_ret); - op_errno = ntoh32 (hdr->rsp.op_errno); - - if (op_ret >= 0) { - remote_fd = ntoh64 (rsp->fd); - gf_stat_to_iatt (&rsp->stat, &stbuf); - - gf_stat_to_iatt (&rsp->preparent, &preparent); - gf_stat_to_iatt (&rsp->postparent, &postparent); - - ino = stbuf.ia_ino; - gen = stbuf.ia_gen; - } - - if (op_ret >= 0) { - ret = inode_ctx_put2 (local->loc.inode, frame->this, ino, gen); - - if (ret < 0) { - gf_log (frame->this->name, GF_LOG_DEBUG, - "CREATE %"PRId64"/%s (%s): failed to set " - "remote inode number to inode ctx", - local->loc.parent->ino, local->loc.name, - local->loc.path); - op_ret = -1; - op_errno = EINVAL; - goto unwind_out; - } - - fdctx = GF_CALLOC (1, sizeof (*fdctx), - gf_client_mt_client_fd_ctx_t); - if (!fdctx) { - op_ret = -1; - op_errno = ENOMEM; - goto unwind_out; - } - - fdctx->remote_fd = remote_fd; - fdctx->inode = inode_ref (fd->inode); - fdctx->ino = ino; - fdctx->gen = gen; - fdctx->flags = local->flags; - - INIT_LIST_HEAD (&fdctx->sfd_pos); - - this_fd_set_ctx (fd, frame->this, &local->loc, fdctx); - - pthread_mutex_lock (&conf->mutex); - { - list_add_tail (&fdctx->sfd_pos, &conf->saved_fds); - } - pthread_mutex_unlock (&conf->mutex); - } -unwind_out: - STACK_UNWIND (frame, op_ret, op_errno, fd, inode, &stbuf, - &preparent, &postparent); - - client_local_wipe (local); - - return 0; -} - - -/* - * client_open_cbk - open callback for client protocol - * @frame: call frame - * @args: argument dictionary - * - * not for external reference - */ -int -client_open_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - int32_t op_ret = -1; - int32_t op_errno = ENOTCONN; - fd_t *fd = NULL; - int64_t remote_fd = 0; - gf_fop_open_rsp_t *rsp = NULL; - client_local_t *local = NULL; - client_conf_t *conf = NULL; - client_fd_ctx_t *fdctx = NULL; - ino_t ino = 0; - uint64_t gen = 0; - - - local = frame->local; - - if (local->op) { - local->op (frame, hdr, hdrlen, iobuf); - return 0; - } - - frame->local = NULL; - conf = frame->this->private; - fd = local->fd; - - rsp = gf_param (hdr); - - op_ret = ntoh32 (hdr->rsp.op_ret); - op_errno = ntoh32 (hdr->rsp.op_errno); - - if (op_ret >= 0) { - remote_fd = ntoh64 (rsp->fd); - } - - if (op_ret >= 0) { - fdctx = GF_CALLOC (1, sizeof (*fdctx), - gf_client_mt_client_fd_ctx_t); - if (!fdctx) { - op_ret = -1; - op_errno = ENOMEM; - goto unwind_out; - } - - inode_ctx_get2 (fd->inode, frame->this, &ino, &gen); - - fdctx->remote_fd = remote_fd; - fdctx->inode = inode_ref (fd->inode); - fdctx->ino = ino; - fdctx->gen = gen; - fdctx->flags = local->flags; - fdctx->wbflags = local->wbflags; - - INIT_LIST_HEAD (&fdctx->sfd_pos); - - this_fd_set_ctx (fd, frame->this, &local->loc, fdctx); - - pthread_mutex_lock (&conf->mutex); - { - list_add_tail (&fdctx->sfd_pos, &conf->saved_fds); - } - pthread_mutex_unlock (&conf->mutex); - } -unwind_out: - STACK_UNWIND (frame, op_ret, op_errno, fd); - - client_local_wipe (local); - - return 0; -} - -/* - * client_stat_cbk - stat callback for client protocol - * @frame: call frame - * @args: arguments dictionary - * - * not for external reference - */ - -int -client_stat_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - struct iatt stbuf = {0, }; - gf_fop_stat_rsp_t *rsp = NULL; - int32_t op_ret = 0; - int32_t op_errno = 0; - - rsp = gf_param (hdr); - - op_ret = ntoh32 (hdr->rsp.op_ret); - op_errno = gf_error_to_errno (ntoh32 (hdr->rsp.op_errno)); - - if (op_ret == 0) { - gf_stat_to_iatt (&rsp->stat, &stbuf); - } - - STACK_UNWIND (frame, op_ret, op_errno, &stbuf); - - return 0; -} - - -/* - * client_mknod_cbk - mknod callback for client protocol - * @frame: call frame - * @args: argument dictionary - * - * not for external reference - */ - -int -client_mknod_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_fop_mknod_rsp_t *rsp = NULL; - int32_t op_ret = 0; - int32_t op_errno = 0; - struct iatt stbuf = {0, }; - inode_t *inode = NULL; - client_local_t *local = NULL; - int ret = 0; - struct iatt preparent = {0,}; - struct iatt postparent = {0,}; - - local = frame->local; - frame->local = NULL; - inode = local->loc.inode; - - rsp = gf_param (hdr); - - op_ret = ntoh32 (hdr->rsp.op_ret); - op_errno = gf_error_to_errno (ntoh32 (hdr->rsp.op_errno)); - - if (op_ret >= 0) { - gf_stat_to_iatt (&rsp->stat, &stbuf); - - ret = inode_ctx_put2 (local->loc.inode, frame->this, - stbuf.ia_ino, stbuf.ia_gen); - if (ret < 0) { - gf_log (frame->this->name, GF_LOG_DEBUG, - "MKNOD %"PRId64"/%s (%s): failed to set remote" - " inode number to inode ctx", - local->loc.parent->ino, local->loc.name, - local->loc.path); - - STACK_UNWIND (frame, -1, EINVAL, inode, NULL, - NULL, NULL); - return 0; - } - - gf_stat_to_iatt (&rsp->preparent, &preparent); - gf_stat_to_iatt (&rsp->postparent, &postparent); - } - - STACK_UNWIND (frame, op_ret, op_errno, inode, &stbuf, - &preparent, &postparent); - - client_local_wipe (local); - - return 0; -} - -/* - * client_symlink_cbk - symlink callback for client protocol - * @frame: call frame - * @args: argument dictionary - * - * not for external reference - */ - -int -client_symlink_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_fop_symlink_rsp_t *rsp = NULL; - int32_t op_ret = 0; - int32_t op_errno = 0; - struct iatt stbuf = {0, }; - struct iatt preparent = {0,}; - struct iatt postparent = {0,}; - inode_t *inode = NULL; - client_local_t *local = NULL; - int ret = 0; - - local = frame->local; - frame->local = NULL; - inode = local->loc.inode; - - rsp = gf_param (hdr); - - op_ret = ntoh32 (hdr->rsp.op_ret); - op_errno = gf_error_to_errno (ntoh32 (hdr->rsp.op_errno)); - - if (op_ret >= 0) { - gf_stat_to_iatt (&rsp->stat, &stbuf); - - ret = inode_ctx_put2 (inode, frame->this, - stbuf.ia_ino, stbuf.ia_gen); - if (ret < 0) { - gf_log (frame->this->name, GF_LOG_DEBUG, - "SYMLINK %"PRId64"/%s (%s): failed to set " - "remote inode number to inode ctx", - local->loc.parent->ino, local->loc.name, - local->loc.path); - STACK_UNWIND (frame, -1, EINVAL, inode, NULL, - NULL, NULL); - return 0; - } - gf_stat_to_iatt (&rsp->preparent, &preparent); - gf_stat_to_iatt (&rsp->postparent, &postparent); - } - - STACK_UNWIND (frame, op_ret, op_errno, inode, &stbuf, - &preparent, &postparent); - - client_local_wipe (local); - - return 0; -} - -/* - * client_link_cbk - link callback for client protocol - * @frame: call frame - * @args: argument dictionary - * - * not for external reference - */ - -int -client_link_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_fop_link_rsp_t *rsp = NULL; - int32_t op_ret = 0; - int32_t op_errno = 0; - struct iatt stbuf = {0, }; - inode_t *inode = NULL; - client_local_t *local = NULL; - struct iatt preparent = {0,}; - struct iatt postparent = {0,}; - - local = frame->local; - frame->local = NULL; - inode = local->loc.inode; - - rsp = gf_param (hdr); - - op_ret = ntoh32 (hdr->rsp.op_ret); - op_errno = gf_error_to_errno (ntoh32 (hdr->rsp.op_errno)); - - if (op_ret >= 0) { - gf_stat_to_iatt (&rsp->stat, &stbuf); - - gf_stat_to_iatt (&rsp->preparent, &preparent); - gf_stat_to_iatt (&rsp->postparent, &postparent); - } - - STACK_UNWIND (frame, op_ret, op_errno, inode, &stbuf, - &preparent, &postparent); - - client_local_wipe (local); - - return 0; -} - -/* - * client_truncate_cbk - truncate callback for client protocol - * @frame: call frame - * @args: argument dictionary - * - * not for external reference - */ - -int -client_truncate_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_fop_truncate_rsp_t *rsp = NULL; - int32_t op_ret = 0; - int32_t op_errno = 0; - struct iatt prestat = {0, }; - struct iatt poststat = {0, }; - - rsp = gf_param (hdr); - - op_ret = ntoh32 (hdr->rsp.op_ret); - op_errno = gf_error_to_errno (ntoh32 (hdr->rsp.op_errno)); - - if (op_ret == 0) { - gf_stat_to_iatt (&rsp->prestat, &prestat); - gf_stat_to_iatt (&rsp->poststat, &poststat); - } - - STACK_UNWIND (frame, op_ret, op_errno, &prestat, &poststat); - - return 0; -} - -/* client_fstat_cbk - fstat callback for client protocol - * @frame: call frame - * @args: argument dictionary - * - * not for external reference - */ - -int -client_fstat_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - struct iatt stbuf = {0, }; - gf_fop_fstat_rsp_t *rsp = NULL; - int32_t op_ret = 0; - int32_t op_errno = 0; - - rsp = gf_param (hdr); - - op_ret = ntoh32 (hdr->rsp.op_ret); - op_errno = gf_error_to_errno (ntoh32 (hdr->rsp.op_errno)); - - if (op_ret == 0) { - gf_stat_to_iatt (&rsp->stat, &stbuf); - - } - - STACK_UNWIND (frame, op_ret, op_errno, &stbuf); - - return 0; -} - -/* - * client_ftruncate_cbk - ftruncate callback for client protocol - * @frame: call frame - * @args: argument dictionary - * - * not for external reference - */ -int -client_ftruncate_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_fop_ftruncate_rsp_t *rsp = NULL; - int32_t op_ret = 0; - int32_t op_errno = 0; - struct iatt prestat = {0, }; - struct iatt poststat = {0, }; - - rsp = gf_param (hdr); - - op_ret = ntoh32 (hdr->rsp.op_ret); - op_errno = gf_error_to_errno (ntoh32 (hdr->rsp.op_errno)); - - if (op_ret == 0) { - gf_stat_to_iatt (&rsp->prestat, &prestat); - gf_stat_to_iatt (&rsp->poststat, &poststat); - } - - STACK_UNWIND (frame, op_ret, op_errno, &prestat, &poststat); - - return 0; -} - - -/* client_readv_cbk - readv callback for client protocol - * @frame: call frame - * @args: argument dictionary - * - * not for external referece - */ - -int -client_readv_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_fop_read_rsp_t *rsp = NULL; - int32_t op_ret = 0; - int32_t op_errno = 0; - struct iovec vector = {0, }; - struct iatt stbuf = {0, }; - struct iobref *iobref = NULL; - - rsp = gf_param (hdr); - - op_ret = ntoh32 (hdr->rsp.op_ret); - op_errno = gf_error_to_errno (ntoh32 (hdr->rsp.op_errno)); - - if (op_ret != -1) { - iobref = iobref_new (); - gf_stat_to_iatt (&rsp->stat, &stbuf); - vector.iov_len = op_ret; - - if (op_ret > 0) { - vector.iov_base = iobuf->ptr; - iobref_add (iobref, iobuf); - } - } - - STACK_UNWIND (frame, op_ret, op_errno, &vector, 1, &stbuf, iobref); - - if (iobref) - iobref_unref (iobref); - - if (iobuf) - iobuf_unref (iobuf); - - return 0; -} - -/* - * client_write_cbk - write callback for client protocol - * @frame: cal frame - * @args: argument dictionary - * - * not for external reference - */ - -int -client_write_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_fop_write_rsp_t *rsp = NULL; - int32_t op_ret = 0; - int32_t op_errno = 0; - struct iatt prestat = {0, }; - struct iatt poststat = {0, }; - - rsp = gf_param (hdr); - - op_ret = ntoh32 (hdr->rsp.op_ret); - op_errno = gf_error_to_errno (ntoh32 (hdr->rsp.op_errno)); - - if (op_ret >= 0) { - gf_stat_to_iatt (&rsp->prestat, &prestat); - gf_stat_to_iatt (&rsp->poststat, &poststat); - } - - STACK_UNWIND (frame, op_ret, op_errno, &prestat, &poststat); - - return 0; -} - - -int -client_readdirp_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_fop_readdirp_rsp_t *rsp = NULL; - int32_t op_ret = 0; - int32_t op_errno = 0; - uint32_t buf_size = 0; - gf_dirent_t entries; - - rsp = gf_param (hdr); - - op_ret = ntoh32 (hdr->rsp.op_ret); - op_errno = ntoh32 (hdr->rsp.op_errno); - - INIT_LIST_HEAD (&entries.list); - if (op_ret > 0) { - buf_size = ntoh32 (rsp->size); - gf_dirent_unserialize (&entries, rsp->buf, buf_size); - } - - STACK_UNWIND (frame, op_ret, op_errno, &entries); - - gf_dirent_free (&entries); - - return 0; -} - - -int -client_readdir_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_fop_readdir_rsp_t *rsp = NULL; - int32_t op_ret = 0; - int32_t op_errno = 0; - uint32_t buf_size = 0; - gf_dirent_t entries; - - rsp = gf_param (hdr); - - op_ret = ntoh32 (hdr->rsp.op_ret); - op_errno = ntoh32 (hdr->rsp.op_errno); - - INIT_LIST_HEAD (&entries.list); - if (op_ret > 0) { - buf_size = ntoh32 (rsp->size); - gf_dirent_unserialize (&entries, rsp->buf, buf_size); - } - - STACK_UNWIND (frame, op_ret, op_errno, &entries); - - gf_dirent_free (&entries); - - return 0; -} - -/* - * client_fsync_cbk - fsync callback for client protocol - * - * @frame: call frame - * @args: argument dictionary - * - * not for external reference - */ - -int -client_fsync_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - struct iatt prestat = {0, }; - struct iatt poststat = {0,}; - gf_fop_fsync_rsp_t *rsp = NULL; - int32_t op_ret = 0; - int32_t op_errno = 0; - - rsp = gf_param (hdr); - - op_ret = ntoh32 (hdr->rsp.op_ret); - op_errno = gf_error_to_errno (ntoh32 (hdr->rsp.op_errno)); - - if (op_ret == 0) { - gf_stat_to_iatt (&rsp->prestat, &prestat); - gf_stat_to_iatt (&rsp->poststat, &poststat); - } - - STACK_UNWIND (frame, op_ret, op_errno, &prestat, &poststat); - - return 0; -} - -/* - * client_unlink_cbk - unlink callback for client protocol - * @frame: call frame - * @args: argument dictionary - * - * not for external reference - */ - -int -client_unlink_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_fop_unlink_rsp_t *rsp = NULL; - int32_t op_ret = 0; - int32_t op_errno = 0; - struct iatt preparent = {0,}; - struct iatt postparent = {0,}; - - rsp = gf_param (hdr); - - op_ret = ntoh32 (hdr->rsp.op_ret); - op_errno = gf_error_to_errno (ntoh32 (hdr->rsp.op_errno)); - - if (op_ret == 0) { - gf_stat_to_iatt (&rsp->preparent, &preparent); - gf_stat_to_iatt (&rsp->postparent, &postparent); - } - - STACK_UNWIND (frame, op_ret, op_errno, &preparent, &postparent); - - return 0; -} - -/* - * client_rename_cbk - rename callback for client protocol - * @frame: call frame - * @args: argument dictionary - * - * not for external reference - */ - -int -client_rename_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - struct iatt stbuf = {0, }; - gf_fop_rename_rsp_t *rsp = NULL; - int32_t op_ret = 0; - int32_t op_errno = 0; - struct iatt preoldparent = {0, }; - struct iatt postoldparent = {0, }; - struct iatt prenewparent = {0, }; - struct iatt postnewparent = {0, }; - - rsp = gf_param (hdr); - - op_ret = ntoh32 (hdr->rsp.op_ret); - op_errno = gf_error_to_errno (ntoh32 (hdr->rsp.op_errno)); - - if (op_ret == 0) { - gf_stat_to_iatt (&rsp->stat, &stbuf); - gf_stat_to_iatt (&rsp->preoldparent, &preoldparent); - gf_stat_to_iatt (&rsp->postoldparent, &postoldparent); - gf_stat_to_iatt (&rsp->prenewparent, &prenewparent); - gf_stat_to_iatt (&rsp->postnewparent, &postnewparent); - } - - STACK_UNWIND (frame, op_ret, op_errno, &stbuf, &preoldparent, - &postoldparent, &prenewparent, &postnewparent); - - return 0; -} - - -/* - * client_readlink_cbk - readlink callback for client protocol - * - * @frame: call frame - * @args: argument dictionary - * - * not for external reference - */ -int -client_readlink_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_fop_readlink_rsp_t *rsp = NULL; - int32_t op_ret = 0; - int32_t op_errno = 0; - char *link = NULL; - struct iatt stbuf = {0,}; - - rsp = gf_param (hdr); - - op_ret = ntoh32 (hdr->rsp.op_ret); - op_errno = gf_error_to_errno (ntoh32 (hdr->rsp.op_errno)); - - if (op_ret > 0) { - link = rsp->path; - gf_stat_to_iatt (&rsp->buf, &stbuf); - } - - STACK_UNWIND (frame, op_ret, op_errno, link, &stbuf); - return 0; -} - -/* - * client_mkdir_cbk - mkdir callback for client protocol - * @frame: call frame - * @args: argument dictionary - * - * not for external reference - */ - -int -client_mkdir_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_fop_mkdir_rsp_t *rsp = NULL; - int32_t op_ret = 0; - int32_t op_errno = 0; - struct iatt stbuf = {0, }; - inode_t *inode = NULL; - client_local_t *local = NULL; - int ret = 0; - struct iatt preparent = {0,}; - struct iatt postparent = {0,}; - - local = frame->local; - inode = local->loc.inode; - frame->local = NULL; - - rsp = gf_param (hdr); - - op_ret = ntoh32 (hdr->rsp.op_ret); - op_errno = gf_error_to_errno (ntoh32 (hdr->rsp.op_errno)); - - if (op_ret >= 0) { - gf_stat_to_iatt (&rsp->stat, &stbuf); - - ret = inode_ctx_put2 (inode, frame->this, stbuf.ia_ino, - stbuf.ia_gen); - if (ret < 0) { - gf_log (frame->this->name, GF_LOG_DEBUG, - "MKDIR %"PRId64"/%s (%s): failed to set " - "remote inode number to inode ctx", - local->loc.parent->ino, local->loc.name, - local->loc.path); - STACK_UNWIND (frame, -1, EINVAL, inode, NULL, - NULL, NULL); - return 0; - } - - gf_stat_to_iatt (&rsp->preparent, &preparent); - gf_stat_to_iatt (&rsp->postparent, &postparent); - } - - STACK_UNWIND (frame, op_ret, op_errno, inode, &stbuf, - &preparent, &postparent); - - client_local_wipe (local); - - return 0; -} - -/* - * client_flush_cbk - flush callback for client protocol - * - * @frame: call frame - * @args: argument dictionary - * - * not for external reference - */ - -int -client_flush_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - int32_t op_ret = 0; - int32_t op_errno = 0; - - op_ret = ntoh32 (hdr->rsp.op_ret); - op_errno = gf_error_to_errno (ntoh32 (hdr->rsp.op_errno)); - - STACK_UNWIND (frame, op_ret, op_errno); - - return 0; -} - -/* - * client_opendir_cbk - opendir callback for client protocol - * @frame: call frame - * @args: argument dictionary - * - * not for external reference - */ - -int -client_opendir_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - int32_t op_ret = -1; - int32_t op_errno = ENOTCONN; - fd_t *fd = NULL; - int64_t remote_fd = 0; - gf_fop_opendir_rsp_t *rsp = NULL; - client_local_t *local = NULL; - client_conf_t *conf = NULL; - client_fd_ctx_t *fdctx = NULL; - ino_t ino = 0; - uint64_t gen = 0; - - - local = frame->local; - - if (local->op) { - local->op (frame, hdr, hdrlen, iobuf); - return 0; - } - - frame->local = NULL; - conf = frame->this->private; - fd = local->fd; - - rsp = gf_param (hdr); - - op_ret = ntoh32 (hdr->rsp.op_ret); - op_errno = ntoh32 (hdr->rsp.op_errno); - - if (op_ret >= 0) { - remote_fd = ntoh64 (rsp->fd); - } - - if (op_ret >= 0) { - fdctx = GF_CALLOC (1, sizeof (*fdctx), - gf_client_mt_client_fd_ctx_t); - if (!fdctx) { - op_ret = -1; - op_errno = ENOMEM; - goto unwind_out; - } - - inode_ctx_get2 (fd->inode, frame->this, &ino, &gen); - - fdctx->remote_fd = remote_fd; - fdctx->inode = inode_ref (fd->inode); - fdctx->ino = ino; - fdctx->gen = gen; - - fdctx->is_dir = 1; - - INIT_LIST_HEAD (&fdctx->sfd_pos); - - this_fd_set_ctx (fd, frame->this, &local->loc, fdctx); - - pthread_mutex_lock (&conf->mutex); - { - list_add_tail (&fdctx->sfd_pos, &conf->saved_fds); - } - pthread_mutex_unlock (&conf->mutex); - } -unwind_out: - STACK_UNWIND (frame, op_ret, op_errno, fd); - - client_local_wipe (local); - - return 0; -} - -/* - * client_rmdir_cbk - rmdir callback for client protocol - * @frame: call frame - * @args: argument dictionary - * - * not for external reference - */ - -int -client_rmdir_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_fop_rmdir_rsp_t *rsp = NULL; - int32_t op_ret = 0; - int32_t op_errno = 0; - struct iatt preparent = {0,}; - struct iatt postparent = {0,}; - - rsp = gf_param (hdr); - - op_ret = ntoh32 (hdr->rsp.op_ret); - op_errno = gf_error_to_errno (ntoh32 (hdr->rsp.op_errno)); - - if (op_ret == 0) { - gf_stat_to_iatt (&rsp->preparent, &preparent); - gf_stat_to_iatt (&rsp->postparent, &postparent); - } - - STACK_UNWIND (frame, op_ret, op_errno, &preparent, &postparent); - - return 0; -} - -/* - * client_access_cbk - access callback for client protocol - * @frame: call frame - * @args: argument dictionary - * - * not for external reference - */ - -int -client_access_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_fop_access_rsp_t *rsp = NULL; - int32_t op_ret = 0; - int32_t op_errno = 0; - - rsp = gf_param (hdr); - - op_ret = ntoh32 (hdr->rsp.op_ret); - op_errno = gf_error_to_errno (ntoh32 (hdr->rsp.op_errno)); - - STACK_UNWIND (frame, op_ret, op_errno); - - return 0; -} - -/* - * client_lookup_cbk - lookup callback for client protocol - * - * @frame: call frame - * @args: arguments dictionary - * - * not for external reference - */ - -int -client_lookup_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - struct iatt stbuf = {0, }; - struct iatt postparent = {0, }; - inode_t *inode = NULL; - dict_t *xattr = NULL; - gf_fop_lookup_rsp_t *rsp = NULL; - int32_t op_ret = 0; - int32_t op_errno = 0; - size_t dict_len = 0; - char *dictbuf = NULL; - int32_t ret = -1; - int32_t gf_errno = 0; - client_local_t *local = NULL; - ino_t oldino = 0; - uint64_t oldgen = 0; - - local = frame->local; - inode = local->loc.inode; - frame->local = NULL; - - rsp = gf_param (hdr); - - op_ret = ntoh32 (hdr->rsp.op_ret); - - gf_stat_to_iatt (&rsp->postparent, &postparent); - - if (op_ret == 0) { - op_ret = -1; - gf_stat_to_iatt (&rsp->stat, &stbuf); - - ret = inode_ctx_get2 (inode, frame->this, &oldino, &oldgen); - if (oldino != stbuf.ia_ino || oldgen != stbuf.ia_gen) { - if (oldino) { - gf_log (frame->this->name, GF_LOG_DEBUG, - "LOOKUP %"PRId64"/%s (%s): " - "inode number changed from " - "{%"PRId64",%"PRId64"} to {%"PRId64",%"PRId64"}", - local->loc.parent ? - local->loc.parent->ino : (uint64_t) 0, - local->loc.name, - local->loc.path, - oldgen, oldino, stbuf.ia_gen, stbuf.ia_ino); - op_errno = ESTALE; - goto fail; - } - - ret = inode_ctx_put2 (inode, frame->this, - stbuf.ia_ino, stbuf.ia_gen); - if (ret < 0) { - gf_log (frame->this->name, GF_LOG_DEBUG, - "LOOKUP %"PRId64"/%s (%s) : " - "failed to set remote inode " - "number to inode ctx", - local->loc.parent ? - local->loc.parent->ino : (uint64_t) 0, - local->loc.name, - local->loc.path); - op_errno = EINVAL; - goto fail; - } - } - - dict_len = ntoh32 (rsp->dict_len); - - if (dict_len > 0) { - dictbuf = memdup (rsp->dict, dict_len); - GF_VALIDATE_OR_GOTO (frame->this->name, dictbuf, fail); - - xattr = dict_new(); - GF_VALIDATE_OR_GOTO (frame->this->name, xattr, fail); - - ret = dict_unserialize (dictbuf, dict_len, &xattr); - if (ret < 0) { - gf_log (frame->this->name, GF_LOG_DEBUG, - "%s (%"PRId64"): failed to " - "unserialize dictionary", - local->loc.path, inode->ino); - goto fail; - } else { - xattr->extra_free = dictbuf; - dictbuf = NULL; - } - } - op_ret = 0; - } - gf_errno = ntoh32 (hdr->rsp.op_errno); - op_errno = gf_error_to_errno (gf_errno); - -fail: - STACK_UNWIND (frame, op_ret, op_errno, inode, &stbuf, xattr, - &postparent); - - client_local_wipe (local); - - if (dictbuf) - GF_FREE (dictbuf); - - if (xattr) - dict_unref (xattr); - - return 0; -} - -static int32_t -client_setattr_cbk (call_frame_t *frame,gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - struct iatt statpre = {0, }; - struct iatt statpost = {0, }; - gf_fop_setattr_rsp_t *rsp = NULL; - int32_t op_ret = 0; - int32_t op_errno = 0; - - rsp = gf_param (hdr); - - op_ret = ntoh32 (hdr->rsp.op_ret); - op_errno = gf_error_to_errno (ntoh32 (hdr->rsp.op_errno)); - - if (op_ret == 0) { - gf_stat_to_iatt (&rsp->statpre, &statpre); - gf_stat_to_iatt (&rsp->statpost, &statpost); - } - - STACK_UNWIND (frame, op_ret, op_errno, &statpre, &statpost); - - return 0; -} - -static int32_t -client_fsetattr_cbk (call_frame_t *frame,gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - struct iatt statpre = {0, }; - struct iatt statpost = {0, }; - gf_fop_setattr_rsp_t *rsp = NULL; - int32_t op_ret = 0; - int32_t op_errno = 0; - - rsp = gf_param (hdr); - - op_ret = ntoh32 (hdr->rsp.op_ret); - op_errno = gf_error_to_errno (ntoh32 (hdr->rsp.op_errno)); - - if (op_ret == 0) { - gf_stat_to_iatt (&rsp->statpre, &statpre); - gf_stat_to_iatt (&rsp->statpost, &statpost); - } - - STACK_UNWIND (frame, op_ret, op_errno, &statpre, &statpost); - - return 0; -} - - -int -gf_free_direntry (dir_entry_t *head) -{ - dir_entry_t *prev = NULL; - dir_entry_t *trav = NULL; - - prev = head; - GF_VALIDATE_OR_GOTO ("client-protocol", prev, fail); - - trav = head->next; - while (trav) { - prev->next = trav->next; - GF_FREE (trav->name); - if (IA_ISLNK (trav->buf.ia_type)) - GF_FREE (trav->link); - GF_FREE (trav); - trav = prev->next; - } - GF_FREE (head); -fail: - return 0; -} - -/* - * client_statfs_cbk - statfs callback for client protocol - * @frame: call frame - * @args: argument dictionary - * - * not for external reference - */ - -int -client_statfs_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - struct statvfs stbuf = {0, }; - gf_fop_statfs_rsp_t *rsp = NULL; - int32_t op_ret = 0; - int32_t op_errno = 0; - - rsp = gf_param (hdr); - - op_ret = ntoh32 (hdr->rsp.op_ret); - op_errno = gf_error_to_errno (ntoh32 (hdr->rsp.op_errno)); - - if (op_ret == 0) { - gf_statfs_to_statfs (&rsp->statfs, &stbuf); - } - - STACK_UNWIND (frame, op_ret, op_errno, &stbuf); - - return 0; -} - -/* - * client_fsyncdir_cbk - fsyncdir callback for client protocol - * @frame: call frame - * @args: argument dictionary - * - * not for external reference - */ - -int -client_fsyncdir_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - int32_t op_ret = 0; - int32_t op_errno = 0; - - op_ret = ntoh32 (hdr->rsp.op_ret); - op_errno = gf_error_to_errno (ntoh32 (hdr->rsp.op_errno)); - - STACK_UNWIND (frame, op_ret, op_errno); - - return 0; -} - -/* - * client_setxattr_cbk - setxattr callback for client protocol - * @frame: call frame - * @args: argument dictionary - * - * not for external reference - */ - -int -client_setxattr_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_fop_setxattr_rsp_t *rsp = NULL; - int32_t op_ret = 0; - int32_t op_errno = 0; - - rsp = gf_param (hdr); - - op_ret = ntoh32 (hdr->rsp.op_ret); - op_errno = gf_error_to_errno (ntoh32 (hdr->rsp.op_errno)); - - STACK_UNWIND (frame, op_ret, op_errno); - - return 0; -} - -/* - * client_getxattr_cbk - getxattr callback for client protocol - * @frame: call frame - * @args: argument dictionary - * - * not for external reference - */ - -int -client_getxattr_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_fop_getxattr_rsp_t *rsp = NULL; - int32_t op_ret = 0; - int32_t gf_errno = 0; - int32_t op_errno = 0; - int32_t dict_len = 0; - dict_t *dict = NULL; - int32_t ret = -1; - char *dictbuf = NULL; - client_local_t *local = NULL; - - local = frame->local; - frame->local = NULL; - - rsp = gf_param (hdr); - GF_VALIDATE_OR_GOTO (frame->this->name, rsp, fail); - - op_ret = ntoh32 (hdr->rsp.op_ret); - - if (op_ret >= 0) { - op_ret = -1; - dict_len = ntoh32 (rsp->dict_len); - - if (dict_len > 0) { - dictbuf = memdup (rsp->dict, dict_len); - GF_VALIDATE_OR_GOTO (frame->this->name, dictbuf, fail); - - dict = dict_new(); - GF_VALIDATE_OR_GOTO (frame->this->name, dict, fail); - - ret = dict_unserialize (dictbuf, dict_len, &dict); - if (ret < 0) { - gf_log (frame->this->name, GF_LOG_DEBUG, - "%s (%"PRId64"): failed to " - "unserialize xattr dictionary", - local->loc.path, - local->loc.inode->ino); - goto fail; - } else { - dict->extra_free = dictbuf; - dictbuf = NULL; - } - } - op_ret = 0; - } - gf_errno = ntoh32 (hdr->rsp.op_errno); - op_errno = gf_error_to_errno (gf_errno); -fail: - STACK_UNWIND (frame, op_ret, op_errno, dict); - - client_local_wipe (local); - - if (dictbuf) - GF_FREE (dictbuf); - - if (dict) - dict_unref (dict); - - return 0; -} - -/* - * client_removexattr_cbk - removexattr callback for client protocol - * @frame: call frame - * @args: argument dictionary - * - * not for external reference - */ - -int -client_removexattr_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, - size_t hdrlen, struct iobuf *iobuf) -{ - int32_t op_ret = 0; - int32_t op_errno = 0; - - op_ret = ntoh32 (hdr->rsp.op_ret); - op_errno = gf_error_to_errno (ntoh32 (hdr->rsp.op_errno)); - - STACK_UNWIND (frame, op_ret, op_errno); - - return 0; -} - -/* - * client_lk_cbk - lk callback for client protocol - * @frame: call frame - * @args: argument dictionary - * - * not for external reference - */ - -int -client_lk_common_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - struct flock lock = {0,}; - gf_fop_lk_rsp_t *rsp = NULL; - int32_t op_ret = 0; - int32_t op_errno = 0; - - rsp = gf_param (hdr); - - op_ret = ntoh32 (hdr->rsp.op_ret); - op_errno = gf_error_to_errno (ntoh32 (hdr->rsp.op_errno)); - - if (op_ret >= 0) { - gf_flock_to_flock (&rsp->flock, &lock); - } - - STACK_UNWIND (frame, op_ret, op_errno, &lock); - return 0; -} - -/* - * client_gf_file_lk_cbk - gf_file_lk callback for client protocol - * @frame: call frame - * @args: argument dictionary - * - * not for external reference - */ - -int -client_inodelk_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_fop_inodelk_rsp_t *rsp = NULL; - int32_t op_ret = 0; - int32_t op_errno = 0; - - rsp = gf_param (hdr); - - op_ret = ntoh32 (hdr->rsp.op_ret); - op_errno = gf_error_to_errno (ntoh32 (hdr->rsp.op_errno)); - - STACK_UNWIND (frame, op_ret, op_errno); - return 0; -} - - -int -client_finodelk_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_fop_finodelk_rsp_t *rsp = NULL; - int32_t op_ret = 0; - int32_t op_errno = 0; - - rsp = gf_param (hdr); - - op_ret = ntoh32 (hdr->rsp.op_ret); - op_errno = gf_error_to_errno (ntoh32 (hdr->rsp.op_errno)); - - STACK_UNWIND (frame, op_ret, op_errno); - return 0; -} - -/* - * client_entrylk_cbk - entrylk callback for client protocol - * @frame: call frame - * @args: argument dictionary - * - * not for external reference - */ - -int -client_entrylk_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_fop_entrylk_rsp_t *rsp = NULL; - int32_t op_ret = 0; - int32_t op_errno = 0; - - rsp = gf_param (hdr); - - op_ret = ntoh32 (hdr->rsp.op_ret); - op_errno = gf_error_to_errno (ntoh32 (hdr->rsp.op_errno)); - - STACK_UNWIND (frame, op_ret, op_errno); - return 0; -} - -int -client_fentrylk_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_fop_fentrylk_rsp_t *rsp = NULL; - int32_t op_ret = 0; - int32_t op_errno = 0; - - rsp = gf_param (hdr); - - op_ret = ntoh32 (hdr->rsp.op_ret); - op_errno = gf_error_to_errno (ntoh32 (hdr->rsp.op_errno)); - - STACK_UNWIND (frame, op_ret, op_errno); - return 0; -} - - - -/* - * client_getspec - getspec function for client protocol - * @frame: call frame - * @this: client protocol xlator structure - * @flag: - * - * external reference through client_protocol_xlator->fops->getspec - */ - -int -client_getspec (call_frame_t *frame, xlator_t *this, const char *key, - int32_t flag) -{ - gf_hdr_common_t *hdr = NULL; - gf_mop_getspec_req_t *req = NULL; - size_t hdrlen = -1; - int keylen = 0; - int ret = -1; - - if (key) - keylen = STRLEN_0 (key); - - hdrlen = gf_hdr_len (req, keylen); - hdr = gf_hdr_new (req, keylen); - GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - - req = gf_param (hdr); - req->flags = hton32 (flag); - req->keylen = hton32 (keylen); - if (keylen) - strcpy (req->key, key); - - ret = protocol_client_xfer (frame, this, - CLIENT_CHANNEL (this, CHANNEL_BULK), - GF_OP_TYPE_MOP_REQUEST, GF_MOP_GETSPEC, - hdr, hdrlen, NULL, 0, NULL); - - return ret; -unwind: - if (hdr) - GF_FREE (hdr); - STACK_UNWIND (frame, -1, EINVAL, NULL); - return 0; -} - -/* - * client_getspec_cbk - getspec callback for client protocol - * - * @frame: call frame - * @args: argument dictionary - * - * not for external reference - */ - -int -client_getspec_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_mop_getspec_rsp_t *rsp = NULL; - char *spec_data = NULL; - int32_t op_ret = 0; - int32_t op_errno = 0; - int32_t gf_errno = 0; - - op_ret = ntoh32 (hdr->rsp.op_ret); - gf_errno = ntoh32 (hdr->rsp.op_errno); - op_errno = gf_error_to_errno (gf_errno); - rsp = gf_param (hdr); - - if (op_ret >= 0) { - spec_data = rsp->spec; - } - - STACK_UNWIND (frame, op_ret, op_errno, spec_data); - return 0; -} - - -int -client_rchecksum (call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset, - int32_t len) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_rchecksum_req_t *req = NULL; - size_t hdrlen = -1; - int ret = -1; - - int64_t remote_fd = -1; - client_fd_ctx_t *fdctx = NULL; - client_conf_t *conf = NULL; - - hdrlen = gf_hdr_len (req, 0); - hdr = gf_hdr_new (req, 0); - req = gf_param (hdr); - - conf = this->private; - - pthread_mutex_lock (&conf->mutex); - { - fdctx = this_fd_get_ctx (fd, this); - } - pthread_mutex_unlock (&conf->mutex); - - if (fdctx == NULL) { - gf_log (this->name, GF_LOG_TRACE, - "(%"PRId64"): failed to get fd ctx. EBADFD", - fd->inode->ino); - STACK_UNWIND (frame, -1, EBADFD, 0, NULL); - return 0; - } - - if (fdctx->remote_fd == -1) { - gf_log (this->name, GF_LOG_TRACE, - "(%"PRId64"): failed to get fd ctx. EBADFD", - fd->inode->ino); - STACK_UNWIND (frame, -1, EBADFD, 0, NULL); - return 0; - } - - remote_fd = fdctx->remote_fd; - - req->fd = hton64 (remote_fd); - req->offset = hton64 (offset); - req->len = hton32 (len); - - ret = protocol_client_xfer (frame, this, - CLIENT_CHANNEL (this, CHANNEL_BULK), - GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_RCHECKSUM, - hdr, hdrlen, NULL, 0, NULL); - - return ret; -} - - -int -client_rchecksum_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_fop_rchecksum_rsp_t *rsp = NULL; - - int32_t op_ret = 0; - int32_t op_errno = 0; - int32_t gf_errno = 0; - uint32_t weak_checksum = 0; - unsigned char *strong_checksum = NULL; - - rsp = gf_param (hdr); - - op_ret = ntoh32 (hdr->rsp.op_ret); - gf_errno = ntoh32 (hdr->rsp.op_errno); - op_errno = gf_error_to_errno (gf_errno); - - if (op_ret >= 0) { - weak_checksum = rsp->weak_checksum; - strong_checksum = rsp->strong_checksum; - } - - STACK_UNWIND (frame, op_ret, op_errno, weak_checksum, strong_checksum); - - return 0; -} - - -/* - * client_setspec_cbk - setspec callback for client protocol - * @frame: call frame - * @args: argument dictionary - * - * not for external reference - */ - -int -client_setspec_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - int32_t op_ret = 0; - int32_t op_errno = 0; - - op_ret = ntoh32 (hdr->rsp.op_ret); - op_errno = gf_error_to_errno (ntoh32 (hdr->rsp.op_errno)); - - STACK_UNWIND (frame, op_ret, op_errno); - - return 0; -} - - - -int -protocol_client_reopendir_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, - size_t hdrlen, struct iobuf *iobuf) -{ - int32_t op_ret = -1; - int32_t op_errno = ENOTCONN; - int64_t remote_fd = -1; - gf_fop_open_rsp_t *rsp = NULL; - client_local_t *local = NULL; - client_conf_t *conf = NULL; - client_fd_ctx_t *fdctx = NULL; - - - local = frame->local; frame->local = NULL; - conf = frame->this->private; - fdctx = local->fdctx; - - rsp = gf_param (hdr); - - op_ret = ntoh32 (hdr->rsp.op_ret); - op_errno = ntoh32 (hdr->rsp.op_errno); - - if (op_ret >= 0) - remote_fd = ntoh64 (rsp->fd); - - gf_log (frame->this->name, GF_LOG_DEBUG, - "reopendir on %s returned %d (%"PRId64")", - local->loc.path, op_ret, remote_fd); - - pthread_mutex_lock (&conf->mutex); - { - fdctx->remote_fd = remote_fd; - - if (!fdctx->released) { - list_add_tail (&fdctx->sfd_pos, &conf->saved_fds); - fdctx = NULL; - } - } - pthread_mutex_unlock (&conf->mutex); - - if (fdctx) - client_fdctx_destroy (frame->this, fdctx); - - STACK_DESTROY (frame->root); - - client_local_wipe (local); - - return 0; -} - - - -int -protocol_client_reopendir (xlator_t *this, client_fd_ctx_t *fdctx) -{ - int ret = -1; - gf_hdr_common_t *hdr = NULL; - size_t hdrlen = 0; - gf_fop_opendir_req_t *req = NULL; - size_t pathlen = 0; - client_local_t *local = NULL; - inode_t *inode = NULL; - char *path = NULL; - call_frame_t *frame = NULL; - - inode = fdctx->inode; - - ret = inode_path (inode, NULL, &path); - if (ret < 0) { - goto out; - } - - local = GF_CALLOC (1, sizeof (*local), gf_client_mt_client_local_t); - if (!local) { - goto out; - } - - local->fdctx = fdctx; - local->op = protocol_client_reopendir_cbk; - local->loc.path = path; path = NULL; - - frame = create_frame (this, this->ctx->pool); - if (!frame) { - goto out; - } - - pathlen = STRLEN_0 (local->loc.path); - - hdrlen = gf_hdr_len (req, pathlen); - hdr = gf_hdr_new (req, pathlen); - - req = gf_param (hdr); - - req->ino = hton64 (fdctx->ino); - req->gen = hton64 (fdctx->gen); - - strcpy (req->path, local->loc.path); - - gf_log (frame->this->name, GF_LOG_DEBUG, - "attempting reopendir on %s", local->loc.path); - - frame->local = local; local = NULL; - - ret = protocol_client_xfer (frame, this, - CLIENT_CHANNEL (this, CHANNEL_LOWLAT), - GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_OPENDIR, - hdr, hdrlen, NULL, 0, NULL); - - return ret; - -out: - if (frame) - STACK_DESTROY (frame->root); - - if (local) - client_local_wipe (local); - - if (path) - GF_FREE (path); - - return 0; -} - - -int -protocol_client_reopen_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, - size_t hdrlen, struct iobuf *iobuf) -{ - int32_t op_ret = -1; - int32_t op_errno = ENOTCONN; - int64_t remote_fd = -1; - gf_fop_open_rsp_t *rsp = NULL; - client_local_t *local = NULL; - client_conf_t *conf = NULL; - client_fd_ctx_t *fdctx = NULL; - - - local = frame->local; frame->local = NULL; - conf = frame->this->private; - fdctx = local->fdctx; - - rsp = gf_param (hdr); - - op_ret = ntoh32 (hdr->rsp.op_ret); - op_errno = ntoh32 (hdr->rsp.op_errno); - - if (op_ret >= 0) - remote_fd = ntoh64 (rsp->fd); - - gf_log (frame->this->name, GF_LOG_DEBUG, - "reopen on %s returned %d (%"PRId64")", - local->loc.path, op_ret, remote_fd); - - pthread_mutex_lock (&conf->mutex); - { - fdctx->remote_fd = remote_fd; - - if (!fdctx->released) { - list_add_tail (&fdctx->sfd_pos, &conf->saved_fds); - fdctx = NULL; - } - } - pthread_mutex_unlock (&conf->mutex); - - if (fdctx) - client_fdctx_destroy (frame->this, fdctx); - - STACK_DESTROY (frame->root); - - client_local_wipe (local); - - return 0; -} - - -int -protocol_client_reopen (xlator_t *this, client_fd_ctx_t *fdctx) -{ - int ret = -1; - gf_hdr_common_t *hdr = NULL; - size_t hdrlen = 0; - gf_fop_open_req_t *req = NULL; - size_t pathlen = 0; - client_local_t *local = NULL; - inode_t *inode = NULL; - char *path = NULL; - call_frame_t *frame = NULL; - - inode = fdctx->inode; - - ret = inode_path (inode, NULL, &path); - if (ret < 0) { - goto out; - } - - local = GF_CALLOC (1, sizeof (*local), gf_client_mt_client_local_t); - if (!local) { - goto out; - } - - local->fdctx = fdctx; - local->op = protocol_client_reopen_cbk; - local->loc.path = path; path = NULL; - - frame = create_frame (this, this->ctx->pool); - if (!frame) { - goto out; - } - - pathlen = STRLEN_0 (local->loc.path); - - hdrlen = gf_hdr_len (req, pathlen); - hdr = gf_hdr_new (req, pathlen); - - req = gf_param (hdr); - - req->ino = hton64 (fdctx->ino); - req->gen = hton64 (fdctx->gen); - req->flags = hton32 (gf_flags_from_flags (fdctx->flags)); - req->wbflags = hton32 (fdctx->wbflags); - strcpy (req->path, local->loc.path); - - gf_log (frame->this->name, GF_LOG_DEBUG, - "attempting reopen on %s", local->loc.path); - - frame->local = local; local = NULL; - - ret = protocol_client_xfer (frame, this, - CLIENT_CHANNEL (this, CHANNEL_LOWLAT), - GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_OPEN, - hdr, hdrlen, NULL, 0, NULL); - - return ret; - -out: - if (frame) - STACK_DESTROY (frame->root); - - if (local) - client_local_wipe (local); - - if (path) - GF_FREE (path); - - return 0; - -} - - -int -protocol_client_post_handshake (call_frame_t *frame, xlator_t *this) -{ - client_conf_t *conf = NULL; - client_fd_ctx_t *tmp = NULL; - client_fd_ctx_t *fdctx = NULL; - xlator_list_t *parent = NULL; - struct list_head reopen_head; - - conf = this->private; - INIT_LIST_HEAD (&reopen_head); - - pthread_mutex_lock (&conf->mutex); - { - list_for_each_entry_safe (fdctx, tmp, &conf->saved_fds, - sfd_pos) { - if (fdctx->remote_fd != -1) - continue; - - list_del (&fdctx->sfd_pos); - list_add_tail (&fdctx->sfd_pos, &reopen_head); - } - } - pthread_mutex_unlock (&conf->mutex); - - list_for_each_entry_safe (fdctx, tmp, &reopen_head, sfd_pos) { - list_del_init (&fdctx->sfd_pos); - - if (fdctx->is_dir) - protocol_client_reopendir (this, fdctx); - else - protocol_client_reopen (this, fdctx); - } - - parent = this->parents; - - while (parent) { - xlator_notify (parent->xlator, GF_EVENT_CHILD_UP, - this); - parent = parent->next; - } - - return 0; -} - -/* - * client_setvolume_cbk - setvolume callback for client protocol - * @frame: call frame - * @args: argument dictionary - * - * not for external reference - */ - -int -client_setvolume_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - client_conf_t *conf = NULL; - gf_mop_setvolume_rsp_t *rsp = NULL; - client_connection_t *conn = NULL; - glusterfs_ctx_t *ctx = NULL; - xlator_t *this = NULL; - xlator_list_t *parent = NULL; - transport_t *trans = NULL; - dict_t *reply = NULL; - char *remote_subvol = NULL; - char *remote_error = NULL; - char *process_uuid = NULL; - int32_t ret = -1; - int32_t op_ret = -1; - int32_t op_errno = EINVAL; - int32_t dict_len = 0; - transport_t *peer_trans = NULL; - uint64_t peer_trans_int = 0; - - trans = frame->local; frame->local = NULL; - this = frame->this; - conn = trans->xl_private; - conf = this->private; - - rsp = gf_param (hdr); - - op_ret = ntoh32 (hdr->rsp.op_ret); - op_errno = gf_error_to_errno (ntoh32 (hdr->rsp.op_errno)); - - if (op_ret < 0) { - gf_log (this->name, GF_LOG_DEBUG, - "setvolume failed (%s)", - strerror (op_errno)); - goto out; - } - - reply = dict_new (); - GF_VALIDATE_OR_GOTO (this->name, reply, out); - - dict_len = ntoh32 (rsp->dict_len); - ret = dict_unserialize (rsp->buf, dict_len, &reply); - if (ret < 0) { - gf_log (frame->this->name, GF_LOG_DEBUG, - "failed to unserialize buffer(%p) to dictionary", - rsp->buf); - goto out; - } - - ret = dict_get_str (reply, "ERROR", &remote_error); - if (ret < 0) { - gf_log (this->name, GF_LOG_DEBUG, - "failed to get ERROR string from reply dictionary"); - } - - ret = dict_get_str (reply, "process-uuid", &process_uuid); - if (ret < 0) { - gf_log (this->name, GF_LOG_DEBUG, - "failed to get 'process-uuid' from reply dictionary"); - } - - if (op_ret < 0) { - gf_log (trans->xl->name, GF_LOG_ERROR, - "SETVOLUME on remote-host failed: %s", - remote_error ? remote_error : strerror (op_errno)); - errno = op_errno; - if (op_errno == ESTALE) { - parent = trans->xl->parents; - while (parent) { - xlator_notify (parent->xlator, - GF_EVENT_VOLFILE_MODIFIED, - trans->xl); - parent = parent->next; - } - } - - } else { - ret = dict_get_str (this->options, "remote-subvolume", - &remote_subvol); - if (!remote_subvol) - goto out; - - ctx = this->ctx; - - if (process_uuid && !strcmp (ctx->process_uuid,process_uuid)) { - ret = dict_get_uint64 (reply, "transport-ptr", - &peer_trans_int); - - peer_trans = (void *) (long) (peer_trans_int); - - gf_log (this->name, GF_LOG_WARNING, - "attaching to the local volume '%s'", - remote_subvol); - - transport_setpeer (trans, peer_trans); - - } - - gf_log (trans->xl->name, GF_LOG_NORMAL, - "Connected to %s, attached " - "to remote volume '%s'.", - trans->peerinfo.identifier, remote_subvol); - - pthread_mutex_lock (&(conn->lock)); - { - conn->connected = 1; - } - pthread_mutex_unlock (&(conn->lock)); - - protocol_client_post_handshake (frame, frame->this); - } - - conf->connecting = 0; -out: - - if (-1 == op_ret) { - /* Let the connection/re-connection happen in - * background, for now, don't hang here, - * tell the parents that i am all ok.. - */ - parent = trans->xl->parents; - while (parent) { - xlator_notify (parent->xlator, - GF_EVENT_CHILD_CONNECTING, trans->xl); - parent = parent->next; - } - conf->connecting= 1; - } - - STACK_DESTROY (frame->root); - - if (reply) - dict_unref (reply); - - return op_ret; -} - -/* - * client_enosys_cbk - - * @frame: call frame - * - * not for external reference - */ - -int -client_enosys_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - STACK_DESTROY (frame->root); - return 0; -} - - -void -client_protocol_reconnect (void *trans_ptr) -{ - transport_t *trans = NULL; - client_connection_t *conn = NULL; - struct timeval tv = {0, 0}; - int32_t ret = 0; - - trans = trans_ptr; - conn = trans->xl_private; - pthread_mutex_lock (&conn->lock); - { - if (conn->reconnect) - gf_timer_call_cancel (trans->xl->ctx, - conn->reconnect); - conn->reconnect = 0; - - if (conn->connected == 0) { - tv.tv_sec = 10; - - gf_log (trans->xl->name, GF_LOG_TRACE, - "attempting reconnect"); - ret = transport_connect (trans); - - conn->reconnect = - gf_timer_call_after (trans->xl->ctx, tv, - client_protocol_reconnect, - trans); - } else { - gf_log (trans->xl->name, GF_LOG_TRACE, - "breaking reconnect chain"); - } - } - pthread_mutex_unlock (&conn->lock); - - if (ret == -1 && errno != EINPROGRESS) { - default_notify (trans->xl, GF_EVENT_CHILD_DOWN, NULL); - } -} - -int -protocol_client_mark_fd_bad (xlator_t *this) -{ - client_conf_t *conf = NULL; - client_fd_ctx_t *tmp = NULL; - client_fd_ctx_t *fdctx = NULL; - - conf = this->private; - - pthread_mutex_lock (&conf->mutex); - { - list_for_each_entry_safe (fdctx, tmp, &conf->saved_fds, - sfd_pos) { - fdctx->remote_fd = -1; - } - } - pthread_mutex_unlock (&conf->mutex); - - return 0; -} - -/* - * client_protocol_cleanup - cleanup function - * @trans: transport object - * - */ - -int -protocol_client_cleanup (transport_t *trans) -{ - client_connection_t *conn = NULL; - struct saved_frames *saved_frames = NULL; - - conn = trans->xl_private; - - gf_log (trans->xl->name, GF_LOG_TRACE, - "cleaning up state in transport object %p", trans); - - pthread_mutex_lock (&conn->lock); - { - saved_frames = conn->saved_frames; - conn->saved_frames = gf_client_saved_frames_new (); - - /* bailout logic cleanup */ - if (conn->timer) { - gf_timer_call_cancel (trans->xl->ctx, conn->timer); - conn->timer = NULL; - } - - if (conn->reconnect == NULL) { - /* :O This part is empty.. any thing missing? */ - } - } - pthread_mutex_unlock (&conn->lock); - - gf_client_saved_frames_destroy (trans->xl, saved_frames, - gf_fops, gf_mops, gf_cbks); - - return 0; -} - - -/* cbk callbacks */ -int -client_releasedir_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, - size_t hdrlen, struct iobuf *iobuf) -{ - STACK_DESTROY (frame->root); - return 0; -} - - -int -client_release_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - STACK_DESTROY (frame->root); - return 0; -} - - -int -client_forget_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_log ("", GF_LOG_CRITICAL, "fop not implemented"); - return 0; -} - - -int -client_log_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_log ("", GF_LOG_CRITICAL, "fop not implemented"); - return 0; -} - - -static gf_op_t gf_fops[] = { - [GF_PROTO_FOP_STAT] = client_stat_cbk, - [GF_PROTO_FOP_READLINK] = client_readlink_cbk, - [GF_PROTO_FOP_MKNOD] = client_mknod_cbk, - [GF_PROTO_FOP_MKDIR] = client_mkdir_cbk, - [GF_PROTO_FOP_UNLINK] = client_unlink_cbk, - [GF_PROTO_FOP_RMDIR] = client_rmdir_cbk, - [GF_PROTO_FOP_SYMLINK] = client_symlink_cbk, - [GF_PROTO_FOP_RENAME] = client_rename_cbk, - [GF_PROTO_FOP_LINK] = client_link_cbk, - [GF_PROTO_FOP_TRUNCATE] = client_truncate_cbk, - [GF_PROTO_FOP_OPEN] = client_open_cbk, - [GF_PROTO_FOP_READ] = client_readv_cbk, - [GF_PROTO_FOP_WRITE] = client_write_cbk, - [GF_PROTO_FOP_STATFS] = client_statfs_cbk, - [GF_PROTO_FOP_FLUSH] = client_flush_cbk, - [GF_PROTO_FOP_FSYNC] = client_fsync_cbk, - [GF_PROTO_FOP_SETXATTR] = client_setxattr_cbk, - [GF_PROTO_FOP_GETXATTR] = client_getxattr_cbk, - [GF_PROTO_FOP_REMOVEXATTR] = client_removexattr_cbk, - [GF_PROTO_FOP_OPENDIR] = client_opendir_cbk, - [GF_PROTO_FOP_FSYNCDIR] = client_fsyncdir_cbk, - [GF_PROTO_FOP_ACCESS] = client_access_cbk, - [GF_PROTO_FOP_CREATE] = client_create_cbk, - [GF_PROTO_FOP_FTRUNCATE] = client_ftruncate_cbk, - [GF_PROTO_FOP_FSTAT] = client_fstat_cbk, - [GF_PROTO_FOP_LK] = client_lk_common_cbk, - [GF_PROTO_FOP_LOOKUP] = client_lookup_cbk, - [GF_PROTO_FOP_READDIR] = client_readdir_cbk, - [GF_PROTO_FOP_READDIRP] = client_readdirp_cbk, - [GF_PROTO_FOP_INODELK] = client_inodelk_cbk, - [GF_PROTO_FOP_FINODELK] = client_finodelk_cbk, - [GF_PROTO_FOP_ENTRYLK] = client_entrylk_cbk, - [GF_PROTO_FOP_FENTRYLK] = client_fentrylk_cbk, - [GF_PROTO_FOP_RCHECKSUM] = client_rchecksum_cbk, - [GF_PROTO_FOP_XATTROP] = client_xattrop_cbk, - [GF_PROTO_FOP_FXATTROP] = client_fxattrop_cbk, - [GF_PROTO_FOP_SETATTR] = client_setattr_cbk, - [GF_PROTO_FOP_FSETATTR] = client_fsetattr_cbk -}; - -static gf_op_t gf_mops[] = { - [GF_MOP_SETVOLUME] = client_setvolume_cbk, - [GF_MOP_GETVOLUME] = client_enosys_cbk, - [GF_MOP_SETSPEC] = client_setspec_cbk, - [GF_MOP_GETSPEC] = client_getspec_cbk, - [GF_MOP_PING] = client_ping_cbk, - [GF_MOP_LOG] = client_log_cbk -}; - -static gf_op_t gf_cbks[] = { - [GF_CBK_FORGET] = client_forget_cbk, - [GF_CBK_RELEASE] = client_release_cbk, - [GF_CBK_RELEASEDIR] = client_releasedir_cbk -}; - -/* - * client_protocol_interpret - protocol interpreter - * @trans: transport object - * @blk: data block - * - */ -int -protocol_client_interpret (xlator_t *this, transport_t *trans, - char *hdr_p, size_t hdrlen, struct iobuf *iobuf) -{ - int ret = -1; - call_frame_t *frame = NULL; - gf_hdr_common_t *hdr = NULL; - uint64_t callid = 0; - int type = -1; - int op = -1; - client_connection_t *conn = NULL; - - conn = trans->xl_private; - - hdr = (gf_hdr_common_t *)hdr_p; - - type = ntoh32 (hdr->type); - op = ntoh32 (hdr->op); - callid = ntoh64 (hdr->callid); - - frame = lookup_frame (trans, op, type, callid); - if (frame == NULL) { - gf_log (this->name, GF_LOG_WARNING, - "no frame for callid=%"PRId64" type=%d op=%d", - callid, type, op); - return 0; - } - - switch (type) { - case GF_OP_TYPE_FOP_REPLY: - if ((op > GF_PROTO_FOP_MAXVALUE) || - (op < 0)) { - gf_log (trans->xl->name, GF_LOG_WARNING, - "invalid fop '%d'", op); - } else { - ret = gf_fops[op] (frame, hdr, hdrlen, iobuf); - } - break; - case GF_OP_TYPE_MOP_REPLY: - if ((op > GF_MOP_MAXVALUE) || - (op < 0)) { - gf_log (trans->xl->name, GF_LOG_WARNING, - "invalid fop '%d'", op); - } else { - ret = gf_mops[op] (frame, hdr, hdrlen, iobuf); - } - break; - case GF_OP_TYPE_CBK_REPLY: - if ((op > GF_CBK_MAXVALUE) || - (op < 0)) { - gf_log (trans->xl->name, GF_LOG_WARNING, - "invalid cbk '%d'", op); - } else { - ret = gf_cbks[op] (frame, hdr, hdrlen, iobuf); - } - break; - default: - gf_log (trans->xl->name, GF_LOG_DEBUG, - "invalid packet type: %d", type); - break; - } - - return ret; -} - -int32_t -mem_acct_init (xlator_t *this) -{ - int ret = -1; - - if (!this) - return ret; - - ret = xlator_mem_acct_init (this, gf_client_mt_end + 1); - - if (ret != 0) { - gf_log (this->name, GF_LOG_ERROR, "Memory accounting init" - "failed"); - return ret; - } - - return ret; -} - - -/* - * init - initiliazation function. called during loading of client protocol - * @this: - * - */ - -int -init (xlator_t *this) -{ - transport_t *trans = NULL; - client_conf_t *conf = NULL; - client_connection_t *conn = NULL; - int32_t frame_timeout = 0; - int32_t ping_timeout = 0; - data_t *remote_subvolume = NULL; - int32_t ret = -1; - int i = 0; - - if (this->children) { - gf_log (this->name, GF_LOG_ERROR, - "FATAL: client protocol translator cannot have any " - "subvolumes"); - goto out; - } - - if (!this->parents) { - gf_log (this->name, GF_LOG_WARNING, - "Volume is dangling. "); - } - - remote_subvolume = dict_get (this->options, "remote-subvolume"); - if (remote_subvolume == NULL) { - gf_log (this->name, GF_LOG_ERROR, - "Option 'remote-subvolume' is not specified."); - goto out; - } - - ret = dict_get_int32 (this->options, "frame-timeout", - &frame_timeout); - if (ret >= 0) { - gf_log (this->name, GF_LOG_DEBUG, - "setting frame-timeout to %d", frame_timeout); - } else { - gf_log (this->name, GF_LOG_DEBUG, - "defaulting frame-timeout to 30mins"); - frame_timeout = 1800; - } - - ret = dict_get_int32 (this->options, "ping-timeout", - &ping_timeout); - if (ret >= 0) { - gf_log (this->name, GF_LOG_DEBUG, - "setting ping-timeout to %d", ping_timeout); - } else { - gf_log (this->name, GF_LOG_DEBUG, - "defaulting ping-timeout to 42"); - ping_timeout = GF_UNIVERSAL_ANSWER; - } - - conf = GF_CALLOC (1, sizeof (client_conf_t), - gf_client_mt_client_conf_t); - - protocol_common_init (); - - pthread_mutex_init (&conf->mutex, NULL); - INIT_LIST_HEAD (&conf->saved_fds); - - this->private = conf; - - for (i = 0; i < CHANNEL_MAX; i++) { - if (CHANNEL_LOWLAT == i) { - dict_set (this->options, "transport.socket.lowlat", - data_from_dynstr (gf_strdup ("true"))); - } - trans = transport_load (this->options, this); - if (trans == NULL) { - gf_log (this->name, GF_LOG_DEBUG, - "Failed to load transport"); - ret = -1; - goto out; - } - - conn = GF_CALLOC (1, sizeof (*conn), - gf_client_mt_client_connection_t); - - conn->saved_frames = gf_client_saved_frames_new (); - - conn->callid = 1; - - conn->frame_timeout = frame_timeout; - conn->ping_timeout = ping_timeout; - - pthread_mutex_init (&conn->lock, NULL); - - trans->xl_private = conn; - conf->transport[i] = transport_ref (trans); - } - -#ifndef GF_DARWIN_HOST_OS - { - struct rlimit lim; - - lim.rlim_cur = 1048576; - lim.rlim_max = 1048576; - - ret = setrlimit (RLIMIT_NOFILE, &lim); - if (ret == -1) { - gf_log (this->name, GF_LOG_WARNING, - "WARNING: Failed to set 'ulimit -n 1M': %s", - strerror(errno)); - lim.rlim_cur = 65536; - lim.rlim_max = 65536; - - ret = setrlimit (RLIMIT_NOFILE, &lim); - if (ret == -1) { - gf_log (this->name, GF_LOG_DEBUG, - "Failed to set max open fd to 64k: %s", - strerror(errno)); - } else { - gf_log (this->name, GF_LOG_DEBUG, - "max open fd set to 64k"); - } - - } - } -#endif - ret = 0; -out: - return ret; -} - -/* - * fini - finish function called during unloading of client protocol - * @this: - * - */ -void -fini (xlator_t *this) -{ - /* TODO: Check if its enough.. how to call transport's fini () */ - client_conf_t *conf = NULL; - - conf = this->private; - this->private = NULL; - - if (conf) { - GF_FREE (conf); - } - return; -} - - -int -protocol_client_handshake (xlator_t *this, transport_t *trans) -{ - gf_hdr_common_t *hdr = NULL; - gf_mop_setvolume_req_t *req = NULL; - dict_t *options = NULL; - int32_t ret = -1; - int hdrlen = 0; - int dict_len = 0; - call_frame_t *fr = NULL; - char *process_uuid_xl; - - options = this->options; - ret = dict_set_str (options, "protocol-version", GF_PROTOCOL_VERSION); - if (ret < 0) { - gf_log (this->name, GF_LOG_DEBUG, - "failed to set protocol version(%s) in handshake msg", - GF_PROTOCOL_VERSION); - } - - ret = gf_asprintf (&process_uuid_xl, "%s-%s", this->ctx->process_uuid, - this->name); - if (-1 == ret) { - gf_log (this->name, GF_LOG_ERROR, - "asprintf failed while setting process_uuid"); - goto fail; - } - ret = dict_set_dynstr (options, "process-uuid", - process_uuid_xl); - if (ret < 0) { - gf_log (this->name, GF_LOG_DEBUG, - "failed to set process-uuid(%s) in handshake msg", - process_uuid_xl); - } - - if (this->ctx->cmd_args.volfile_server) { - if (this->ctx->cmd_args.volfile_id) - ret = dict_set_str (options, "volfile-key", - this->ctx->cmd_args.volfile_id); - ret = dict_set_uint32 (options, "volfile-checksum", - this->graph->volfile_checksum); - } - - dict_len = dict_serialized_length (options); - if (dict_len < 0) { - gf_log (this->name, GF_LOG_DEBUG, - "failed to get serialized length of dict(%p)", - options); - ret = dict_len; - goto fail; - } - - hdrlen = gf_hdr_len (req, dict_len); - hdr = gf_hdr_new (req, dict_len); - GF_VALIDATE_OR_GOTO (this->name, hdr, fail); - - req = gf_param (hdr); - - ret = dict_serialize (options, req->buf); - if (ret < 0) { - gf_log (this->name, GF_LOG_DEBUG, - "failed to serialize dictionary(%p)", - options); - goto fail; - } - - req->dict_len = hton32 (dict_len); - fr = create_frame (this, this->ctx->pool); - GF_VALIDATE_OR_GOTO (this->name, fr, fail); - - fr->local = trans; - ret = protocol_client_xfer (fr, this, trans, - GF_OP_TYPE_MOP_REQUEST, GF_MOP_SETVOLUME, - hdr, hdrlen, NULL, 0, NULL); - return ret; -fail: - if (hdr) - GF_FREE (hdr); - return ret; -} - - -int -protocol_client_pollout (xlator_t *this, transport_t *trans) -{ - client_conf_t *conf = NULL; - - conf = trans->xl->private; - - pthread_mutex_lock (&conf->mutex); - { - gettimeofday (&conf->last_sent, NULL); - } - pthread_mutex_unlock (&conf->mutex); - - return 0; -} - - -int -protocol_client_pollin (xlator_t *this, transport_t *trans) -{ - client_conf_t *conf = NULL; - int ret = -1; - struct iobuf *iobuf = NULL; - char *hdr = NULL; - size_t hdrlen = 0; - - conf = trans->xl->private; - - pthread_mutex_lock (&conf->mutex); - { - gettimeofday (&conf->last_received, NULL); - } - pthread_mutex_unlock (&conf->mutex); - - ret = transport_receive (trans, &hdr, &hdrlen, &iobuf); - - if (ret == 0) - { - ret = protocol_client_interpret (this, trans, hdr, hdrlen, - iobuf); - } - - /* TODO: use mem-pool */ - GF_FREE (hdr); - - return ret; -} - -int -client_priv_dump (xlator_t *this) -{ - client_conf_t *conf = NULL; - int ret = -1; - client_fd_ctx_t *tmp = NULL; - int i = 0; - char key[GF_DUMP_MAX_BUF_LEN]; - char key_prefix[GF_DUMP_MAX_BUF_LEN]; - - if (!this) - return -1; - - conf = this->private; - if (!conf) { - gf_log (this->name, GF_LOG_WARNING, - "conf null in xlator"); - return -1; - } - - ret = pthread_mutex_trylock(&conf->mutex); - if (ret) { - gf_log("", GF_LOG_WARNING, "Unable to lock client %s" - " errno: %d", this->name, errno); - return -1; - } - - gf_proc_dump_build_key(key_prefix, "xlator.protocol.client", - "%s.priv", this->name); - - gf_proc_dump_add_section(key_prefix); - - list_for_each_entry(tmp, &conf->saved_fds, sfd_pos) { - gf_proc_dump_build_key(key, key_prefix, - "fd.%d.remote_fd", ++i); - gf_proc_dump_write(key, "%d", tmp->remote_fd); - } - - gf_proc_dump_build_key(key, key_prefix, "connecting"); - gf_proc_dump_write(key, "%d", conf->connecting); - gf_proc_dump_build_key(key, key_prefix, "last_sent"); - gf_proc_dump_write(key, "%s", ctime(&conf->last_sent.tv_sec)); - gf_proc_dump_build_key(key, key_prefix, "last_received"); - gf_proc_dump_write(key, "%s", ctime(&conf->last_received.tv_sec)); - - pthread_mutex_unlock(&conf->mutex); - - return 0; - -} - -int32_t -client_inodectx_dump (xlator_t *this, inode_t *inode) -{ - ino_t par = 0; - int ret = -1; - char key[GF_DUMP_MAX_BUF_LEN]; - - if (!inode) - return -1; - - if (!this) - return -1; - - ret = inode_ctx_get (inode, this, &par); - - if (ret != 0) - return ret; - - gf_proc_dump_build_key(key, "xlator.protocol.client", - "%s.inode.%ld.par", - this->name,inode->ino); - gf_proc_dump_write(key, "%ld", par); - - return 0; -} - -/* - * client_protocol_notify - notify function for client protocol - * @this: - * @trans: transport object - * @event - * - */ - -int -notify (xlator_t *this, int32_t event, void *data, ...) -{ - int i = 0; - int ret = 0; - int child_down = 1; - int was_not_down = 0; - transport_t *trans = NULL; - client_connection_t *conn = NULL; - client_conf_t *conf = NULL; - xlator_list_t *parent = NULL; - - conf = this->private; - trans = data; - - switch (event) { - case GF_EVENT_POLLOUT: - { - ret = protocol_client_pollout (this, trans); - - break; - } - case GF_EVENT_POLLIN: - { - ret = protocol_client_pollin (this, trans); - - break; - } - /* no break for ret check to happen below */ - case GF_EVENT_POLLERR: - { - ret = -1; - protocol_client_cleanup (trans); - - if (conf->connecting == 0) { - /* Let the connection/re-connection happen in - * background, for now, don't hang here, - * tell the parents that i am all ok.. - */ - parent = trans->xl->parents; - while (parent) { - parent->xlator->notify (parent->xlator, - GF_EVENT_CHILD_CONNECTING, - trans->xl); - parent = parent->next; - } - conf->connecting = 1; - } - - was_not_down = 0; - for (i = 0; i < CHANNEL_MAX; i++) { - conn = conf->transport[i]->xl_private; - if (conn->connected == 1) - was_not_down = 1; - } - - conn = trans->xl_private; - if (conn->connected) { - conn->connected = 0; - if (conn->reconnect == 0) - client_protocol_reconnect (trans); - } - - child_down = 1; - for (i = 0; i < CHANNEL_MAX; i++) { - trans = conf->transport[i]; - conn = trans->xl_private; - if (conn->connected == 1) - child_down = 0; - } - - if (child_down && was_not_down) { - gf_log (this->name, GF_LOG_INFO, "disconnected"); - - protocol_client_mark_fd_bad (this); - - parent = this->parents; - while (parent) { - xlator_notify (parent->xlator, - GF_EVENT_CHILD_DOWN, this); - parent = parent->next; - } - } - } - break; - - case GF_EVENT_PARENT_UP: - { - client_conf_t *conf = NULL; - int i = 0; - transport_t *trans = NULL; - - conf = this->private; - for (i = 0; i < CHANNEL_MAX; i++) { - trans = conf->transport[i]; - if (!trans) { - gf_log (this->name, GF_LOG_DEBUG, - "transport init failed"); - return -1; - } - - conn = trans->xl_private; - - gf_log (this->name, GF_LOG_DEBUG, - "got GF_EVENT_PARENT_UP, attempting connect " - "on transport"); - - client_protocol_reconnect (trans); - } - } - break; - - case GF_EVENT_CHILD_UP: - { - char *handshake = NULL; - - ret = dict_get_str (this->options, "disable-handshake", - &handshake); - gf_log (this->name, GF_LOG_DEBUG, - "got GF_EVENT_CHILD_UP"); - if ((ret < 0) || - (strcasecmp (handshake, "on"))) { - ret = protocol_client_handshake (this, trans); - } else { - conn = trans->xl_private; - conn->connected = 1; - ret = default_notify (this, event, trans); - } - - if (ret) - transport_disconnect (trans); - - } - break; - - default: - gf_log (this->name, GF_LOG_DEBUG, - "got %d, calling default_notify ()", event); - - default_notify (this, event, data); - break; - } - - return ret; -} - - -struct xlator_fops fops = { - .stat = client_stat, - .readlink = client_readlink, - .mknod = client_mknod, - .mkdir = client_mkdir, - .unlink = client_unlink, - .rmdir = client_rmdir, - .symlink = client_symlink, - .rename = client_rename, - .link = client_link, - .truncate = client_truncate, - .open = client_open, - .readv = client_readv, - .writev = client_writev, - .statfs = client_statfs, - .flush = client_flush, - .fsync = client_fsync, - .setxattr = client_setxattr, - .getxattr = client_getxattr, - .fsetxattr = client_fsetxattr, - .fgetxattr = client_fgetxattr, - .removexattr = client_removexattr, - .opendir = client_opendir, - .readdir = client_readdir, - .readdirp = client_readdirp, - .fsyncdir = client_fsyncdir, - .access = client_access, - .ftruncate = client_ftruncate, - .fstat = client_fstat, - .create = client_create, - .lk = client_lk, - .inodelk = client_inodelk, - .finodelk = client_finodelk, - .entrylk = client_entrylk, - .fentrylk = client_fentrylk, - .lookup = client_lookup, - .rchecksum = client_rchecksum, - .xattrop = client_xattrop, - .fxattrop = client_fxattrop, - .setattr = client_setattr, - .fsetattr = client_fsetattr, - .getspec = client_getspec, -}; - -struct xlator_cbks cbks = { - .release = client_release, - .releasedir = client_releasedir -}; - - -struct xlator_dumpops dumpops = { - .priv = client_priv_dump, - .inodectx = client_inodectx_dump, -}; - -struct volume_options options[] = { - { .key = {"username"}, - .type = GF_OPTION_TYPE_ANY - }, - { .key = {"password"}, - .type = GF_OPTION_TYPE_ANY - }, - { .key = {"transport-type"}, - .value = {"tcp", "socket", "ib-verbs", "unix", "ib-sdp", - "tcp/client", "ib-verbs/client"}, - .type = GF_OPTION_TYPE_STR - }, - { .key = {"remote-host"}, - .type = GF_OPTION_TYPE_INTERNET_ADDRESS - }, - { .key = {"remote-subvolume"}, - .type = GF_OPTION_TYPE_ANY - }, - { .key = {"frame-timeout"}, - .type = GF_OPTION_TYPE_TIME, - .min = 0, - .max = 86400, - }, - { .key = {"ping-timeout"}, - .type = GF_OPTION_TYPE_TIME, - .min = 1, - .max = 1013, - }, - { .key = {NULL} }, -}; diff --git a/xlators/protocol/legacy/client/src/client-protocol.h b/xlators/protocol/legacy/client/src/client-protocol.h deleted file mode 100644 index ae65fb5fe72..00000000000 --- a/xlators/protocol/legacy/client/src/client-protocol.h +++ /dev/null @@ -1,178 +0,0 @@ -/* - Copyright (c) 2006-2009 Gluster, Inc. <http://www.gluster.com> - This file is part of GlusterFS. - - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. -*/ - -#ifndef _CLIENT_PROTOCOL_H -#define _CLIENT_PROTOCOL_H - -#ifndef _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif - -#include <stdio.h> -#include <arpa/inet.h> -#include "inode.h" -#include "timer.h" -#include "byte-order.h" -#include "saved-frames.h" - -#define CLIENT_PORT_CEILING 1023 - -#define GF_CLIENT_INODE_SELF 0 -#define GF_CLIENT_INODE_PARENT 1 - -#define CLIENT_CONF(this) ((client_conf_t *)(this->private)) - -#define RECEIVE_TIMEOUT(_cprivate,_current) \ - ((_cprivate->last_received.tv_sec + \ - _cprivate->frame_timeout) < \ - _current.tv_sec) - -#define SEND_TIMEOUT(_cprivate,_current) \ - ((_cprivate->last_sent.tv_sec + \ - _cprivate->frame_timeout) < \ - _current.tv_sec) - -enum { - CHANNEL_BULK = 0, - CHANNEL_LOWLAT = 1, - CHANNEL_MAX -}; - -#define CLIENT_CHANNEL client_channel - -struct client_connection; -typedef struct client_connection client_connection_t; - -#include "stack.h" -#include "xlator.h" -#include "transport.h" -#include "protocol.h" - -typedef struct _client_fd_ctx { - struct list_head sfd_pos; /* Stores the reference to this - fd's position in the saved_fds list. - */ - int64_t remote_fd; - inode_t *inode; - uint64_t ino; - uint64_t gen; - char is_dir; - char released; - int32_t flags; - int32_t wbflags; -} client_fd_ctx_t; - -struct _client_conf { - transport_t *transport[CHANNEL_MAX]; - struct list_head saved_fds; - struct timeval last_sent; - struct timeval last_received; - pthread_mutex_t mutex; - int connecting; -}; -typedef struct _client_conf client_conf_t; - -/* This will be stored in transport_t->xl_private */ -struct client_connection { - pthread_mutex_t lock; - uint64_t callid; - struct saved_frames *saved_frames; - int32_t frame_timeout; - int32_t ping_started; - int32_t ping_timeout; - int32_t transport_activity; - gf_timer_t *reconnect; - char connected; - uint64_t max_block_size; - gf_timer_t *timer; - gf_timer_t *ping_timer; -}; - -typedef struct { - loc_t loc; - loc_t loc2; - fd_t *fd; - gf_op_t op; - client_fd_ctx_t *fdctx; - uint32_t flags; - uint32_t wbflags; -} client_local_t; - - -static inline void -gf_string_to_stat(char *string, struct iatt *stbuf) -{ - uint64_t dev = 0; - uint64_t ino = 0; - uint32_t mode = 0; - uint32_t nlink = 0; - uint32_t uid = 0; - uint32_t gid = 0; - uint64_t rdev = 0; - uint64_t size = 0; - uint32_t blksize = 0; - uint64_t blocks = 0; - uint32_t atime = 0; - uint32_t atime_nsec = 0; - uint32_t mtime = 0; - uint32_t mtime_nsec = 0; - uint32_t ctime = 0; - uint32_t ctime_nsec = 0; - - sscanf (string, GF_STAT_PRINT_FMT_STR, - &dev, - &ino, - &mode, - &nlink, - &uid, - &gid, - &rdev, - &size, - &blksize, - &blocks, - &atime, - &atime_nsec, - &mtime, - &mtime_nsec, - &ctime, - &ctime_nsec); - - stbuf->ia_gen = dev; - stbuf->ia_ino = ino; - stbuf->ia_prot = ia_prot_from_st_mode (mode); - stbuf->ia_type = ia_type_from_st_mode (mode); - stbuf->ia_nlink = nlink; - stbuf->ia_uid = uid; - stbuf->ia_gid = gid; - stbuf->ia_rdev = rdev; - stbuf->ia_size = size; - stbuf->ia_blksize = blksize; - stbuf->ia_blocks = blocks; - - stbuf->ia_atime = atime; - stbuf->ia_mtime = mtime; - stbuf->ia_ctime = ctime; - - stbuf->ia_atime_nsec = atime_nsec; - stbuf->ia_mtime_nsec = mtime_nsec; - stbuf->ia_ctime_nsec = ctime_nsec; -} - -#endif diff --git a/xlators/protocol/legacy/client/src/saved-frames.c b/xlators/protocol/legacy/client/src/saved-frames.c deleted file mode 100644 index de40dc22dec..00000000000 --- a/xlators/protocol/legacy/client/src/saved-frames.c +++ /dev/null @@ -1,196 +0,0 @@ -/* - Copyright (c) 2008-2009 Gluster, Inc. <http://www.gluster.com> - This file is part of GlusterFS. - - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. -*/ - - -#include "saved-frames.h" -#include "common-utils.h" -#include "protocol.h" -#include "xlator.h" -#include "client-mem-types.h" - - - -struct saved_frames * -gf_client_saved_frames_new (void) -{ - struct saved_frames *saved_frames = NULL; - - saved_frames = GF_CALLOC (sizeof (*saved_frames), 1, - gf_client_mt_saved_frames); - if (!saved_frames) { - return NULL; - } - - gf_log ("", 1, "here"); - INIT_LIST_HEAD (&saved_frames->fops.list); - INIT_LIST_HEAD (&saved_frames->mops.list); - INIT_LIST_HEAD (&saved_frames->cbks.list); - - return saved_frames; -} - - -struct saved_frame * -get_head_frame_for_type (struct saved_frames *frames, int8_t type) -{ - struct saved_frame *head_frame = NULL; - - switch (type) { - case GF_OP_TYPE_FOP_REQUEST: - case GF_OP_TYPE_FOP_REPLY: - head_frame = &frames->fops; - break; - case GF_OP_TYPE_MOP_REQUEST: - case GF_OP_TYPE_MOP_REPLY: - head_frame = &frames->mops; - break; - case GF_OP_TYPE_CBK_REQUEST: - case GF_OP_TYPE_CBK_REPLY: - head_frame = &frames->cbks; - break; - } - - return head_frame; -} - - -int -saved_frames_put (struct saved_frames *frames, call_frame_t *frame, - int32_t op, int8_t type, int64_t callid) -{ - struct saved_frame *saved_frame = NULL; - struct saved_frame *head_frame = NULL; - - head_frame = get_head_frame_for_type (frames, type); - - saved_frame = GF_CALLOC (sizeof (*saved_frame), 1, - gf_client_mt_saved_frame); - if (!saved_frame) { - return -ENOMEM; - } - - INIT_LIST_HEAD (&saved_frame->list); - saved_frame->frame = frame; - saved_frame->op = op; - saved_frame->type = type; - saved_frame->callid = callid; - - gettimeofday (&saved_frame->saved_at, NULL); - - list_add_tail (&saved_frame->list, &head_frame->list); - frames->count++; - - return 0; -} - - -call_frame_t * -saved_frames_get (struct saved_frames *frames, int32_t op, - int8_t type, int64_t callid) -{ - struct saved_frame *saved_frame = NULL; - struct saved_frame *tmp = NULL; - struct saved_frame *head_frame = NULL; - call_frame_t *frame = NULL; - - head_frame = get_head_frame_for_type (frames, type); - - list_for_each_entry (tmp, &head_frame->list, list) { - if (tmp->callid == callid) { - list_del_init (&tmp->list); - frames->count--; - saved_frame = tmp; - break; - } - } - - if (saved_frame) - frame = saved_frame->frame; - - GF_FREE (saved_frame); - - return frame; -} - -struct saved_frame * -saved_frames_get_timedout (struct saved_frames *frames, int8_t type, - uint32_t timeout, struct timeval *current) -{ - struct saved_frame *bailout_frame = NULL, *tmp = NULL; - struct saved_frame *head_frame = NULL; - - head_frame = get_head_frame_for_type (frames, type); - - if (!list_empty(&head_frame->list)) { - tmp = list_entry (head_frame->list.next, typeof (*tmp), list); - if ((tmp->saved_at.tv_sec + timeout) < current->tv_sec) { - bailout_frame = tmp; - list_del_init (&bailout_frame->list); - frames->count--; - } - } - - return bailout_frame; -} - -void -saved_frames_unwind (xlator_t *this, struct saved_frames *saved_frames, - struct saved_frame *head, - gf_op_t gf_ops[], char *gf_op_list[]) -{ - struct saved_frame *trav = NULL; - struct saved_frame *tmp = NULL; - - gf_hdr_common_t hdr = {0, }; - call_frame_t *frame = NULL; - - hdr.rsp.op_ret = hton32 (-1); - hdr.rsp.op_errno = hton32 (ENOTCONN); - - list_for_each_entry_safe (trav, tmp, &head->list, list) { - gf_log (this->name, GF_LOG_ERROR, - "forced unwinding frame type(%d) op(%s)", - trav->type, gf_op_list[trav->op]); - - hdr.type = hton32 (trav->type); - hdr.op = hton32 (trav->op); - - frame = trav->frame; - - saved_frames->count--; - - gf_ops[trav->op] (frame, &hdr, sizeof (hdr), NULL); - - list_del_init (&trav->list); - GF_FREE (trav); - } -} - - -void -gf_client_saved_frames_destroy (xlator_t *this, struct saved_frames *frames, - gf_op_t gf_fops[], gf_op_t gf_mops[], - gf_op_t gf_cbks[]) -{ - saved_frames_unwind (this, frames, &frames->fops, gf_fops, gf_fop_list); - saved_frames_unwind (this, frames, &frames->mops, gf_mops, gf_mop_list); - saved_frames_unwind (this, frames, &frames->cbks, gf_cbks, gf_cbk_list); - - GF_FREE (frames); -} diff --git a/xlators/protocol/legacy/client/src/saved-frames.h b/xlators/protocol/legacy/client/src/saved-frames.h deleted file mode 100644 index 7103a1ff432..00000000000 --- a/xlators/protocol/legacy/client/src/saved-frames.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - Copyright (c) 2008-2009 Gluster, Inc. <http://www.gluster.com> - This file is part of GlusterFS. - - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. -*/ - -#ifndef _SAVED_FRAMES_H -#define _SAVED_FRAMES_H - -#ifndef _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif - -#include <stdint.h> -#include <sys/time.h> -#include "stack.h" -#include "list.h" -#include "protocol.h" - -/* UGLY: have common typedef b/w saved-frames.c and protocol-client.c */ -typedef int32_t (*gf_op_t) (call_frame_t *frame, - gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf); - - -struct saved_frame { - union { - struct list_head list; - struct { - struct saved_frame *frame_next; - struct saved_frame *frame_prev; - }; - }; - - struct timeval saved_at; - call_frame_t *frame; - int32_t op; - int8_t type; - uint64_t callid; -}; - - -struct saved_frames { - int64_t count; - struct saved_frame fops; - struct saved_frame mops; - struct saved_frame cbks; -}; - - -struct saved_frames *gf_client_saved_frames_new (); -int saved_frames_put (struct saved_frames *frames, call_frame_t *frame, - int32_t op, int8_t type, int64_t callid); -call_frame_t *saved_frames_get (struct saved_frames *frames, int32_t op, - int8_t type, int64_t callid); - -struct saved_frame * -saved_frames_get_timedout (struct saved_frames *frames, int8_t type, - uint32_t timeout, struct timeval *current); - -void gf_client_saved_frames_destroy (xlator_t *this, struct saved_frames *frames, - gf_op_t gf_fops[], gf_op_t gf_mops[], - gf_op_t gf_cbks[]); - -#endif /* _SAVED_FRAMES_H */ diff --git a/xlators/protocol/legacy/lib/Makefile.am b/xlators/protocol/legacy/lib/Makefile.am deleted file mode 100644 index d471a3f9243..00000000000 --- a/xlators/protocol/legacy/lib/Makefile.am +++ /dev/null @@ -1,3 +0,0 @@ -SUBDIRS = src - -CLEANFILES = diff --git a/xlators/protocol/legacy/lib/src/Makefile.am b/xlators/protocol/legacy/lib/src/Makefile.am deleted file mode 100644 index 1f0e93e3047..00000000000 --- a/xlators/protocol/legacy/lib/src/Makefile.am +++ /dev/null @@ -1,14 +0,0 @@ -lib_LTLIBRARIES = libgfproto.la - -libgfproto_la_CFLAGS = -fPIC -Wall -g -shared -nostartfiles $(GF_CFLAGS) $(GF_DARWIN_LIBGLUSTERFS_CFLAGS) - -libgfproto_la_CPPFLAGS = -D_FILE_OFFSET_BITS=64 -D__USE_FILE_OFFSET64 -D_GNU_SOURCE \ - -D$(GF_HOST_OS) -DLIBDIR=\"$(libdir)/glusterfs/$(PACKAGE_VERSION)/auth\" \ - -DTRANSPORTDIR=\"$(libdir)/glusterfs/$(PACKAGE_VERSION)/transport\" \ - -I$(CONTRIBDIR)/rbtree -I$(top_srcdir)/libglusterfs/src/ - -libgfproto_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la - -libgfproto_la_SOURCES = transport.c protocol.c - -noinst_HEADERS = transport.h protocol.h diff --git a/xlators/protocol/legacy/lib/src/protocol.c b/xlators/protocol/legacy/lib/src/protocol.c deleted file mode 100644 index 63950f43dec..00000000000 --- a/xlators/protocol/legacy/lib/src/protocol.c +++ /dev/null @@ -1,108 +0,0 @@ - -#include "globals.h" -#include "compat.h" -#include "protocol.h" - -char *gf_mop_list[GF_MOP_MAXVALUE]; -char *gf_cbk_list[GF_CBK_MAXVALUE]; - -static int -gf_dirent_nb_size (gf_dirent_t *entries) -{ - return (sizeof (struct gf_dirent_nb) + strlen (entries->d_name) + 1); -} - -int -gf_dirent_serialize (gf_dirent_t *entries, char *buf, size_t buf_size) -{ - struct gf_dirent_nb *entry_nb = NULL; - gf_dirent_t *entry = NULL; - int size = 0; - int entry_size = 0; - - - list_for_each_entry (entry, &entries->list, list) { - entry_size = gf_dirent_nb_size (entry); - - if (buf && (size + entry_size <= buf_size)) { - entry_nb = (void *) (buf + size); - - entry_nb->d_ino = hton64 (entry->d_ino); - entry_nb->d_off = hton64 (entry->d_off); - entry_nb->d_len = hton32 (entry->d_len); - entry_nb->d_type = hton32 (entry->d_type); - - gf_stat_from_iatt (&entry_nb->d_stat, &entry->d_stat); - - strcpy (entry_nb->d_name, entry->d_name); - } - size += entry_size; - } - - return size; -} - - -int -gf_dirent_unserialize (gf_dirent_t *entries, const char *buf, size_t buf_size) -{ - struct gf_dirent_nb *entry_nb = NULL; - int remaining_size = 0; - int least_dirent_size = 0; - int count = 0; - gf_dirent_t *entry = NULL; - int entry_strlen = 0; - int entry_len = 0; - - - remaining_size = buf_size; - least_dirent_size = (sizeof (struct gf_dirent_nb) + 2); - - while (remaining_size >= least_dirent_size) { - entry_nb = (void *)(buf + (buf_size - remaining_size)); - - entry_strlen = strnlen (entry_nb->d_name, remaining_size); - if (entry_strlen == remaining_size) { - break; - } - - entry_len = sizeof (gf_dirent_t) + entry_strlen + 1; - entry = GF_CALLOC (1, entry_len, gf_common_mt_gf_dirent_t); - if (!entry) { - break; - } - - entry->d_ino = ntoh64 (entry_nb->d_ino); - entry->d_off = ntoh64 (entry_nb->d_off); - entry->d_len = ntoh32 (entry_nb->d_len); - entry->d_type = ntoh32 (entry_nb->d_type); - - gf_stat_to_iatt (&entry_nb->d_stat, &entry->d_stat); - - strcpy (entry->d_name, entry_nb->d_name); - - list_add_tail (&entry->list, &entries->list); - - remaining_size -= (sizeof (*entry_nb) + entry_strlen + 1); - count++; - } - - return count; -} - -int -protocol_common_init (void) -{ - gf_mop_list[GF_MOP_SETVOLUME] = "SETVOLUME"; - gf_mop_list[GF_MOP_GETVOLUME] = "GETVOLUME"; - gf_mop_list[GF_MOP_SETSPEC] = "SETSPEC"; - gf_mop_list[GF_MOP_GETSPEC] = "GETSPEC"; - gf_mop_list[GF_MOP_LOG] = "LOG"; - gf_mop_list[GF_MOP_PING] = "PING"; - - gf_cbk_list[GF_CBK_FORGET] = "FORGET"; - gf_cbk_list[GF_CBK_RELEASE] = "RELEASE"; - gf_cbk_list[GF_CBK_RELEASEDIR] = "RELEASEDIR"; - - return 0; -} diff --git a/xlators/protocol/legacy/lib/src/protocol.h b/xlators/protocol/legacy/lib/src/protocol.h deleted file mode 100644 index e929693d7d8..00000000000 --- a/xlators/protocol/legacy/lib/src/protocol.h +++ /dev/null @@ -1,1118 +0,0 @@ -/* - Copyright (c) 2006-2009 Gluster, Inc. <http://www.gluster.com> - This file is part of GlusterFS. - - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. -*/ - -#ifndef _PROTOCOL_H -#define _PROTOCOL_H - -#ifndef _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif - -#include <inttypes.h> -#include <sys/time.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <sys/statvfs.h> -#include <unistd.h> -#include <fcntl.h> - -#include "byte-order.h" -#include "iatt.h" - -/* Any changes in the protocol structure or adding new '[f,m]ops' needs to - * bump the protocol version by "0.1" - */ - -#define GF_PROTOCOL_VERSION "3.0" - -extern char *gf_mop_list[]; -extern char *gf_cbk_list[]; - -/* NOTE: add members ONLY at the end (just before _MAXVALUE) */ -typedef enum { - GF_PROTO_FOP_STAT, /* 0 */ - GF_PROTO_FOP_READLINK, /* 1 */ - GF_PROTO_FOP_MKNOD, /* 2 */ - GF_PROTO_FOP_MKDIR, - GF_PROTO_FOP_UNLINK, - GF_PROTO_FOP_RMDIR, /* 5 */ - GF_PROTO_FOP_SYMLINK, - GF_PROTO_FOP_RENAME, - GF_PROTO_FOP_LINK, - GF_PROTO_FOP_TRUNCATE, - GF_PROTO_FOP_OPEN, /* 10 */ - GF_PROTO_FOP_READ, - GF_PROTO_FOP_WRITE, - GF_PROTO_FOP_STATFS, /* 15 */ - GF_PROTO_FOP_FLUSH, - GF_PROTO_FOP_FSYNC, - GF_PROTO_FOP_SETXATTR, - GF_PROTO_FOP_GETXATTR, - GF_PROTO_FOP_REMOVEXATTR,/* 20 */ - GF_PROTO_FOP_OPENDIR, - GF_PROTO_FOP_GETDENTS, - GF_PROTO_FOP_FSYNCDIR, - GF_PROTO_FOP_ACCESS, - GF_PROTO_FOP_CREATE, /* 25 */ - GF_PROTO_FOP_FTRUNCATE, - GF_PROTO_FOP_FSTAT, - GF_PROTO_FOP_LK, - GF_PROTO_FOP_LOOKUP, - GF_PROTO_FOP_SETDENTS, - GF_PROTO_FOP_READDIR, - GF_PROTO_FOP_INODELK, /* 35 */ - GF_PROTO_FOP_FINODELK, - GF_PROTO_FOP_ENTRYLK, - GF_PROTO_FOP_FENTRYLK, - GF_PROTO_FOP_CHECKSUM, - GF_PROTO_FOP_XATTROP, /* 40 */ - GF_PROTO_FOP_FXATTROP, - GF_PROTO_FOP_LOCK_NOTIFY, - GF_PROTO_FOP_LOCK_FNOTIFY, - GF_PROTO_FOP_FGETXATTR, - GF_PROTO_FOP_FSETXATTR, /* 45 */ - GF_PROTO_FOP_RCHECKSUM, - GF_PROTO_FOP_SETATTR, - GF_PROTO_FOP_FSETATTR, - GF_PROTO_FOP_READDIRP, - GF_PROTO_FOP_MAXVALUE, -} glusterfs_proto_fop_t; - -/* NOTE: add members ONLY at the end (just before _MAXVALUE) */ -typedef enum { - GF_MOP_SETVOLUME, /* 0 */ - GF_MOP_GETVOLUME, /* 1 */ - GF_MOP_STATS, - GF_MOP_SETSPEC, - GF_MOP_GETSPEC, - GF_MOP_PING, /* 5 */ - GF_MOP_LOG, - GF_MOP_NOTIFY, - GF_MOP_MAXVALUE, /* 8 */ -} glusterfs_mop_t; - -typedef enum { - GF_CBK_FORGET, /* 0 */ - GF_CBK_RELEASE, /* 1 */ - GF_CBK_RELEASEDIR, /* 2 */ - GF_CBK_MAXVALUE /* 3 */ -} glusterfs_cbk_t; - -typedef enum { - GF_OP_TYPE_FOP_REQUEST = 1, - GF_OP_TYPE_MOP_REQUEST, - GF_OP_TYPE_CBK_REQUEST, - GF_OP_TYPE_FOP_REPLY, - GF_OP_TYPE_MOP_REPLY, - GF_OP_TYPE_CBK_REPLY -} glusterfs_op_type_t; - - -struct gf_stat { - uint64_t ino; - uint64_t size; - uint64_t blocks; - uint64_t dev; - uint32_t rdev; - uint32_t mode; - uint32_t nlink; - uint32_t uid; - uint32_t gid; - uint32_t blksize; - uint32_t atime; - uint32_t atime_nsec; - uint32_t mtime ; - uint32_t mtime_nsec; - uint32_t ctime; - uint32_t ctime_nsec; -} __attribute__((packed)); - - -static inline void -gf_stat_to_stat (struct gf_stat *gf_stat, struct stat *stat) -{ - stat->st_dev = ntoh64 (gf_stat->dev); - stat->st_ino = ntoh64 (gf_stat->ino); - stat->st_mode = ntoh32 (gf_stat->mode); - stat->st_nlink = ntoh32 (gf_stat->nlink); - stat->st_uid = ntoh32 (gf_stat->uid); - stat->st_gid = ntoh32 (gf_stat->gid); - stat->st_rdev = ntoh32 (gf_stat->rdev); - stat->st_size = ntoh64 (gf_stat->size); - stat->st_blksize = ntoh32 (gf_stat->blksize); - stat->st_blocks = ntoh64 (gf_stat->blocks); - stat->st_atime = ntoh32 (gf_stat->atime); - stat->st_mtime = ntoh32 (gf_stat->mtime); - stat->st_ctime = ntoh32 (gf_stat->ctime); - ST_ATIM_NSEC_SET(stat, ntoh32 (gf_stat->atime_nsec)); - ST_MTIM_NSEC_SET(stat, ntoh32 (gf_stat->mtime_nsec)); - ST_CTIM_NSEC_SET(stat, ntoh32 (gf_stat->ctime_nsec)); -} - - -static inline void -gf_stat_from_stat (struct gf_stat *gf_stat, struct stat *stat) -{ - gf_stat->dev = hton64 (stat->st_dev); - gf_stat->ino = hton64 (stat->st_ino); - gf_stat->mode = hton32 (stat->st_mode); - gf_stat->nlink = hton32 (stat->st_nlink); - gf_stat->uid = hton32 (stat->st_uid); - gf_stat->gid = hton32 (stat->st_gid); - gf_stat->rdev = hton32 (stat->st_rdev); - gf_stat->size = hton64 (stat->st_size); - gf_stat->blksize = hton32 (stat->st_blksize); - gf_stat->blocks = hton64 (stat->st_blocks); - gf_stat->atime = hton32 (stat->st_atime); - gf_stat->mtime = hton32 (stat->st_mtime); - gf_stat->ctime = hton32 (stat->st_ctime); - gf_stat->atime_nsec = hton32 (ST_ATIM_NSEC(stat)); - gf_stat->mtime_nsec = hton32 (ST_MTIM_NSEC(stat)); - gf_stat->ctime_nsec = hton32 (ST_CTIM_NSEC(stat)); -} - - -static inline void -gf_stat_to_iatt (struct gf_stat *gf_stat, struct iatt *iatt) -{ - iatt->ia_ino = ntoh64 (gf_stat->ino); - iatt->ia_dev = ntoh64 (gf_stat->dev); - iatt->ia_type = ia_type_from_st_mode (ntoh32 (gf_stat->mode)); - iatt->ia_prot = ia_prot_from_st_mode (ntoh32 (gf_stat->mode)); - iatt->ia_nlink = ntoh32 (gf_stat->nlink); - iatt->ia_uid = ntoh32 (gf_stat->uid); - iatt->ia_gid = ntoh32 (gf_stat->gid); - iatt->ia_rdev = ntoh64 (gf_stat->rdev); - iatt->ia_size = ntoh64 (gf_stat->size); - iatt->ia_blksize = ntoh32 (gf_stat->blksize); - iatt->ia_blocks = ntoh64 (gf_stat->blocks); - iatt->ia_atime = ntoh32 (gf_stat->atime); - iatt->ia_atime_nsec = ntoh32 (gf_stat->atime_nsec); - iatt->ia_mtime = ntoh32 (gf_stat->mtime); - iatt->ia_mtime_nsec = ntoh32 (gf_stat->mtime_nsec); - iatt->ia_ctime = ntoh32 (gf_stat->ctime); - iatt->ia_ctime_nsec = ntoh32 (gf_stat->ctime_nsec); - - iatt->ia_gen = ntoh64 (gf_stat->dev); -} - - -static inline void -gf_stat_from_iatt (struct gf_stat *gf_stat, struct iatt *iatt) -{ - gf_stat->ino = hton64 (iatt->ia_ino); - gf_stat->dev = hton64 (iatt->ia_dev); - gf_stat->mode = hton32 (st_mode_from_ia (iatt->ia_prot, - iatt->ia_type)); - gf_stat->nlink = hton32 (iatt->ia_nlink); - gf_stat->uid = hton32 (iatt->ia_uid); - gf_stat->gid = hton32 (iatt->ia_gid); - gf_stat->rdev = hton32 (iatt->ia_rdev); - gf_stat->size = hton64 (iatt->ia_size); - gf_stat->blksize = hton32 (iatt->ia_blksize); - gf_stat->blocks = hton64 (iatt->ia_blocks); - gf_stat->atime = hton32 (iatt->ia_atime); - gf_stat->atime_nsec = hton32 (iatt->ia_atime_nsec); - gf_stat->mtime = hton32 (iatt->ia_mtime); - gf_stat->mtime_nsec = hton32 (iatt->ia_mtime_nsec); - gf_stat->ctime = hton32 (iatt->ia_ctime); - gf_stat->ctime_nsec = hton32 (iatt->ia_ctime_nsec); - - gf_stat->dev = hton64 (iatt->ia_gen); - -} - - -struct gf_statfs { - uint64_t bsize; - uint64_t frsize; - uint64_t blocks; - uint64_t bfree; - uint64_t bavail; - uint64_t files; - uint64_t ffree; - uint64_t favail; - uint64_t fsid; - uint64_t flag; - uint64_t namemax; -} __attribute__((packed)); - - -static inline void -gf_statfs_to_statfs (struct gf_statfs *gf_stat, struct statvfs *stat) -{ - stat->f_bsize = ntoh64 (gf_stat->bsize); - stat->f_frsize = ntoh64 (gf_stat->frsize); - stat->f_blocks = ntoh64 (gf_stat->blocks); - stat->f_bfree = ntoh64 (gf_stat->bfree); - stat->f_bavail = ntoh64 (gf_stat->bavail); - stat->f_files = ntoh64 (gf_stat->files); - stat->f_ffree = ntoh64 (gf_stat->ffree); - stat->f_favail = ntoh64 (gf_stat->favail); - stat->f_fsid = ntoh64 (gf_stat->fsid); - stat->f_flag = ntoh64 (gf_stat->flag); - stat->f_namemax = ntoh64 (gf_stat->namemax); -} - - -static inline void -gf_statfs_from_statfs (struct gf_statfs *gf_stat, struct statvfs *stat) -{ - gf_stat->bsize = hton64 (stat->f_bsize); - gf_stat->frsize = hton64 (stat->f_frsize); - gf_stat->blocks = hton64 (stat->f_blocks); - gf_stat->bfree = hton64 (stat->f_bfree); - gf_stat->bavail = hton64 (stat->f_bavail); - gf_stat->files = hton64 (stat->f_files); - gf_stat->ffree = hton64 (stat->f_ffree); - gf_stat->favail = hton64 (stat->f_favail); - gf_stat->fsid = hton64 (stat->f_fsid); - gf_stat->flag = hton64 (stat->f_flag); - gf_stat->namemax = hton64 (stat->f_namemax); -} - - -struct gf_flock { - uint16_t type; - uint16_t whence; - uint64_t start; - uint64_t len; - uint32_t pid; -} __attribute__((packed)); - - -static inline void -gf_flock_to_flock (struct gf_flock *gf_flock, struct flock *flock) -{ - flock->l_type = ntoh16 (gf_flock->type); - flock->l_whence = ntoh16 (gf_flock->whence); - flock->l_start = ntoh64 (gf_flock->start); - flock->l_len = ntoh64 (gf_flock->len); - flock->l_pid = ntoh32 (gf_flock->pid); -} - - -static inline void -gf_flock_from_flock (struct gf_flock *gf_flock, struct flock *flock) -{ - gf_flock->type = hton16 (flock->l_type); - gf_flock->whence = hton16 (flock->l_whence); - gf_flock->start = hton64 (flock->l_start); - gf_flock->len = hton64 (flock->l_len); - gf_flock->pid = hton32 (flock->l_pid); -} - - -struct gf_timespec { - uint32_t tv_sec; - uint32_t tv_nsec; -} __attribute__((packed)); - - -static inline void -gf_timespec_to_timespec (struct gf_timespec *gf_ts, struct timespec *ts) -{ - - ts[0].tv_sec = ntoh32 (gf_ts[0].tv_sec); - ts[0].tv_nsec = ntoh32 (gf_ts[0].tv_nsec); - ts[1].tv_sec = ntoh32 (gf_ts[1].tv_sec); - ts[1].tv_nsec = ntoh32 (gf_ts[1].tv_nsec); -} - - -static inline void -gf_timespec_from_timespec (struct gf_timespec *gf_ts, struct timespec *ts) -{ - gf_ts[0].tv_sec = hton32 (ts[0].tv_sec); - gf_ts[0].tv_nsec = hton32 (ts[0].tv_nsec); - gf_ts[1].tv_sec = hton32 (ts[1].tv_sec); - gf_ts[1].tv_nsec = hton32 (ts[1].tv_nsec); -} - - -#define GF_O_ACCMODE 003 -#define GF_O_RDONLY 00 -#define GF_O_WRONLY 01 -#define GF_O_RDWR 02 -#define GF_O_CREAT 0100 -#define GF_O_EXCL 0200 -#define GF_O_NOCTTY 0400 -#define GF_O_TRUNC 01000 -#define GF_O_APPEND 02000 -#define GF_O_NONBLOCK 04000 -#define GF_O_SYNC 010000 -#define GF_O_ASYNC 020000 - -#define GF_O_DIRECT 040000 -#define GF_O_DIRECTORY 0200000 -#define GF_O_NOFOLLOW 0400000 -#define GF_O_NOATIME 01000000 -#define GF_O_CLOEXEC 02000000 - -#define GF_O_LARGEFILE 0100000 - -#define XLATE_BIT(from, to, bit) do { \ - if (from & bit) \ - to = to | GF_##bit; \ - } while (0) - -#define UNXLATE_BIT(from, to, bit) do { \ - if (from & GF_##bit) \ - to = to | bit; \ - } while (0) - -#define XLATE_ACCESSMODE(from, to) do { \ - switch (from & O_ACCMODE) { \ - case O_RDONLY: to |= GF_O_RDONLY; \ - break; \ - case O_WRONLY: to |= GF_O_WRONLY; \ - break; \ - case O_RDWR: to |= GF_O_RDWR; \ - break; \ - } \ - } while (0) - -#define UNXLATE_ACCESSMODE(from, to) do { \ - switch (from & GF_O_ACCMODE) { \ - case GF_O_RDONLY: to |= O_RDONLY; \ - break; \ - case GF_O_WRONLY: to |= O_WRONLY; \ - break; \ - case GF_O_RDWR: to |= O_RDWR; \ - break; \ - } \ - } while (0) - -static inline uint32_t -gf_flags_from_flags (uint32_t flags) -{ - uint32_t gf_flags = 0; - - XLATE_ACCESSMODE (flags, gf_flags); - - XLATE_BIT (flags, gf_flags, O_CREAT); - XLATE_BIT (flags, gf_flags, O_EXCL); - XLATE_BIT (flags, gf_flags, O_NOCTTY); - XLATE_BIT (flags, gf_flags, O_TRUNC); - XLATE_BIT (flags, gf_flags, O_APPEND); - XLATE_BIT (flags, gf_flags, O_NONBLOCK); - XLATE_BIT (flags, gf_flags, O_SYNC); - XLATE_BIT (flags, gf_flags, O_ASYNC); - - XLATE_BIT (flags, gf_flags, O_DIRECT); - XLATE_BIT (flags, gf_flags, O_DIRECTORY); - XLATE_BIT (flags, gf_flags, O_NOFOLLOW); -#ifdef O_NOATIME - XLATE_BIT (flags, gf_flags, O_NOATIME); -#endif -#ifdef O_CLOEXEC - XLATE_BIT (flags, gf_flags, O_CLOEXEC); -#endif - XLATE_BIT (flags, gf_flags, O_LARGEFILE); - - return gf_flags; -} - -static inline uint32_t -gf_flags_to_flags (uint32_t gf_flags) -{ - uint32_t flags = 0; - - UNXLATE_ACCESSMODE (gf_flags, flags); - - UNXLATE_BIT (gf_flags, flags, O_CREAT); - UNXLATE_BIT (gf_flags, flags, O_EXCL); - UNXLATE_BIT (gf_flags, flags, O_NOCTTY); - UNXLATE_BIT (gf_flags, flags, O_TRUNC); - UNXLATE_BIT (gf_flags, flags, O_APPEND); - UNXLATE_BIT (gf_flags, flags, O_NONBLOCK); - UNXLATE_BIT (gf_flags, flags, O_SYNC); - UNXLATE_BIT (gf_flags, flags, O_ASYNC); - - UNXLATE_BIT (gf_flags, flags, O_DIRECT); - UNXLATE_BIT (gf_flags, flags, O_DIRECTORY); - UNXLATE_BIT (gf_flags, flags, O_NOFOLLOW); -#ifdef O_NOATIME - UNXLATE_BIT (gf_flags, flags, O_NOATIME); -#endif -#ifdef O_CLOEXEC - UNXLATE_BIT (gf_flags, flags, O_CLOEXEC); -#endif - UNXLATE_BIT (gf_flags, flags, O_LARGEFILE); - - return flags; -} - - -typedef struct { - uint64_t ino; - uint64_t gen; - char path[0]; /* NULL terminated */ -} __attribute__((packed)) gf_fop_stat_req_t;; -typedef struct { - struct gf_stat stat; -} __attribute__((packed)) gf_fop_stat_rsp_t; - - -typedef struct { - uint64_t ino; - uint64_t gen; - uint32_t size; - char path[0]; /* NULL terminated */ -} __attribute__((packed)) gf_fop_readlink_req_t; -typedef struct { - struct gf_stat buf; - char path[0]; /* NULL terminated */ -} __attribute__((packed)) gf_fop_readlink_rsp_t; - - -typedef struct { - uint64_t par; - uint64_t gen; - uint64_t dev; - uint32_t mode; - char path[0]; /* NULL terminated */ - char bname[0]; /* NULL terminated */ -} __attribute__((packed)) gf_fop_mknod_req_t; -typedef struct { - struct gf_stat stat; - struct gf_stat preparent; - struct gf_stat postparent; -} __attribute__((packed)) gf_fop_mknod_rsp_t; - - -typedef struct { - uint64_t par; - uint64_t gen; - uint32_t mode; - char path[0]; /* NULL terminated */ - char bname[0]; /* NULL terminated */ -} __attribute__((packed)) gf_fop_mkdir_req_t; -typedef struct { - struct gf_stat stat; - struct gf_stat preparent; - struct gf_stat postparent; -} __attribute__((packed)) gf_fop_mkdir_rsp_t; - - -typedef struct { - uint64_t par; - uint64_t gen; - char path[0]; /* NULL terminated */ - char bname[0]; /* NULL terminated */ -} __attribute__((packed)) gf_fop_unlink_req_t; -typedef struct { - struct gf_stat preparent; - struct gf_stat postparent; -} __attribute__((packed)) gf_fop_unlink_rsp_t; - - -typedef struct { - uint64_t par; - uint64_t gen; - char path[0]; - char bname[0]; /* NULL terminated */ -} __attribute__((packed)) gf_fop_rmdir_req_t; -typedef struct { - struct gf_stat preparent; - struct gf_stat postparent; -} __attribute__((packed)) gf_fop_rmdir_rsp_t; - - -typedef struct { - uint64_t par; - uint64_t gen; - char path[0]; - char bname[0]; - char linkname[0]; -} __attribute__((packed)) gf_fop_symlink_req_t; -typedef struct { - struct gf_stat stat; - struct gf_stat preparent; - struct gf_stat postparent; -}__attribute__((packed)) gf_fop_symlink_rsp_t; - - -typedef struct { - uint64_t oldpar; - uint64_t oldgen; - uint64_t newpar; - uint64_t newgen; - char oldpath[0]; - char oldbname[0]; /* NULL terminated */ - char newpath[0]; - char newbname[0]; /* NULL terminated */ -} __attribute__((packed)) gf_fop_rename_req_t; -typedef struct { - struct gf_stat stat; - struct gf_stat preoldparent; - struct gf_stat postoldparent; - struct gf_stat prenewparent; - struct gf_stat postnewparent; -} __attribute__((packed)) gf_fop_rename_rsp_t; - - -typedef struct { - uint64_t oldino; - uint64_t oldgen; - uint64_t newpar; - uint64_t newgen; - char oldpath[0]; - char newpath[0]; - char newbname[0]; -}__attribute__((packed)) gf_fop_link_req_t; -typedef struct { - struct gf_stat stat; - struct gf_stat preparent; - struct gf_stat postparent; -} __attribute__((packed)) gf_fop_link_rsp_t; - -typedef struct { - uint64_t ino; - uint64_t gen; - uint64_t offset; - char path[0]; -} __attribute__((packed)) gf_fop_truncate_req_t; -typedef struct { - struct gf_stat prestat; - struct gf_stat poststat; -} __attribute__((packed)) gf_fop_truncate_rsp_t; - - -typedef struct { - uint64_t ino; - uint64_t gen; - uint32_t flags; - uint32_t wbflags; - char path[0]; -} __attribute__((packed)) gf_fop_open_req_t; -typedef struct { - int64_t fd; -} __attribute__((packed)) gf_fop_open_rsp_t; - - -typedef struct { - uint64_t ino; - uint64_t gen; - int64_t fd; - uint64_t offset; - uint32_t size; -} __attribute__((packed)) gf_fop_read_req_t; -typedef struct { - struct gf_stat stat; - char buf[0]; -} __attribute__((packed)) gf_fop_read_rsp_t; - - -typedef struct { - uint64_t ino; - uint64_t gen; - int64_t fd; - uint64_t offset; - uint32_t size; -} __attribute__((packed)) gf_fop_write_req_t; -typedef struct { - struct gf_stat prestat; - struct gf_stat poststat; -} __attribute__((packed)) gf_fop_write_rsp_t; - - -typedef struct { - uint64_t ino; - uint64_t gen; - char path[0]; -} __attribute__((packed)) gf_fop_statfs_req_t; -typedef struct { - struct gf_statfs statfs; -} __attribute__((packed)) gf_fop_statfs_rsp_t; - - -typedef struct { - uint64_t ino; - uint64_t gen; - int64_t fd; -} __attribute__((packed)) gf_fop_flush_req_t; -typedef struct { } __attribute__((packed)) gf_fop_flush_rsp_t; - - -typedef struct fsync_req { - uint64_t ino; - uint64_t gen; - int64_t fd; - uint32_t data; -} __attribute__((packed)) gf_fop_fsync_req_t; -typedef struct { - struct gf_stat prestat; - struct gf_stat poststat; -} __attribute__((packed)) gf_fop_fsync_rsp_t; - - -typedef struct { - uint64_t ino; - uint64_t gen; - uint32_t flags; - uint32_t dict_len; - char dict[0]; - char path[0]; -} __attribute__((packed)) gf_fop_setxattr_req_t; -typedef struct { } __attribute__((packed)) gf_fop_setxattr_rsp_t; - - -typedef struct { - uint64_t ino; - uint64_t gen; - int64_t fd; - uint32_t flags; - uint32_t dict_len; - char dict[0]; -} __attribute__((packed)) gf_fop_fsetxattr_req_t; -typedef struct { } __attribute__((packed)) gf_fop_fsetxattr_rsp_t; - - -typedef struct { - uint64_t ino; - uint64_t gen; - uint32_t flags; - uint32_t dict_len; - char dict[0]; - char path[0]; -} __attribute__((packed)) gf_fop_xattrop_req_t; - -typedef struct { - uint32_t dict_len; - char dict[0]; -} __attribute__((packed)) gf_fop_xattrop_rsp_t; - - -typedef struct { - uint64_t ino; - uint64_t gen; - int64_t fd; - uint32_t flags; - uint32_t dict_len; - char dict[0]; -} __attribute__((packed)) gf_fop_fxattrop_req_t; - -typedef struct { - uint32_t dict_len; - char dict[0]; -} __attribute__((packed)) gf_fop_fxattrop_rsp_t; - - -typedef struct { - uint64_t ino; - uint64_t gen; - uint32_t namelen; - char path[0]; - char name[0]; -} __attribute__((packed)) gf_fop_getxattr_req_t; -typedef struct { - uint32_t dict_len; - char dict[0]; -} __attribute__((packed)) gf_fop_getxattr_rsp_t; - - -typedef struct { - uint64_t ino; - uint64_t gen; - int64_t fd; - uint32_t namelen; - char name[0]; -} __attribute__((packed)) gf_fop_fgetxattr_req_t; -typedef struct { - uint32_t dict_len; - char dict[0]; -} __attribute__((packed)) gf_fop_fgetxattr_rsp_t; - - -typedef struct { - uint64_t ino; - uint64_t gen; - char path[0]; - char name[0]; -} __attribute__((packed)) gf_fop_removexattr_req_t; -typedef struct { } __attribute__((packed)) gf_fop_removexattr_rsp_t; - - -typedef struct { - uint64_t ino; - uint64_t gen; - char path[0]; -} __attribute__((packed)) gf_fop_opendir_req_t; -typedef struct { - int64_t fd; -} __attribute__((packed)) gf_fop_opendir_rsp_t; - - -typedef struct fsyncdir_req { - uint64_t ino; - uint64_t gen; - int64_t fd; - int32_t data; -} __attribute__((packed)) gf_fop_fsyncdir_req_t; -typedef struct { -} __attribute__((packed)) gf_fop_fsyncdir_rsp_t; - - -typedef struct { - uint64_t ino; - uint64_t gen; - int64_t fd; - uint64_t offset; - uint32_t size; -} __attribute__((packed)) gf_fop_readdir_req_t; -typedef struct { - uint32_t size; - char buf[0]; -} __attribute__((packed)) gf_fop_readdir_rsp_t; - - -typedef struct { - uint64_t ino; - uint64_t gen; - int64_t fd; - uint64_t offset; - uint32_t size; -} __attribute__((packed)) gf_fop_readdirp_req_t; -typedef struct { - uint32_t size; - char buf[0]; -} __attribute__((packed)) gf_fop_readdirp_rsp_t; - - -typedef struct { - uint64_t ino; - uint64_t gen; - uint32_t mask; - char path[0]; -} __attribute__((packed)) gf_fop_access_req_t; -typedef struct { -} __attribute__((packed)) gf_fop_access_rsp_t; - - -typedef struct { - uint64_t par; - uint64_t gen; - uint32_t flags; - uint32_t mode; - char path[0]; - char bname[0]; -} __attribute__((packed)) gf_fop_create_req_t; -typedef struct { - struct gf_stat stat; - uint64_t fd; - struct gf_stat preparent; - struct gf_stat postparent; -} __attribute__((packed)) gf_fop_create_rsp_t; - - - -typedef struct { - uint64_t ino; - uint64_t gen; - int64_t fd; - uint64_t offset; -} __attribute__((packed)) gf_fop_ftruncate_req_t; -typedef struct { - struct gf_stat prestat; - struct gf_stat poststat; -} __attribute__((packed)) gf_fop_ftruncate_rsp_t; - - -typedef struct { - uint64_t ino; - uint64_t gen; - int64_t fd; -} __attribute__((packed)) gf_fop_fstat_req_t; -typedef struct { - struct gf_stat stat; -} __attribute__((packed)) gf_fop_fstat_rsp_t; - - -typedef struct { - uint64_t ino; - uint64_t gen; - int64_t fd; - uint32_t cmd; - uint32_t type; - struct gf_flock flock; -} __attribute__((packed)) gf_fop_lk_req_t; -typedef struct { - struct gf_flock flock; -} __attribute__((packed)) gf_fop_lk_rsp_t; - -typedef struct { - uint64_t ino; - uint64_t gen; - uint32_t cmd; - uint32_t type; - struct gf_flock flock; - char path[0]; - char volume[0]; -} __attribute__((packed)) gf_fop_inodelk_req_t; -typedef struct { -} __attribute__((packed)) gf_fop_inodelk_rsp_t; - -typedef struct { - uint64_t ino; - uint64_t gen; - int64_t fd; - uint32_t cmd; - uint32_t type; - struct gf_flock flock; - char volume[0]; -} __attribute__((packed)) gf_fop_finodelk_req_t; -typedef struct { -} __attribute__((packed)) gf_fop_finodelk_rsp_t; - -typedef struct { - uint64_t ino; - uint64_t gen; - uint32_t cmd; - uint32_t type; - uint64_t namelen; - char path[0]; - char name[0]; - char volume[0]; -} __attribute__((packed)) gf_fop_entrylk_req_t; -typedef struct { -} __attribute__((packed)) gf_fop_entrylk_rsp_t; - -typedef struct { - uint64_t ino; - uint64_t gen; - int64_t fd; - uint32_t cmd; - uint32_t type; - uint64_t namelen; - char name[0]; - char volume[0]; -} __attribute__((packed)) gf_fop_fentrylk_req_t; -typedef struct { -} __attribute__((packed)) gf_fop_fentrylk_rsp_t; - -typedef struct { - uint64_t ino; /* NOTE: used only in case of 'root' lookup */ - uint64_t par; - uint64_t gen; - uint32_t flags; - uint32_t dictlen; - char path[0]; - char bname[0]; - char dict[0]; -} __attribute__((packed)) gf_fop_lookup_req_t; -typedef struct { - struct gf_stat stat; - struct gf_stat postparent; - uint32_t dict_len; - char dict[0]; -} __attribute__((packed)) gf_fop_lookup_rsp_t; - -typedef struct { - uint64_t ino; - uint64_t gen; - uint32_t flag; - char path[0]; -} __attribute__((packed)) gf_fop_checksum_req_t; -typedef struct { - unsigned char fchecksum[0]; - unsigned char dchecksum[0]; -} __attribute__((packed)) gf_fop_checksum_rsp_t; - -typedef struct { - uint64_t ino; - uint64_t gen; - struct gf_stat stbuf; - int32_t valid; - char path[0]; -} __attribute__((packed)) gf_fop_setattr_req_t; -typedef struct { - struct gf_stat statpre; - struct gf_stat statpost; -} __attribute__((packed)) gf_fop_setattr_rsp_t; - -typedef struct { - int64_t fd; - struct gf_stat stbuf; - int32_t valid; -} __attribute__((packed)) gf_fop_fsetattr_req_t; -typedef struct { - struct gf_stat statpre; - struct gf_stat statpost; -} __attribute__((packed)) gf_fop_fsetattr_rsp_t; - -typedef struct { - int64_t fd; - uint64_t offset; - uint32_t len; -} __attribute__((packed)) gf_fop_rchecksum_req_t; -typedef struct { - uint32_t weak_checksum; - unsigned char strong_checksum[0]; -} __attribute__((packed)) gf_fop_rchecksum_rsp_t; - -typedef struct { - uint32_t flags; - uint32_t keylen; - char key[0]; -} __attribute__((packed)) gf_mop_getspec_req_t; -typedef struct { - char spec[0]; -} __attribute__((packed)) gf_mop_getspec_rsp_t; - - -typedef struct { - uint32_t msglen; - char msg[0]; -} __attribute__((packed)) gf_mop_log_req_t; -typedef struct { -} __attribute__((packed)) gf_mop_log_rsp_t; - - -typedef struct { - uint32_t dict_len; - char buf[0]; -} __attribute__((packed)) gf_mop_setvolume_req_t; -typedef struct { - uint32_t dict_len; - char buf[0]; -} __attribute__((packed)) gf_mop_setvolume_rsp_t; - - -typedef struct { -} __attribute__((packed)) gf_mop_ping_req_t; -typedef struct { -} __attribute__((packed)) gf_mop_ping_rsp_t; - -typedef struct { - uint32_t flags; - char buf[0]; -} __attribute__((packed)) gf_mop_notify_req_t; -typedef struct { - uint32_t flags; - char buf[0]; -} __attribute__((packed)) gf_mop_notify_rsp_t; - -typedef struct { - uint64_t ino; - uint64_t gen; - int64_t fd; -} __attribute__((packed)) gf_cbk_releasedir_req_t; -typedef struct { -} __attribute__((packed)) gf_cbk_releasedir_rsp_t; - - -typedef struct { - uint64_t ino; - uint64_t gen; - int64_t fd; -} __attribute__((packed)) gf_cbk_release_req_t; -typedef struct { -} __attribute__((packed)) gf_cbk_release_rsp_t; - - -typedef struct { - uint32_t count; - uint64_t ino_array[0]; -} __attribute__((packed)) gf_cbk_forget_req_t; -typedef struct { } __attribute__((packed)) gf_cbk_forget_rsp_t; - -typedef struct { - uint32_t pid; - uint32_t uid; - uint32_t gid; - - /* Number of groups being sent through the array above. */ - uint32_t ngrps; - - /* Array of groups to which the uid belongs apart from the primary group - * in gid. - */ - uint32_t groups[GF_REQUEST_MAXGROUPS]; - - uint64_t lk_owner; -} __attribute__ ((packed)) gf_hdr_req_t; - - -typedef struct { - uint32_t op_ret; - uint32_t op_errno; -} __attribute__ ((packed)) gf_hdr_rsp_t; - - -typedef struct { - uint64_t callid; - uint32_t type; - uint32_t op; - uint32_t size; - union { - gf_hdr_req_t req; - gf_hdr_rsp_t rsp; - } __attribute__ ((packed)); -} __attribute__ ((packed)) gf_hdr_common_t; - - -static inline gf_hdr_common_t * -__gf_hdr_new (int size) -{ - gf_hdr_common_t *hdr = NULL; - - /* TODO: use mem-pool */ - hdr = GF_CALLOC (sizeof (gf_hdr_common_t) + size, 1, - gf_common_mt_gf_hdr_common_t); - - if (!hdr) { - return NULL; - } - - hdr->size = hton32 (size); - - return hdr; -} - - -#define gf_hdr_len(type, x) (sizeof (gf_hdr_common_t) + sizeof (*type) + x) -#define gf_hdr_new(type, x) __gf_hdr_new (sizeof (*type) + x) - - -static inline void * -gf_param (gf_hdr_common_t *hdr) -{ - return ((void *)hdr) + sizeof (*hdr); -} - - -struct gf_dirent_nb { - uint64_t d_ino; - uint64_t d_off; - uint32_t d_len; - uint32_t d_type; - struct gf_stat d_stat; - char d_name[0]; -} __attribute__((packed)); - -int -gf_dirent_unserialize (gf_dirent_t *entries, const char *buf, size_t buf_size); -int -gf_dirent_serialize (gf_dirent_t *entries, char *buf, size_t buf_size); - -int protocol_common_init (void); - -#endif diff --git a/xlators/protocol/legacy/lib/src/transport.c b/xlators/protocol/legacy/lib/src/transport.c deleted file mode 100644 index d460d02096e..00000000000 --- a/xlators/protocol/legacy/lib/src/transport.c +++ /dev/null @@ -1,422 +0,0 @@ -/* - Copyright (c) 2006-2009 Gluster, Inc. <http://www.gluster.com> - This file is part of GlusterFS. - - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. -*/ - -#include <dlfcn.h> -#include <stdlib.h> -#include <stdio.h> -#include <sys/poll.h> -#include <fnmatch.h> -#include <stdint.h> - -#ifndef _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif - -#include "logging.h" -#include "transport.h" -#include "glusterfs.h" -#include "xlator.h" -#include "list.h" - - -transport_t * -transport_load (dict_t *options, - xlator_t *xl) -{ - struct transport *trans = NULL, *return_trans = NULL; - char *name = NULL; - void *handle = NULL; - char *type = NULL; - char str[] = "ERROR"; - int32_t ret = -1; - int8_t is_tcp = 0, is_unix = 0, is_ibsdp = 0; - volume_opt_list_t *vol_opt = NULL; - - GF_VALIDATE_OR_GOTO("transport", options, fail); - GF_VALIDATE_OR_GOTO("transport", xl, fail); - - trans = GF_CALLOC (1, sizeof (struct transport), - gf_common_mt_transport); - GF_VALIDATE_OR_GOTO("transport", trans, fail); - - trans->xl = xl; - type = str; - - /* Backward compatibility */ - ret = dict_get_str (options, "transport-type", &type); - if (ret < 0) { - ret = dict_set_str (options, "transport-type", "socket"); - if (ret < 0) - gf_log ("dict", GF_LOG_DEBUG, - "setting transport-type failed"); - gf_log ("transport", GF_LOG_WARNING, - "missing 'option transport-type'. defaulting to " - "\"socket\""); - } else { - { - /* Backword compatibility to handle * /client, - * * /server. - */ - char *tmp = strchr (type, '/'); - if (tmp) - *tmp = '\0'; - } - - is_tcp = strcmp (type, "tcp"); - is_unix = strcmp (type, "unix"); - is_ibsdp = strcmp (type, "ib-sdp"); - if ((is_tcp == 0) || - (is_unix == 0) || - (is_ibsdp == 0)) { - if (is_unix == 0) - ret = dict_set_str (options, - "transport.address-family", - "unix"); - if (is_ibsdp == 0) - ret = dict_set_str (options, - "transport.address-family", - "inet-sdp"); - - if (ret < 0) - gf_log ("dict", GF_LOG_DEBUG, - "setting address-family failed"); - - ret = dict_set_str (options, - "transport-type", "socket"); - if (ret < 0) - gf_log ("dict", GF_LOG_DEBUG, - "setting transport-type failed"); - } - } - - ret = dict_get_str (options, "transport-type", &type); - if (ret < 0) { - GF_FREE (trans); - gf_log ("transport", GF_LOG_ERROR, - "'option transport-type <xx>' missing in volume '%s'", - xl->name); - goto fail; - } - - ret = gf_asprintf (&name, "%s/%s.so", TRANSPORTDIR, type); - if (-1 == ret) { - gf_log ("transport", GF_LOG_ERROR, "asprintf failed"); - goto fail; - } - gf_log ("transport", GF_LOG_DEBUG, - "attempt to load file %s", name); - - handle = dlopen (name, RTLD_NOW|RTLD_GLOBAL); - if (handle == NULL) { - gf_log ("transport", GF_LOG_ERROR, "%s", dlerror ()); - gf_log ("transport", GF_LOG_ERROR, - "volume '%s': transport-type '%s' is not valid or " - "not found on this machine", - xl->name, type); - GF_FREE (name); - GF_FREE (trans); - goto fail; - } - GF_FREE (name); - - trans->ops = dlsym (handle, "tops"); - if (trans->ops == NULL) { - gf_log ("transport", GF_LOG_ERROR, - "dlsym (transport_ops) on %s", dlerror ()); - GF_FREE (trans); - goto fail; - } - - trans->init = dlsym (handle, "init"); - if (trans->init == NULL) { - gf_log ("transport", GF_LOG_ERROR, - "dlsym (gf_transport_init) on %s", dlerror ()); - GF_FREE (trans); - goto fail; - } - - trans->fini = dlsym (handle, "fini"); - if (trans->fini == NULL) { - gf_log ("transport", GF_LOG_ERROR, - "dlsym (gf_transport_fini) on %s", dlerror ()); - GF_FREE (trans); - goto fail; - } - - vol_opt = GF_CALLOC (1, sizeof (volume_opt_list_t), - gf_common_mt_volume_opt_list_t); - vol_opt->given_opt = dlsym (handle, "options"); - if (vol_opt->given_opt == NULL) { - gf_log ("transport", GF_LOG_DEBUG, - "volume option validation not specified"); - } else { - list_add_tail (&vol_opt->list, &xl->volume_options); - if (-1 == - validate_xlator_volume_options (xl, - vol_opt->given_opt)) { - gf_log ("transport", GF_LOG_ERROR, - "volume option validation failed"); - GF_FREE (trans); - goto fail; - } - } - - ret = trans->init (trans); - if (ret != 0) { - gf_log ("transport", GF_LOG_ERROR, - "'%s' initialization failed", type); - GF_FREE (trans); - goto fail; - } - - pthread_mutex_init (&trans->lock, NULL); - return_trans = trans; -fail: - return return_trans; -} - - -int32_t -transport_submit (transport_t *this, char *buf, int32_t len, - struct iovec *vector, int count, - struct iobref *iobref) -{ - int32_t ret = -1; - transport_t *peer_trans = NULL; - struct iobuf *iobuf = NULL; - struct transport_msg *msg = NULL; - - if (this->peer_trans) { - peer_trans = this->peer_trans; - - msg = GF_CALLOC (1, sizeof (*msg), - gf_common_mt_transport_msg); - if (!msg) { - return -ENOMEM; - } - - msg->hdr = buf; - msg->hdrlen = len; - - if (vector) { - iobuf = iobuf_get (this->xl->ctx->iobuf_pool); - if (!iobuf) { - GF_FREE (msg->hdr); - GF_FREE (msg); - return -ENOMEM; - } - - iov_unload (iobuf->ptr, vector, count); - msg->iobuf = iobuf; - } - - pthread_mutex_lock (&peer_trans->handover.mutex); - { - list_add_tail (&msg->list, &peer_trans->handover.msgs); - pthread_cond_broadcast (&peer_trans->handover.cond); - } - pthread_mutex_unlock (&peer_trans->handover.mutex); - - return 0; - } - - GF_VALIDATE_OR_GOTO("transport", this, fail); - GF_VALIDATE_OR_GOTO("transport", this->ops, fail); - - ret = this->ops->submit (this, buf, len, vector, count, iobref); -fail: - return ret; -} - - -int32_t -transport_connect (transport_t *this) -{ - int ret = -1; - - GF_VALIDATE_OR_GOTO("transport", this, fail); - - ret = this->ops->connect (this); -fail: - return ret; -} - - -int32_t -transport_listen (transport_t *this) -{ - int ret = -1; - - GF_VALIDATE_OR_GOTO("transport", this, fail); - - ret = this->ops->listen (this); -fail: - return ret; -} - - -int32_t -transport_disconnect (transport_t *this) -{ - int32_t ret = -1; - - GF_VALIDATE_OR_GOTO("transport", this, fail); - - ret = this->ops->disconnect (this); -fail: - return ret; -} - - -int32_t -transport_destroy (transport_t *this) -{ - int32_t ret = -1; - - GF_VALIDATE_OR_GOTO("transport", this, fail); - - if (this->fini) - this->fini (this); - - pthread_mutex_destroy (&this->lock); - GF_FREE (this); -fail: - return ret; -} - - -transport_t * -transport_ref (transport_t *this) -{ - transport_t *return_this = NULL; - - GF_VALIDATE_OR_GOTO("transport", this, fail); - - pthread_mutex_lock (&this->lock); - { - this->refcount ++; - } - pthread_mutex_unlock (&this->lock); - - return_this = this; -fail: - return return_this; -} - - -int32_t -transport_receive (transport_t *this, char **hdr_p, size_t *hdrlen_p, - struct iobuf **iobuf_p) -{ - int32_t ret = -1; - - GF_VALIDATE_OR_GOTO("transport", this, fail); - - if (this->peer_trans) { - *hdr_p = this->handover.msg->hdr; - *hdrlen_p = this->handover.msg->hdrlen; - *iobuf_p = this->handover.msg->iobuf; - - return 0; - } - - ret = this->ops->receive (this, hdr_p, hdrlen_p, iobuf_p); -fail: - return ret; -} - - -int32_t -transport_unref (transport_t *this) -{ - int32_t refcount = 0; - int32_t ret = -1; - - GF_VALIDATE_OR_GOTO("transport", this, fail); - - pthread_mutex_lock (&this->lock); - { - refcount = --this->refcount; - } - pthread_mutex_unlock (&this->lock); - - if (refcount == 0) { - xlator_notify (this->xl, GF_EVENT_TRANSPORT_CLEANUP, this); - transport_destroy (this); - } - - ret = 0; -fail: - return ret; -} - - -void * -transport_peerproc (void *trans_data) -{ - transport_t *trans = NULL; - struct transport_msg *msg = NULL; - - trans = trans_data; - - while (1) { - pthread_mutex_lock (&trans->handover.mutex); - { - while (list_empty (&trans->handover.msgs)) - pthread_cond_wait (&trans->handover.cond, - &trans->handover.mutex); - - msg = list_entry (trans->handover.msgs.next, - struct transport_msg, list); - - list_del_init (&msg->list); - } - pthread_mutex_unlock (&trans->handover.mutex); - - trans->handover.msg = msg; - - xlator_notify (trans->xl, GF_EVENT_POLLIN, trans); - - GF_FREE (msg); - } -} - - -int -transport_setpeer (transport_t *trans, transport_t *peer_trans) -{ - trans->peer_trans = transport_ref (peer_trans); - - INIT_LIST_HEAD (&trans->handover.msgs); - pthread_cond_init (&trans->handover.cond, NULL); - pthread_mutex_init (&trans->handover.mutex, NULL); - pthread_create (&trans->handover.thread, NULL, - transport_peerproc, trans); - - peer_trans->peer_trans = transport_ref (trans); - - INIT_LIST_HEAD (&peer_trans->handover.msgs); - pthread_cond_init (&peer_trans->handover.cond, NULL); - pthread_mutex_init (&peer_trans->handover.mutex, NULL); - pthread_create (&peer_trans->handover.thread, NULL, - transport_peerproc, peer_trans); - - return 0; -} diff --git a/xlators/protocol/legacy/lib/src/transport.h b/xlators/protocol/legacy/lib/src/transport.h deleted file mode 100644 index f0623d5b417..00000000000 --- a/xlators/protocol/legacy/lib/src/transport.h +++ /dev/null @@ -1,106 +0,0 @@ -/* - Copyright (c) 2006-2009 Gluster, Inc. <http://www.gluster.com> - This file is part of GlusterFS. - - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. -*/ - -#ifndef __TRANSPORT_H__ -#define __TRANSPORT_H__ - -#ifndef _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif - -#include <inttypes.h> - -struct transport_ops; -typedef struct transport transport_t; - -#include "xlator.h" -#include "dict.h" -#include "compat.h" - -typedef struct peer_info { - struct sockaddr_storage sockaddr; - socklen_t sockaddr_len; - char identifier[UNIX_PATH_MAX]; -}peer_info_t; - -struct transport_msg { - struct list_head list; - char *hdr; - int hdrlen; - struct iobuf *iobuf; -}; - -struct transport { - struct transport_ops *ops; - void *private; - void *xl_private; - pthread_mutex_t lock; - int32_t refcount; - - xlator_t *xl; - void *dnscache; - data_t *buf; - int32_t (*init) (transport_t *this); - void (*fini) (transport_t *this); - /* int (*notify) (transport_t *this, int event, void *data); */ - peer_info_t peerinfo; - peer_info_t myinfo; - - transport_t *peer_trans; - struct { - pthread_mutex_t mutex; - pthread_cond_t cond; - pthread_t thread; - struct list_head msgs; - struct transport_msg *msg; - } handover; - -}; - -struct transport_ops { - int32_t (*receive) (transport_t *this, char **hdr_p, size_t *hdrlen_p, - struct iobuf **iobuf_p); - int32_t (*submit) (transport_t *this, char *buf, int len, - struct iovec *vector, int count, - struct iobref *iobref); - int32_t (*connect) (transport_t *this); - int32_t (*listen) (transport_t *this); - int32_t (*disconnect) (transport_t *this); -}; - - -int32_t transport_listen (transport_t *this); -int32_t transport_connect (transport_t *this); -int32_t transport_disconnect (transport_t *this); -int32_t transport_notify (transport_t *this, int event); -int32_t transport_submit (transport_t *this, char *buf, int len, - struct iovec *vector, int count, - struct iobref *iobref); -int32_t transport_receive (transport_t *this, char **hdr_p, size_t *hdrlen_p, - struct iobuf **iobuf_p); -int32_t transport_destroy (transport_t *this); - -transport_t *transport_load (dict_t *options, xlator_t *xl); -transport_t *transport_ref (transport_t *trans); -int32_t transport_unref (transport_t *trans); - -int transport_setpeer (transport_t *trans, transport_t *trans_peer); - -#endif /* __TRANSPORT_H__ */ diff --git a/xlators/protocol/legacy/server/Makefile.am b/xlators/protocol/legacy/server/Makefile.am deleted file mode 100644 index d471a3f9243..00000000000 --- a/xlators/protocol/legacy/server/Makefile.am +++ /dev/null @@ -1,3 +0,0 @@ -SUBDIRS = src - -CLEANFILES = diff --git a/xlators/protocol/legacy/server/src/Makefile.am b/xlators/protocol/legacy/server/src/Makefile.am deleted file mode 100644 index 262fec9ea07..00000000000 --- a/xlators/protocol/legacy/server/src/Makefile.am +++ /dev/null @@ -1,27 +0,0 @@ - -xlator_LTLIBRARIES = server-old.la -xlatordir = $(libdir)/glusterfs/$(PACKAGE_VERSION)/xlator/legacy/protocol - -server_old_la_LDFLAGS = -module -avoidversion - -server_old_la_SOURCES = server-protocol.c server-resolve.c server-helpers.c \ - authenticate.c - -server_old_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la \ - $(top_builddir)/xlators/protocol/legacy/lib/src/libgfproto.la - -noinst_HEADERS = server-protocol.h server-helpers.h server-mem-types.h \ - authenticate.h - -AM_CFLAGS = -fPIC -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -Wall -D$(GF_HOST_OS) \ - -I$(top_srcdir)/libglusterfs/src -shared -nostartfiles \ - -I$(top_srcdir)/contrib/md5/ \ - -DDATADIR=\"$(localstatedir)\" -DCONFDIR=\"$(sysconfdir)/glusterfs\" \ - -DLIBDIR=\"$(libdir)/glusterfs/$(PACKAGE_VERSION)/auth\" \ - $(GF_CFLAGS) -I$(top_srcdir)/xlators/protocol/legacy/lib/src \ - -I$(top_srcdir)/xlators/protocol/lib/src - -CLEANFILES = - -install-data-hook: - ln -sf server-old.so $(DESTDIR)$(xlatordir)/server.so diff --git a/xlators/protocol/legacy/server/src/authenticate.c b/xlators/protocol/legacy/server/src/authenticate.c deleted file mode 100644 index 5205b54df61..00000000000 --- a/xlators/protocol/legacy/server/src/authenticate.c +++ /dev/null @@ -1,249 +0,0 @@ -/* - Copyright (c) 2007-2010 Gluster, Inc. <http://www.gluster.com> - This file is part of GlusterFS. - - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. -*/ - -#ifndef _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif - -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif - -#include <stdio.h> -#include <dlfcn.h> -#include <errno.h> -#include "authenticate.h" - -static void -init (dict_t *this, - char *key, - data_t *value, - void *data) -{ - void *handle = NULL; - char *auth_file = NULL; - auth_handle_t *auth_handle = NULL; - auth_fn_t authenticate = NULL; - int *error = NULL; - int ret = 0; - - /* It gets over written */ - error = data; - - if (!strncasecmp (key, "ip", strlen ("ip"))) { - gf_log ("authenticate", GF_LOG_ERROR, - "AUTHENTICATION MODULE \"IP\" HAS BEEN REPLACED " - "BY \"ADDR\""); - dict_set (this, key, data_from_dynptr (NULL, 0)); - /* TODO: 1.3.x backword compatibility */ - // *error = -1; - // return; - key = "addr"; - } - - ret = gf_asprintf (&auth_file, "%s/%s.so", LIBDIR, key); - if (-1 == ret) { - gf_log ("authenticate", GF_LOG_ERROR, "asprintf failed"); - dict_set (this, key, data_from_dynptr (NULL, 0)); - *error = -1; - return; - } - - handle = dlopen (auth_file, RTLD_LAZY); - if (!handle) { - gf_log ("authenticate", GF_LOG_ERROR, "dlopen(%s): %s\n", - auth_file, dlerror ()); - dict_set (this, key, data_from_dynptr (NULL, 0)); - GF_FREE (auth_file); - *error = -1; - return; - } - GF_FREE (auth_file); - - authenticate = dlsym (handle, "gf_auth"); - if (!authenticate) { - gf_log ("authenticate", GF_LOG_ERROR, - "dlsym(gf_auth) on %s\n", dlerror ()); - dict_set (this, key, data_from_dynptr (NULL, 0)); - *error = -1; - return; - } - - auth_handle = GF_CALLOC (1, sizeof (*auth_handle), - gf_common_mt_auth_handle_t); - if (!auth_handle) { - gf_log ("authenticate", GF_LOG_ERROR, "Out of memory"); - dict_set (this, key, data_from_dynptr (NULL, 0)); - *error = -1; - return; - } - auth_handle->vol_opt = GF_CALLOC (1, sizeof (volume_opt_list_t), - gf_common_mt_volume_opt_list_t); - auth_handle->vol_opt->given_opt = dlsym (handle, "options"); - if (auth_handle->vol_opt->given_opt == NULL) { - gf_log ("authenticate", GF_LOG_DEBUG, - "volume option validation not specified"); - } - - auth_handle->authenticate = authenticate; - auth_handle->handle = handle; - - dict_set (this, key, - data_from_dynptr (auth_handle, sizeof (*auth_handle))); -} - -static void -fini (dict_t *this, - char *key, - data_t *value, - void *data) -{ - auth_handle_t *handle = data_to_ptr (value); - if (handle) { - dlclose (handle->handle); - } -} - -int32_t -gf_auth_init (xlator_t *xl, dict_t *auth_modules) -{ - int ret = 0; - auth_handle_t *handle = NULL; - data_pair_t *pair = NULL; - dict_foreach (auth_modules, init, &ret); - if (!ret) { - pair = auth_modules->members_list; - while (pair) { - handle = data_to_ptr (pair->value); - if (handle) { - list_add_tail (&(handle->vol_opt->list), - &(xl->volume_options)); - if (-1 == - validate_xlator_volume_options (xl, - handle->vol_opt->given_opt)) { - gf_log ("authenticate", GF_LOG_ERROR, - "volume option validation " - "failed"); - ret = -1; - } - } - pair = pair->next; - } - } - if (ret) { - gf_log (xl->name, GF_LOG_ERROR, "authentication init failed"); - dict_foreach (auth_modules, fini, &ret); - ret = -1; - } - return ret; -} - -static dict_t *__input_params; -static dict_t *__config_params; - -void -map (dict_t *this, - char *key, - data_t *value, - void *data) -{ - dict_t *res = data; - auth_fn_t authenticate; - auth_handle_t *handle = NULL; - - if (value && (handle = data_to_ptr (value)) && - (authenticate = handle->authenticate)) { - dict_set (res, key, - int_to_data (authenticate (__input_params, - __config_params))); - } else { - dict_set (res, key, int_to_data (AUTH_DONT_CARE)); - } -} - -void -reduce (dict_t *this, - char *key, - data_t *value, - void *data) -{ - int64_t val = 0; - int64_t *res = data; - if (!data) - return; - - val = data_to_int64 (value); - switch (val) - { - case AUTH_ACCEPT: - if (AUTH_DONT_CARE == *res) - *res = AUTH_ACCEPT; - break; - - case AUTH_REJECT: - *res = AUTH_REJECT; - break; - - case AUTH_DONT_CARE: - break; - } -} - - -auth_result_t -gf_authenticate (dict_t *input_params, - dict_t *config_params, - dict_t *auth_modules) -{ - dict_t *results = NULL; - int64_t result = AUTH_DONT_CARE; - - results = get_new_dict (); - __input_params = input_params; - __config_params = config_params; - - dict_foreach (auth_modules, map, results); - - dict_foreach (results, reduce, &result); - if (AUTH_DONT_CARE == result) { - data_t *peerinfo_data = dict_get (input_params, "peer-info-name"); - char *name = NULL; - - if (peerinfo_data) { - name = peerinfo_data->data; - } - - gf_log ("auth", GF_LOG_ERROR, - "no authentication module is interested in " - "accepting remote-client %s", name); - result = AUTH_REJECT; - } - - dict_destroy (results); - return result; -} - -void -gf_auth_fini (dict_t *auth_modules) -{ - int32_t dummy; - - dict_foreach (auth_modules, fini, &dummy); -} diff --git a/xlators/protocol/legacy/server/src/authenticate.h b/xlators/protocol/legacy/server/src/authenticate.h deleted file mode 100644 index 93d73741b0a..00000000000 --- a/xlators/protocol/legacy/server/src/authenticate.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - Copyright (c) 2007-2009 Gluster, Inc. <http://www.gluster.com> - This file is part of GlusterFS. - - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. -*/ - -#ifndef _AUTHENTICATE_H -#define _AUTHENTICATE_H - -#ifndef _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif - -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif - -#include <stdio.h> -#include <fnmatch.h> -#include "dict.h" -#include "compat.h" -#include "list.h" -#include "xlator.h" - -typedef enum { - AUTH_ACCEPT, - AUTH_REJECT, - AUTH_DONT_CARE -} auth_result_t; - -typedef auth_result_t (*auth_fn_t) (dict_t *input_params, - dict_t *config_params); - -typedef struct { - void *handle; - auth_fn_t authenticate; - volume_opt_list_t *vol_opt; -} auth_handle_t; - -auth_result_t gf_authenticate (dict_t *input_params, - dict_t *config_params, - dict_t *auth_modules); -int32_t gf_auth_init (xlator_t *xl, dict_t *auth_modules); -void gf_auth_fini (dict_t *auth_modules); - -#endif /* _AUTHENTICATE_H */ diff --git a/xlators/protocol/legacy/server/src/server-helpers.c b/xlators/protocol/legacy/server/src/server-helpers.c deleted file mode 100644 index 08f89af5aba..00000000000 --- a/xlators/protocol/legacy/server/src/server-helpers.c +++ /dev/null @@ -1,622 +0,0 @@ -/* - Copyright (c) 2006-2009 Gluster, Inc. <http://www.gluster.com> - This file is part of GlusterFS. - - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. -*/ - -#ifndef _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif - -#include "server-protocol.h" -#include "server-helpers.h" - - - -void -old_server_loc_wipe (loc_t *loc) -{ - if (loc->parent) { - inode_unref (loc->parent); - loc->parent = NULL; - } - - if (loc->inode) { - inode_unref (loc->inode); - loc->inode = NULL; - } - - if (loc->path) - GF_FREE ((char *)loc->path); -} - - -static void -old_server_resolve_wipe (server_resolve_t *resolve) -{ - struct resolve_comp *comp = NULL; - int i = 0; - - if (resolve->path) - GF_FREE (resolve->path); - - if (resolve->bname) - GF_FREE (resolve->bname); - - if (resolve->resolved) - GF_FREE (resolve->resolved); - - loc_wipe (&resolve->deep_loc); - - comp = resolve->components; - if (comp) { - for (i = 0; comp[i].basename; i++) { - if (comp[i].inode) - inode_unref (comp[i].inode); - } - GF_FREE (resolve->components); - } -} - - -void -free_old_server_state (server_state_t *state) -{ - if (state->trans) { - transport_unref (state->trans); - state->trans = NULL; - } - - if (state->fd) { - fd_unref (state->fd); - state->fd = NULL; - } - - if (state->params) { - dict_unref (state->params); - state->params = NULL; - } - - if (state->iobref) { - iobref_unref (state->iobref); - state->iobref = NULL; - } - - if (state->iobuf) { - iobuf_unref (state->iobuf); - state->iobuf = NULL; - } - - if (state->dict) { - dict_unref (state->dict); - state->dict = NULL; - } - - if (state->volume) - GF_FREE ((char *)state->volume); - - if (state->name) - GF_FREE (state->name); - - old_server_loc_wipe (&state->loc); - old_server_loc_wipe (&state->loc2); - - old_server_resolve_wipe (&state->resolve); - old_server_resolve_wipe (&state->resolve2); - - GF_FREE (state); -} - -static struct _lock_table * -gf_lock_table_new (void) -{ - struct _lock_table *new = NULL; - - new = GF_CALLOC (1, sizeof (struct _lock_table), - gf_server_mt_lock_table); - if (new == NULL) { - gf_log ("server-protocol", GF_LOG_CRITICAL, - "failed to allocate memory for new lock table"); - goto out; - } - INIT_LIST_HEAD (&new->dir_lockers); - INIT_LIST_HEAD (&new->file_lockers); - LOCK_INIT (&new->lock); -out: - return new; -} - - -static int -gf_server_nop_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno) -{ - server_state_t *state = NULL; - - state = CALL_STATE(frame); - - if (state) - free_old_server_state (state); - STACK_DESTROY (frame->root); - return 0; -} - - -static int -do_lock_table_cleanup (xlator_t *this, server_connection_t *conn, - call_frame_t *frame, struct _lock_table *ltable) -{ - struct list_head file_lockers, dir_lockers; - call_frame_t *tmp_frame = NULL; - struct flock flock = {0, }; - xlator_t *bound_xl = NULL; - struct _locker *locker = NULL, *tmp = NULL; - int ret = -1; - - bound_xl = conn->bound_xl; - INIT_LIST_HEAD (&file_lockers); - INIT_LIST_HEAD (&dir_lockers); - - LOCK (<able->lock); - { - list_splice_init (<able->file_lockers, - &file_lockers); - - list_splice_init (<able->dir_lockers, &dir_lockers); - } - UNLOCK (<able->lock); - - GF_FREE (ltable); - - flock.l_type = F_UNLCK; - flock.l_start = 0; - flock.l_len = 0; - list_for_each_entry_safe (locker, - tmp, &file_lockers, lockers) { - tmp_frame = copy_frame (frame); - if (tmp_frame == NULL) { - gf_log (this->name, GF_LOG_ERROR, - "out of memory"); - goto out; - } - /* - pid = 0 is a special case that tells posix-locks - to release all locks from this transport - */ - tmp_frame->root->pid = 0; - tmp_frame->root->trans = conn; - - if (locker->fd) { - STACK_WIND (tmp_frame, gf_server_nop_cbk, - bound_xl, - bound_xl->fops->finodelk, - locker->volume, - locker->fd, F_SETLK, &flock); - fd_unref (locker->fd); - } else { - STACK_WIND (tmp_frame, gf_server_nop_cbk, - bound_xl, - bound_xl->fops->inodelk, - locker->volume, - &(locker->loc), F_SETLK, &flock); - loc_wipe (&locker->loc); - } - - GF_FREE (locker->volume); - - list_del_init (&locker->lockers); - GF_FREE (locker); - } - - tmp = NULL; - locker = NULL; - list_for_each_entry_safe (locker, tmp, &dir_lockers, lockers) { - tmp_frame = copy_frame (frame); - - tmp_frame->root->pid = 0; - tmp_frame->root->trans = conn; - - if (locker->fd) { - STACK_WIND (tmp_frame, gf_server_nop_cbk, - bound_xl, - bound_xl->fops->fentrylk, - locker->volume, - locker->fd, NULL, - ENTRYLK_UNLOCK, ENTRYLK_WRLCK); - fd_unref (locker->fd); - } else { - STACK_WIND (tmp_frame, gf_server_nop_cbk, - bound_xl, - bound_xl->fops->entrylk, - locker->volume, - &(locker->loc), NULL, - ENTRYLK_UNLOCK, ENTRYLK_WRLCK); - loc_wipe (&locker->loc); - } - - GF_FREE (locker->volume); - - list_del_init (&locker->lockers); - GF_FREE (locker); - } - ret = 0; - -out: - return ret; -} - - -static int -server_connection_cleanup_flush_cbk (call_frame_t *frame, void *cookie, - xlator_t *this, int32_t op_ret, - int32_t op_errno) -{ - fd_t *fd = NULL; - - fd = frame->local; - - fd_unref (fd); - frame->local = NULL; - - STACK_DESTROY (frame->root); - return 0; -} - - -static int -do_fd_cleanup (xlator_t *this, server_connection_t *conn, call_frame_t *frame, - fdentry_t *fdentries, int fd_count) -{ - fd_t *fd = NULL; - int i = 0, ret = -1; - call_frame_t *tmp_frame = NULL; - xlator_t *bound_xl = NULL; - - bound_xl = conn->bound_xl; - for (i = 0;i < fd_count; i++) { - fd = fdentries[i].fd; - - if (fd != NULL) { - tmp_frame = copy_frame (frame); - if (tmp_frame == NULL) { - gf_log (this->name, GF_LOG_ERROR, - "out of memory"); - goto out; - } - tmp_frame->local = fd; - - tmp_frame->root->pid = 0; - tmp_frame->root->trans = conn; - tmp_frame->root->lk_owner = 0; - STACK_WIND (tmp_frame, - server_connection_cleanup_flush_cbk, - bound_xl, bound_xl->fops->flush, fd); - } - } - - GF_FREE (fdentries); - ret = 0; - -out: - return ret; -} - -static int -do_connection_cleanup (xlator_t *this, server_connection_t *conn, - struct _lock_table *ltable, fdentry_t *fdentries, int fd_count) -{ - int ret = 0; - int saved_ret = 0; - call_frame_t *frame = NULL; - - frame = create_frame (this, this->ctx->pool); - if (frame == NULL) { - gf_log (this->name, GF_LOG_ERROR, "out of memory"); - goto out; - } - - saved_ret = do_lock_table_cleanup (this, conn, frame, ltable); - - if (fdentries != NULL) { - ret = do_fd_cleanup (this, conn, frame, fdentries, fd_count); - } - - STACK_DESTROY (frame->root); - - if (saved_ret || ret) { - ret = -1; - } - -out: - return ret; -} - - -int -gf_server_connection_cleanup (xlator_t *this, server_connection_t *conn) -{ - char do_cleanup = 0; - struct _lock_table *ltable = NULL; - fdentry_t *fdentries = NULL; - uint32_t fd_count = 0; - int ret = 0; - - if (conn == NULL) { - goto out; - } - - pthread_mutex_lock (&conn->lock); - { - conn->active_transports--; - if (conn->active_transports == 0) { - if (conn->ltable) { - ltable = conn->ltable; - conn->ltable = gf_lock_table_new (); - } - - if (conn->fdtable) { - fdentries = gf_fd_fdtable_get_all_fds (conn->fdtable, - &fd_count); - } - do_cleanup = 1; - } - } - pthread_mutex_unlock (&conn->lock); - - if (do_cleanup && conn->bound_xl) - ret = do_connection_cleanup (this, conn, ltable, fdentries, fd_count); - -out: - return ret; -} - - -static int -server_connection_destroy (xlator_t *this, server_connection_t *conn) -{ - call_frame_t *frame = NULL, *tmp_frame = NULL; - xlator_t *bound_xl = NULL; - int32_t ret = -1; - struct list_head file_lockers; - struct list_head dir_lockers; - struct _lock_table *ltable = NULL; - struct _locker *locker = NULL, *tmp = NULL; - struct flock flock = {0,}; - fd_t *fd = NULL; - int32_t i = 0; - fdentry_t *fdentries = NULL; - uint32_t fd_count = 0; - - if (conn == NULL) { - ret = 0; - goto out; - } - - bound_xl = (xlator_t *) (conn->bound_xl); - - if (bound_xl) { - /* trans will have ref_count = 1 after this call, but its - ok since this function is called in - GF_EVENT_TRANSPORT_CLEANUP */ - frame = create_frame (this, this->ctx->pool); - - pthread_mutex_lock (&(conn->lock)); - { - if (conn->ltable) { - ltable = conn->ltable; - conn->ltable = NULL; - } - } - pthread_mutex_unlock (&conn->lock); - - INIT_LIST_HEAD (&file_lockers); - INIT_LIST_HEAD (&dir_lockers); - - if (ltable) { - LOCK (<able->lock); - { - list_splice_init (<able->file_lockers, - &file_lockers); - - list_splice_init (<able->dir_lockers, &dir_lockers); - } - UNLOCK (<able->lock); - GF_FREE (ltable); - } - - flock.l_type = F_UNLCK; - flock.l_start = 0; - flock.l_len = 0; - list_for_each_entry_safe (locker, - tmp, &file_lockers, lockers) { - tmp_frame = copy_frame (frame); - /* - pid = 0 is a special case that tells posix-locks - to release all locks from this transport - */ - tmp_frame->root->pid = 0; - tmp_frame->root->trans = conn; - - if (locker->fd) { - STACK_WIND (tmp_frame, gf_server_nop_cbk, - bound_xl, - bound_xl->fops->finodelk, - locker->volume, - locker->fd, F_SETLK, &flock); - fd_unref (locker->fd); - } else { - STACK_WIND (tmp_frame, gf_server_nop_cbk, - bound_xl, - bound_xl->fops->inodelk, - locker->volume, - &(locker->loc), F_SETLK, &flock); - loc_wipe (&locker->loc); - } - - GF_FREE (locker->volume); - - list_del_init (&locker->lockers); - GF_FREE (locker); - } - - tmp = NULL; - locker = NULL; - list_for_each_entry_safe (locker, tmp, &dir_lockers, lockers) { - tmp_frame = copy_frame (frame); - - tmp_frame->root->pid = 0; - tmp_frame->root->trans = conn; - - if (locker->fd) { - STACK_WIND (tmp_frame, gf_server_nop_cbk, - bound_xl, - bound_xl->fops->fentrylk, - locker->volume, - locker->fd, NULL, - ENTRYLK_UNLOCK, ENTRYLK_WRLCK); - fd_unref (locker->fd); - } else { - STACK_WIND (tmp_frame, gf_server_nop_cbk, - bound_xl, - bound_xl->fops->entrylk, - locker->volume, - &(locker->loc), NULL, - ENTRYLK_UNLOCK, ENTRYLK_WRLCK); - loc_wipe (&locker->loc); - } - - GF_FREE (locker->volume); - - - list_del_init (&locker->lockers); - GF_FREE (locker); - } - - pthread_mutex_lock (&(conn->lock)); - { - if (conn->fdtable) { - fdentries = gf_fd_fdtable_get_all_fds (conn->fdtable, - &fd_count); - gf_fd_fdtable_destroy (conn->fdtable); - conn->fdtable = NULL; - } - } - pthread_mutex_unlock (&conn->lock); - - if (fdentries != NULL) { - for (i = 0; i < fd_count; i++) { - fd = fdentries[i].fd; - if (fd != NULL) { - tmp_frame = copy_frame (frame); - tmp_frame->local = fd; - - STACK_WIND (tmp_frame, - server_connection_cleanup_flush_cbk, - bound_xl, - bound_xl->fops->flush, - fd); - } - } - GF_FREE (fdentries); - } - } - - if (frame) { - STACK_DESTROY (frame->root); - } - - gf_log (this->name, GF_LOG_INFO, "destroyed connection of %s", - conn->id); - - GF_FREE (conn->id); - GF_FREE (conn); - -out: - return ret; -} - - -server_connection_t * -gf_server_connection_get (xlator_t *this, const char *id) -{ - server_connection_t *conn = NULL; - server_connection_t *trav = NULL; - server_conf_t *conf = NULL; - - conf = this->private; - - pthread_mutex_lock (&conf->mutex); - { - list_for_each_entry (trav, &conf->conns, list) { - if (!strcmp (id, trav->id)) { - conn = trav; - break; - } - } - - if (!conn) { - conn = (void *) GF_CALLOC (1, sizeof (*conn), - gf_server_mt_server_connection_t); - - conn->id = gf_strdup (id); - conn->fdtable = gf_fd_fdtable_alloc (); - conn->ltable = gf_lock_table_new (); - - pthread_mutex_init (&conn->lock, NULL); - - list_add (&conn->list, &conf->conns); - } - - conn->ref++; - conn->active_transports++; - } - pthread_mutex_unlock (&conf->mutex); - - return conn; -} - - -void -gf_server_connection_put (xlator_t *this, server_connection_t *conn) -{ - server_conf_t *conf = NULL; - server_connection_t *todel = NULL; - - if (conn == NULL) { - goto out; - } - - conf = this->private; - - pthread_mutex_lock (&conf->mutex); - { - conn->ref--; - - if (!conn->ref) { - list_del_init (&conn->list); - todel = conn; - } - } - pthread_mutex_unlock (&conf->mutex); - - if (todel) { - server_connection_destroy (this, todel); - } - -out: - return; -} diff --git a/xlators/protocol/legacy/server/src/server-helpers.h b/xlators/protocol/legacy/server/src/server-helpers.h deleted file mode 100644 index d22b3211264..00000000000 --- a/xlators/protocol/legacy/server/src/server-helpers.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - Copyright (c) 2006-2009 Gluster, Inc. <http://www.gluster.com> - This file is part of GlusterFS. - - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. -*/ - -#ifndef __SERVER_HELPERS_H__ -#define __SERVER_HELPERS_H__ - -#define CALL_STATE(frame) ((server_state_t *)frame->root->state) - -#define BOUND_XL(frame) ((xlator_t *) CALL_STATE(frame)->bound_xl) - -#define TRANSPORT_FROM_FRAME(frame) ((transport_t *) CALL_STATE(frame)->trans) - -#define SERVER_CONNECTION(frame) \ - ((server_connection_t *) TRANSPORT_FROM_FRAME(frame)->xl_private) - -#define SERVER_CONF(frame) \ - ((server_conf_t *)TRANSPORT_FROM_FRAME(frame)->xl->private) - -#define TRANSPORT_FROM_XLATOR(this) ((((server_conf_t *)this->private))->trans) - -#define INODE_LRU_LIMIT(this) \ - (((server_conf_t *)(this->private))->inode_lru_limit) - -#define IS_ROOT_INODE(inode) (inode == inode->table->root) - -#define IS_NOT_ROOT(pathlen) ((pathlen > 2)? 1 : 0) - -void free_old_server_state (server_state_t *state); - -void old_server_loc_wipe (loc_t *loc); - -#endif /* __SERVER_HELPERS_H__ */ diff --git a/xlators/protocol/legacy/server/src/server-mem-types.h b/xlators/protocol/legacy/server/src/server-mem-types.h deleted file mode 100644 index 86877d79dac..00000000000 --- a/xlators/protocol/legacy/server/src/server-mem-types.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - Copyright (c) 2008-2009 Gluster, Inc. <http://www.gluster.com> - This file is part of GlusterFS. - - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. -*/ - - -#ifndef __AFR_MEM_TYPES_H__ -#define __AFR_MEM_TYPES_H__ - -#include "mem-types.h" - -enum gf_server_mem_types_ { - gf_server_mt_dir_entry_t = gf_common_mt_end + 1, - gf_server_mt_volfile_ctx, - gf_server_mt_server_state_t, - gf_server_mt_server_conf_t, - gf_server_mt_locker, - gf_server_mt_lock_table, - gf_server_mt_char, - gf_server_mt_server_connection_t, - gf_server_mt_resolve_comp, - gf_server_mt_end -}; -#endif - diff --git a/xlators/protocol/legacy/server/src/server-protocol.c b/xlators/protocol/legacy/server/src/server-protocol.c deleted file mode 100644 index b2ce4bd116e..00000000000 --- a/xlators/protocol/legacy/server/src/server-protocol.c +++ /dev/null @@ -1,6587 +0,0 @@ -/* - Copyright (c) 2006-2009 Gluster, Inc. <http://www.gluster.com> - This file is part of GlusterFS. - - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. -*/ - - -#ifndef _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif -#include <time.h> -#include <sys/uio.h> -#include <sys/resource.h> - -#include <libgen.h> - -#include "transport.h" -#include "fnmatch.h" -#include "xlator.h" -#include "protocol.h" -#include "server-protocol.h" -#include "server-helpers.h" -#include "call-stub.h" -#include "defaults.h" -#include "list.h" -#include "dict.h" -#include "compat.h" -#include "compat-errno.h" -#include "statedump.h" -#include "md5.h" - - -static void -print_caller (char *str, int size, call_frame_t *frame) -{ - int filled = 0; - server_state_t *state = NULL; - transport_t *trans = NULL; - - state = CALL_STATE (frame); - trans = state->trans; - - filled += snprintf (str + filled, size - filled, - " Callid=%"PRId64", Client=%s", - frame->root->unique, - trans->peerinfo.identifier); - - return; -} - - -static void -server_print_resolve (char *str, int size, server_resolve_t *resolve) -{ - int filled = 0; - - if (!resolve) { - snprintf (str, size, "<nul>"); - return; - } - - filled += snprintf (str + filled, size - filled, - " Resolve={"); - if (resolve->fd_no != -1) - filled += snprintf (str + filled, size - filled, - "fd=%"PRId64",", (uint64_t) resolve->fd_no); - if (resolve->ino) - filled += snprintf (str + filled, size - filled, - "ino=%"PRIu64",", (uint64_t) resolve->ino); - if (resolve->par) - filled += snprintf (str + filled, size - filled, - "par=%"PRIu64",", (uint64_t) resolve->par); - if (resolve->gen) - filled += snprintf (str + filled, size - filled, - "gen=%"PRIu64",", (uint64_t) resolve->gen); - if (resolve->bname) - filled += snprintf (str + filled, size - filled, - "bname=%s,", resolve->bname); - if (resolve->path) - filled += snprintf (str + filled, size - filled, - "path=%s", resolve->path); - - filled += snprintf (str + filled, size - filled, "}"); -} - - -static void -server_print_loc (char *str, int size, loc_t *loc) -{ - int filled = 0; - - if (!loc) { - snprintf (str, size, "<nul>"); - return; - } - - filled += snprintf (str + filled, size - filled, - " Loc={"); - - if (loc->path) - filled += snprintf (str + filled, size - filled, - "path=%s,", loc->path); - if (loc->inode) - filled += snprintf (str + filled, size - filled, - "inode=%p,", loc->inode); - if (loc->parent) - filled += snprintf (str + filled, size - filled, - "parent=%p", loc->parent); - - filled += snprintf (str + filled, size - filled, "}"); -} - - -static void -server_print_params (char *str, int size, server_state_t *state) -{ - int filled = 0; - - filled += snprintf (str + filled, size - filled, - " Params={"); - - if (state->fd) - filled += snprintf (str + filled, size - filled, - "fd=%p,", state->fd); - if (state->valid) - filled += snprintf (str + filled, size - filled, - "valid=%d,", state->valid); - if (state->flags) - filled += snprintf (str + filled, size - filled, - "flags=%d,", state->flags); - if (state->wbflags) - filled += snprintf (str + filled, size - filled, - "wbflags=%d,", state->wbflags); - if (state->size) - filled += snprintf (str + filled, size - filled, - "size=%zu,", state->size); - if (state->offset) - filled += snprintf (str + filled, size - filled, - "offset=%"PRId64",", state->offset); - if (state->cmd) - filled += snprintf (str + filled, size - filled, - "cmd=%d,", state->cmd); - if (state->type) - filled += snprintf (str + filled, size - filled, - "type=%d,", state->type); - if (state->name) - filled += snprintf (str + filled, size - filled, - "name=%s,", state->name); - if (state->mask) - filled += snprintf (str + filled, size - filled, - "mask=%d,", state->mask); - if (state->volume) - filled += snprintf (str + filled, size - filled, - "volume=%s,", state->volume); - - filled += snprintf (str + filled, size - filled, - "bound_xl=%s}", state->bound_xl->name); -} - - -static int -server_resolve_is_empty (server_resolve_t *resolve) -{ - if (resolve->fd_no != -1) - return 0; - - if (resolve->ino != 0) - return 0; - - if (resolve->gen != 0) - return 0; - - if (resolve->par != 0) - return 0; - - if (resolve->path != 0) - return 0; - - if (resolve->bname != 0) - return 0; - - return 1; -} - -void -gf_server_print_request (call_frame_t *frame) -{ - server_conf_t *conf = NULL; - xlator_t *this = NULL; - server_state_t *state = NULL; - char resolve_vars[256]; - char resolve2_vars[256]; - char loc_vars[256]; - char loc2_vars[256]; - char other_vars[512]; - char caller[512]; - char *op = "UNKNOWN"; - - this = frame->this; - conf = this->private; - - state = CALL_STATE (frame); - - if (!conf->trace) - return; - - memset (resolve_vars, '\0', 256); - memset (resolve2_vars, '\0', 256); - memset (loc_vars, '\0', 256); - memset (loc2_vars, '\0', 256); - memset (other_vars, '\0', 256); - - print_caller (caller, 256, frame); - - if (!server_resolve_is_empty (&state->resolve)) { - server_print_resolve (resolve_vars, 256, &state->resolve); - server_print_loc (loc_vars, 256, &state->loc); - } - - if (!server_resolve_is_empty (&state->resolve2)) { - server_print_resolve (resolve2_vars, 256, &state->resolve2); - server_print_loc (loc2_vars, 256, &state->loc2); - } - - server_print_params (other_vars, 512, state); - - switch (frame->root->type) { - case GF_OP_TYPE_FOP_REQUEST: - case GF_OP_TYPE_FOP_REPLY: - op = gf_fop_list[frame->root->op]; - break; - case GF_OP_TYPE_MOP_REQUEST: - case GF_OP_TYPE_MOP_REPLY: - op = gf_mop_list[frame->root->op]; - break; - case GF_OP_TYPE_CBK_REQUEST: - case GF_OP_TYPE_CBK_REPLY: - op = gf_cbk_list[frame->root->op]; - break; - } - - gf_log (this->name, GF_LOG_NORMAL, - "%s%s%s%s%s%s%s", - gf_fop_list[frame->root->op], caller, - resolve_vars, loc_vars, resolve2_vars, loc2_vars, other_vars); -} - - -static void -server_print_reply (call_frame_t *frame, int op_ret, int op_errno) -{ - server_conf_t *conf = NULL; - server_state_t *state = NULL; - xlator_t *this = NULL; - char caller[512]; - char fdstr[32]; - char *op = "UNKNOWN"; - - this = frame->this; - conf = this->private; - - if (!conf->trace) - return; - - state = CALL_STATE (frame); - - print_caller (caller, 256, frame); - - switch (frame->root->type) { - case GF_OP_TYPE_FOP_REQUEST: - case GF_OP_TYPE_FOP_REPLY: - op = gf_fop_list[frame->root->op]; - break; - case GF_OP_TYPE_MOP_REQUEST: - case GF_OP_TYPE_MOP_REPLY: - op = gf_mop_list[frame->root->op]; - break; - case GF_OP_TYPE_CBK_REQUEST: - case GF_OP_TYPE_CBK_REPLY: - op = gf_cbk_list[frame->root->op]; - break; - } - - fdstr[0] = '\0'; - if (state->fd) - snprintf (fdstr, 32, " fd=%p", state->fd); - - gf_log (this->name, GF_LOG_NORMAL, - "%s%s => (%d, %d)%s", - op, caller, op_ret, op_errno, fdstr); -} - - - -static void -protocol_server_reply (call_frame_t *frame, int type, int op, - gf_hdr_common_t *hdr, size_t hdrlen, - struct iovec *vector, int count, - struct iobref *iobref) -{ - server_state_t *state = NULL; - xlator_t *bound_xl = NULL; - transport_t *trans = NULL; - int ret = 0; - - xlator_t *this = NULL; - - bound_xl = BOUND_XL (frame); - state = CALL_STATE (frame); - trans = state->trans; - this = frame->this; - - hdr->callid = hton64 (frame->root->unique); - hdr->type = hton32 (type); - hdr->op = hton32 (op); - - server_print_reply (frame, ntoh32 (hdr->rsp.op_ret), - gf_error_to_errno (ntoh32 (hdr->rsp.op_errno))); - - ret = transport_submit (trans, (char *)hdr, hdrlen, vector, - count, iobref); - if (ret < 0) { - gf_log ("protocol/server", GF_LOG_ERROR, - "frame %"PRId64": failed to submit. op= %d, type= %d", - frame->root->unique, op, type); - } - - STACK_DESTROY (frame->root); - - if (state) - free_old_server_state (state); - -} - - -static int -gf_add_locker (struct _lock_table *table, const char *volume, - loc_t *loc, fd_t *fd, pid_t pid) -{ - int32_t ret = -1; - struct _locker *new = NULL; - uint8_t dir = 0; - - new = GF_CALLOC (1, sizeof (struct _locker), - gf_server_mt_locker); - if (new == NULL) { - gf_log ("server", GF_LOG_ERROR, - "failed to allocate memory for \'struct _locker\'"); - goto out; - } - INIT_LIST_HEAD (&new->lockers); - - new->volume = gf_strdup (volume); - - if (fd == NULL) { - loc_copy (&new->loc, loc); - dir = IA_ISDIR (new->loc.inode->ia_type); - } else { - new->fd = fd_ref (fd); - dir = IA_ISDIR (fd->inode->ia_type); - } - - new->pid = pid; - - LOCK (&table->lock); - { - if (dir) - list_add_tail (&new->lockers, &table->dir_lockers); - else - list_add_tail (&new->lockers, &table->file_lockers); - } - UNLOCK (&table->lock); -out: - return ret; -} - - -static int -gf_del_locker (struct _lock_table *table, const char *volume, - loc_t *loc, fd_t *fd, pid_t pid) -{ - struct _locker *locker = NULL; - struct _locker *tmp = NULL; - int32_t ret = 0; - uint8_t dir = 0; - struct list_head *head = NULL; - struct list_head del; - - INIT_LIST_HEAD (&del); - - if (fd) { - dir = IA_ISDIR (fd->inode->ia_type); - } else { - dir = IA_ISDIR (loc->inode->ia_type); - } - - LOCK (&table->lock); - { - if (dir) { - head = &table->dir_lockers; - } else { - head = &table->file_lockers; - } - - list_for_each_entry_safe (locker, tmp, head, lockers) { - if (locker->fd && fd && - (locker->fd == fd) && (locker->pid == pid) - && !strcmp (locker->volume, volume)) { - list_move_tail (&locker->lockers, &del); - } else if (locker->loc.inode && - loc && - (locker->loc.inode == loc->inode) && - (locker->pid == pid) - && !strcmp (locker->volume, volume)) { - list_move_tail (&locker->lockers, &del); - } - } - } - UNLOCK (&table->lock); - - tmp = NULL; - locker = NULL; - - list_for_each_entry_safe (locker, tmp, &del, lockers) { - list_del_init (&locker->lockers); - if (locker->fd) - fd_unref (locker->fd); - else - loc_wipe (&locker->loc); - - GF_FREE (locker->volume); - GF_FREE (locker); - } - - return ret; -} - - -/* - * server_lk_cbk - lk callback for server protocol - * @frame: call frame - * @cookie: - * @this: - * @op_ret: - * @op_errno: - * @lock: - * - * not for external reference - */ -static int -server_lk_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct flock *lock) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_lk_rsp_t *rsp = NULL; - size_t hdrlen = 0; - int32_t gf_errno = 0; - server_state_t *state = NULL; - - hdrlen = gf_hdr_len (rsp, 0); - hdr = gf_hdr_new (rsp, 0); - rsp = gf_param (hdr); - - hdr->rsp.op_ret = hton32 (op_ret); - gf_errno = gf_errno_to_error (op_errno); - hdr->rsp.op_errno = hton32 (gf_errno); - - if (op_ret == 0) { - gf_flock_from_flock (&rsp->flock, lock); - } else if (op_errno != ENOSYS) { - state = CALL_STATE(frame); - - gf_log (this->name, GF_LOG_TRACE, - "%"PRId64": LK %"PRId64" (%"PRId64") ==> %"PRId32" (%s)", - frame->root->unique, state->resolve.fd_no, - state->fd ? state->fd->inode->ino : 0, op_ret, - strerror (op_errno)); - } - - protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_LK, - hdr, hdrlen, NULL, 0, NULL); - - return 0; -} - - -static int -server_inodelk_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno) -{ - server_connection_t *conn = NULL; - gf_hdr_common_t *hdr = NULL; - gf_fop_inodelk_rsp_t *rsp = NULL; - server_state_t *state = NULL; - size_t hdrlen = 0; - int32_t gf_errno = 0; - - conn = SERVER_CONNECTION(frame); - - state = CALL_STATE(frame); - - hdrlen = gf_hdr_len (rsp, 0); - hdr = gf_hdr_new (rsp, 0); - rsp = gf_param (hdr); - - hdr->rsp.op_ret = hton32 (op_ret); - gf_errno = gf_errno_to_error (op_errno); - hdr->rsp.op_errno = hton32 (gf_errno); - - if (op_ret >= 0) { - if (state->flock.l_type == F_UNLCK) - gf_del_locker (conn->ltable, state->volume, - &state->loc, NULL, frame->root->pid); - else - gf_add_locker (conn->ltable, state->volume, - &state->loc, NULL, frame->root->pid); - } else if (op_errno != ENOSYS) { - gf_log (this->name, GF_LOG_TRACE, - "%"PRId64": INODELK %s (%"PRId64") ==> %"PRId32" (%s)", - frame->root->unique, state->loc.path, - state->loc.inode ? state->loc.inode->ino : 0, op_ret, - strerror (op_errno)); - } - - protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_INODELK, - hdr, hdrlen, NULL, 0, NULL); - - return 0; -} - - -static int -server_finodelk_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno) -{ - server_connection_t *conn = NULL; - gf_hdr_common_t *hdr = NULL; - gf_fop_finodelk_rsp_t *rsp = NULL; - server_state_t *state = NULL; - size_t hdrlen = 0; - int32_t gf_errno = 0; - - conn = SERVER_CONNECTION(frame); - - hdrlen = gf_hdr_len (rsp, 0); - hdr = gf_hdr_new (rsp, 0); - rsp = gf_param (hdr); - - hdr->rsp.op_ret = hton32 (op_ret); - gf_errno = gf_errno_to_error (op_errno); - hdr->rsp.op_errno = hton32 (gf_errno); - - state = CALL_STATE(frame); - - if (op_ret >= 0) { - if (state->flock.l_type == F_UNLCK) - gf_del_locker (conn->ltable, state->volume, - NULL, state->fd, - frame->root->pid); - else - gf_add_locker (conn->ltable, state->volume, - NULL, state->fd, - frame->root->pid); - } else if (op_errno != ENOSYS) { - gf_log (this->name, GF_LOG_TRACE, - "%"PRId64": FINODELK %"PRId64" (%"PRId64") ==> %"PRId32" (%s)", - frame->root->unique, state->resolve.fd_no, - state->fd ? state->fd->inode->ino : 0, op_ret, - strerror (op_errno)); - } - - protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_FINODELK, - hdr, hdrlen, NULL, 0, NULL); - - return 0; -} - - -/* - * server_entrylk_cbk - - * @frame: call frame - * @cookie: - * @this: - * @op_ret: - * @op_errno: - * @lock: - * - * not for external reference - */ -static int -server_entrylk_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno) -{ - server_connection_t *conn = NULL; - gf_hdr_common_t *hdr = NULL; - gf_fop_entrylk_rsp_t *rsp = NULL; - server_state_t *state = NULL; - size_t hdrlen = 0; - int32_t gf_errno = 0; - - conn = SERVER_CONNECTION(frame); - - state = CALL_STATE(frame); - - hdrlen = gf_hdr_len (rsp, 0); - hdr = gf_hdr_new (rsp, 0); - rsp = gf_param (hdr); - - hdr->rsp.op_ret = hton32 (op_ret); - gf_errno = gf_errno_to_error (op_errno); - hdr->rsp.op_errno = hton32 (gf_errno); - - if (op_ret >= 0) { - if (state->cmd == ENTRYLK_UNLOCK) - gf_del_locker (conn->ltable, state->volume, - &state->loc, NULL, frame->root->pid); - else - gf_add_locker (conn->ltable, state->volume, - &state->loc, NULL, frame->root->pid); - } else if (op_errno != ENOSYS) { - gf_log (this->name, GF_LOG_TRACE, - "%"PRId64": INODELK %s (%"PRId64") ==> %"PRId32" (%s)", - frame->root->unique, state->loc.path, - state->loc.inode ? state->loc.inode->ino : 0, op_ret, - strerror (op_errno)); - } - - protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_ENTRYLK, - hdr, hdrlen, NULL, 0, NULL); - - return 0; -} - - -static int -server_fentrylk_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno) -{ - server_connection_t *conn = NULL; - gf_hdr_common_t *hdr = NULL; - gf_fop_fentrylk_rsp_t *rsp = NULL; - server_state_t *state = NULL; - size_t hdrlen = 0; - int32_t gf_errno = 0; - - conn = SERVER_CONNECTION(frame); - - hdrlen = gf_hdr_len (rsp, 0); - hdr = gf_hdr_new (rsp, 0); - rsp = gf_param (hdr); - - hdr->rsp.op_ret = hton32 (op_ret); - gf_errno = gf_errno_to_error (op_errno); - hdr->rsp.op_errno = hton32 (gf_errno); - - state = CALL_STATE(frame); - if (op_ret >= 0) { - if (state->cmd == ENTRYLK_UNLOCK) - gf_del_locker (conn->ltable, state->volume, - NULL, state->fd, frame->root->pid); - else - gf_add_locker (conn->ltable, state->volume, - NULL, state->fd, frame->root->pid); - } else if (op_errno != ENOSYS) { - gf_log (this->name, GF_LOG_TRACE, - "%"PRId64": FENTRYLK %"PRId64" (%"PRId64") ==> %"PRId32" (%s)", - frame->root->unique, state->resolve.fd_no, - state->fd ? state->fd->inode->ino : 0, op_ret, - strerror (op_errno)); - } - - protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_FENTRYLK, - hdr, hdrlen, NULL, 0, NULL); - - return 0; -} - - -/* - * server_access_cbk - access callback for server protocol - * @frame: call frame - * @cookie: - * @this: - * @op_ret: - * @op_errno: - * - * not for external reference - */ -static int -server_access_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_access_rsp_t *rsp = NULL; - server_state_t *state = NULL; - size_t hdrlen = 0; - int32_t gf_errno = 0; - - state = CALL_STATE(frame); - - hdrlen = gf_hdr_len (rsp, 0); - hdr = gf_hdr_new (rsp, 0); - rsp = gf_param (hdr); - - hdr->rsp.op_ret = hton32 (op_ret); - gf_errno = gf_errno_to_error (op_errno); - hdr->rsp.op_errno = hton32 (gf_errno); - - protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_ACCESS, - hdr, hdrlen, NULL, 0, NULL); - - return 0; -} - -/* - * server_rmdir_cbk - rmdir callback for server protocol - * @frame: call frame - * @cookie: - * @this: - * @op_ret: - * @op_errno: - * - * not for external reference - */ -static int -server_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) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_rmdir_rsp_t *rsp = NULL; - server_state_t *state = NULL; - int32_t gf_errno = 0; - size_t hdrlen = 0; - inode_t *parent = NULL; - - state = CALL_STATE(frame); - - if (op_ret == 0) { - inode_unlink (state->loc.inode, state->loc.parent, - state->loc.name); - parent = inode_parent (state->loc.inode, 0, NULL); - if (parent) - inode_unref (parent); - else - inode_forget (state->loc.inode, 0); - } else { - gf_log (this->name, GF_LOG_TRACE, - "%"PRId64": RMDIR %s (%"PRId64") ==> %"PRId32" (%s)", - frame->root->unique, state->loc.path, - state->loc.inode ? state->loc.inode->ino : 0, - op_ret, strerror (op_errno)); - } - - hdrlen = gf_hdr_len (rsp, 0); - hdr = gf_hdr_new (rsp, 0); - rsp = gf_param (hdr); - - hdr->rsp.op_ret = hton32 (op_ret); - gf_errno = gf_errno_to_error (op_errno); - hdr->rsp.op_errno = hton32 (gf_errno); - - if (op_ret == 0) { - gf_stat_from_iatt (&rsp->preparent, preparent); - gf_stat_from_iatt (&rsp->postparent, postparent); - } - - protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_RMDIR, - hdr, hdrlen, NULL, 0, NULL); - - return 0; -} - -/* - * server_mkdir_cbk - mkdir callback for server protocol - * @frame: call frame - * @cookie: - * @this: - * @op_ret: - * @op_errno: - * @stbuf: - * - * not for external reference - */ -static int -server_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) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_mkdir_rsp_t *rsp = NULL; - server_state_t *state = NULL; - size_t hdrlen = 0; - int32_t gf_errno = 0; - inode_t *link_inode = NULL; - - state = CALL_STATE(frame); - - hdrlen = gf_hdr_len (rsp, 0); - hdr = gf_hdr_new (rsp, 0); - rsp = gf_param (hdr); - - hdr->rsp.op_ret = hton32 (op_ret); - gf_errno = gf_errno_to_error (op_errno); - hdr->rsp.op_errno = hton32 (gf_errno); - - if (op_ret >= 0) { - gf_stat_from_iatt (&rsp->stat, stbuf); - gf_stat_from_iatt (&rsp->preparent, preparent); - gf_stat_from_iatt (&rsp->postparent, postparent); - - link_inode = inode_link (inode, state->loc.parent, - state->loc.name, stbuf); - inode_lookup (link_inode); - inode_unref (link_inode); - } else { - gf_log (this->name, GF_LOG_TRACE, - "%"PRId64": MKDIR %s ==> %"PRId32" (%s)", - frame->root->unique, state->loc.path, - op_ret, strerror (op_errno)); - } - - protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_MKDIR, - hdr, hdrlen, NULL, 0, NULL); - - return 0; -} - -/* - * server_mknod_cbk - mknod callback for server protocol - * @frame: call frame - * @cookie: - * @this: - * @op_ret: - * @op_errno: - * @stbuf: - * - * not for external reference - */ -static int -server_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) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_mknod_rsp_t *rsp = NULL; - server_state_t *state = NULL; - int32_t gf_errno = 0; - size_t hdrlen = 0; - inode_t *link_inode = NULL; - - state = CALL_STATE(frame); - - hdrlen = gf_hdr_len (rsp, 0); - hdr = gf_hdr_new (rsp, 0); - rsp = gf_param (hdr); - - hdr->rsp.op_ret = hton32 (op_ret); - gf_errno = gf_errno_to_error (op_errno); - hdr->rsp.op_errno = hton32 (gf_errno); - - if (op_ret >= 0) { - gf_stat_from_iatt (&rsp->stat, stbuf); - gf_stat_from_iatt (&rsp->preparent, preparent); - gf_stat_from_iatt (&rsp->postparent, postparent); - - link_inode = inode_link (inode, state->loc.parent, - state->loc.name, stbuf); - inode_lookup (link_inode); - inode_unref (link_inode); - } else { - gf_log (this->name, GF_LOG_TRACE, - "%"PRId64": MKNOD %s ==> %"PRId32" (%s)", - frame->root->unique, state->loc.path, - op_ret, strerror (op_errno)); - } - - protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_MKNOD, - hdr, hdrlen, NULL, 0, NULL); - - return 0; -} - -/* - * server_fsyncdir_cbk - fsyncdir callback for server protocol - * @frame: call frame - * @cookie: - * @this: - * @op_ret: - * @op_errno: - * - * not for external reference - */ -static int -server_fsyncdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_fsyncdir_rsp_t *rsp = NULL; - size_t hdrlen = 0; - int32_t gf_errno = 0; - server_state_t *state = NULL; - - hdrlen = gf_hdr_len (rsp, 0); - hdr = gf_hdr_new (rsp, 0); - rsp = gf_param (hdr); - - if (op_ret < 0) { - state = CALL_STATE(frame); - - gf_log (this->name, GF_LOG_TRACE, - "%"PRId64": FSYNCDIR %"PRId64" (%"PRId64") ==> %"PRId32" (%s)", - frame->root->unique, state->resolve.fd_no, - state->fd ? state->fd->inode->ino : 0, op_ret, - strerror (op_errno)); - } - - hdr->rsp.op_ret = hton32 (op_ret); - gf_errno = gf_errno_to_error (op_errno); - hdr->rsp.op_errno = hton32 (gf_errno); - - protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_FSYNCDIR, - hdr, hdrlen, NULL, 0, NULL); - - return 0; -} - - - -/* - * server_readdir_cbk - getdents callback for server protocol - * @frame: call frame - * @cookie: - * @this: - * @op_ret: - * @op_errno: - * - * not for external reference - */ -static int -server_readdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, gf_dirent_t *entries) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_readdir_rsp_t *rsp = NULL; - size_t hdrlen = 0; - size_t buf_size = 0; - int32_t gf_errno = 0; - server_state_t *state = NULL; - - if (op_ret > 0) - buf_size = gf_dirent_serialize (entries, NULL, 0); - - hdrlen = gf_hdr_len (rsp, buf_size); - hdr = gf_hdr_new (rsp, buf_size); - rsp = gf_param (hdr); - - hdr->rsp.op_ret = hton32 (op_ret); - gf_errno = gf_errno_to_error (op_errno); - hdr->rsp.op_errno = hton32 (gf_errno); - - if (op_ret > 0) { - rsp->size = hton32 (buf_size); - gf_dirent_serialize (entries, rsp->buf, buf_size); - } else { - state = CALL_STATE(frame); - - gf_log (this->name, GF_LOG_TRACE, - "%"PRId64": READDIR %"PRId64" (%"PRId64") ==> %"PRId32" (%s)", - frame->root->unique, state->resolve.fd_no, - state->fd ? state->fd->inode->ino : 0, op_ret, - strerror (op_errno)); - } - - protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_READDIR, - hdr, hdrlen, NULL, 0, NULL); - - return 0; -} - - -/* - * server_releasedir_cbk - releasedir callback for server protocol - * @frame: call frame - * @cookie: - * @this: - * @op_ret: return value - * @op_errno: errno - * - * not for external reference - */ -static int -server_releasedir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno) -{ - gf_hdr_common_t *hdr = NULL; - gf_cbk_releasedir_rsp_t *rsp = NULL; - size_t hdrlen = 0; - int32_t gf_errno = 0; - - hdrlen = gf_hdr_len (rsp, 0); - hdr = gf_hdr_new (rsp, 0); - rsp = gf_param (hdr); - - hdr->rsp.op_ret = hton32 (op_ret); - gf_errno = gf_errno_to_error (op_errno); - hdr->rsp.op_errno = hton32 (gf_errno); - - protocol_server_reply (frame, GF_OP_TYPE_CBK_REPLY, GF_CBK_RELEASEDIR, - hdr, hdrlen, NULL, 0, NULL); - - return 0; -} - - -/* - * server_opendir_cbk - opendir callback for server protocol - * @frame: call frame - * @cookie: - * @this: - * @op_ret: return value - * @op_errno: errno - * @fd: file descriptor structure of opened directory - * - * not for external reference - */ -static int -server_opendir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, fd_t *fd) -{ - server_connection_t *conn = NULL; - gf_hdr_common_t *hdr = NULL; - gf_fop_opendir_rsp_t *rsp = NULL; - server_state_t *state = NULL; - size_t hdrlen = 0; - int32_t gf_errno = 0; - uint64_t fd_no = 0; - - conn = SERVER_CONNECTION (frame); - - state = CALL_STATE (frame); - - if (op_ret >= 0) { - fd_bind (fd); - - fd_no = gf_fd_unused_get (conn->fdtable, fd); - fd_ref (fd); // on behalf of the client - } else { - gf_log (this->name, GF_LOG_TRACE, - "%"PRId64": OPENDIR %s (%"PRId64") ==> %"PRId32" (%s)", - frame->root->unique, state->loc.path, - state->loc.inode ? state->loc.inode->ino : 0, - op_ret, strerror (op_errno)); - } - - hdrlen = gf_hdr_len (rsp, 0); - hdr = gf_hdr_new (rsp, 0); - rsp = gf_param (hdr); - - hdr->rsp.op_ret = hton32 (op_ret); - gf_errno = gf_errno_to_error (op_errno); - hdr->rsp.op_errno = hton32 (gf_errno); - rsp->fd = hton64 (fd_no); - - protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_OPENDIR, - hdr, hdrlen, NULL, 0, NULL); - - return 0; -} - -/* - * server_statfs_cbk - statfs callback for server protocol - * @frame: call frame - * @cookie: - * @this: - * @op_ret: return value - * @op_errno: errno - * @buf: - * - * not for external reference - */ -static int -server_statfs_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct statvfs *buf) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_statfs_rsp_t *rsp = NULL; - server_state_t *state = NULL; - size_t hdrlen = 0; - int32_t gf_errno = 0; - - state = CALL_STATE (frame); - - hdrlen = gf_hdr_len (rsp, 0); - hdr = gf_hdr_new (rsp, 0); - rsp = gf_param (hdr); - - hdr->rsp.op_ret = hton32 (op_ret); - gf_errno = gf_errno_to_error (op_errno); - hdr->rsp.op_errno = hton32 (gf_errno); - - if (op_ret >= 0) { - gf_statfs_from_statfs (&rsp->statfs, buf); - } - - protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_STATFS, - hdr, hdrlen, NULL, 0, NULL); - - return 0; -} - -/* - * server_removexattr_cbk - removexattr callback for server protocol - * @frame: call frame - * @cookie: - * @this: - * @op_ret: return value - * @op_errno: errno - * - * not for external reference - */ -static int -server_removexattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_removexattr_rsp_t *rsp = NULL; - server_state_t *state = NULL; - size_t hdrlen = 0; - int32_t gf_errno = 0; - - state = CALL_STATE (frame); - - hdrlen = gf_hdr_len (rsp, 0); - hdr = gf_hdr_new (rsp, 0); - rsp = gf_param (hdr); - - hdr->rsp.op_ret = hton32 (op_ret); - gf_errno = gf_errno_to_error (op_errno); - hdr->rsp.op_errno = hton32 (gf_errno); - - protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_REMOVEXATTR, - hdr, hdrlen, NULL, 0, NULL); - - return 0; -} - -/* - * server_getxattr_cbk - getxattr callback for server protocol - * @frame: call frame - * @cookie: - * @this: - * @op_ret: return value - * @op_errno: errno - * @value: - * - * not for external reference - */ -static int -server_getxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, dict_t *dict) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_getxattr_rsp_t *rsp = NULL; - server_state_t *state = NULL; - size_t hdrlen = 0; - int32_t len = 0; - int32_t gf_errno = 0; - int32_t ret = -1; - - state = CALL_STATE (frame); - - if (op_ret >= 0) { - len = dict_serialized_length (dict); - if (len < 0) { - gf_log (this->name, GF_LOG_ERROR, - "%s (%"PRId64"): failed to get serialized length of " - "reply dict", - state->loc.path, state->resolve.ino); - op_ret = -1; - op_errno = EINVAL; - len = 0; - } - } - - hdrlen = gf_hdr_len (rsp, len + 1); - hdr = gf_hdr_new (rsp, len + 1); - rsp = gf_param (hdr); - - if (op_ret >= 0) { - ret = dict_serialize (dict, rsp->dict); - if (len < 0) { - gf_log (this->name, GF_LOG_ERROR, - "%s (%"PRId64"): failed to serialize reply dict", - state->loc.path, state->resolve.ino); - op_ret = -1; - op_errno = -ret; - } - } - rsp->dict_len = hton32 (len); - - hdr->rsp.op_ret = hton32 (op_ret); - gf_errno = gf_errno_to_error (op_errno); - hdr->rsp.op_errno = hton32 (gf_errno); - - protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_GETXATTR, - hdr, hdrlen, NULL, 0, NULL); - - return 0; -} - - -static int -server_fgetxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, dict_t *dict) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_fgetxattr_rsp_t *rsp = NULL; - server_state_t *state = NULL; - size_t hdrlen = 0; - int32_t len = 0; - int32_t gf_errno = 0; - int32_t ret = -1; - - state = CALL_STATE (frame); - - if (op_ret >= 0) { - len = dict_serialized_length (dict); - if (len < 0) { - gf_log (this->name, GF_LOG_ERROR, - "%s (%"PRId64"): failed to get serialized length of " - "reply dict", - state->loc.path, state->resolve.ino); - op_ret = -1; - op_errno = EINVAL; - len = 0; - } - } - - hdrlen = gf_hdr_len (rsp, len + 1); - hdr = gf_hdr_new (rsp, len + 1); - rsp = gf_param (hdr); - - if (op_ret >= 0) { - ret = dict_serialize (dict, rsp->dict); - if (len < 0) { - gf_log (this->name, GF_LOG_ERROR, - "%s (%"PRId64"): failed to serialize reply dict", - state->loc.path, state->resolve.ino); - op_ret = -1; - op_errno = -ret; - } - } - rsp->dict_len = hton32 (len); - - hdr->rsp.op_ret = hton32 (op_ret); - gf_errno = gf_errno_to_error (op_errno); - hdr->rsp.op_errno = hton32 (gf_errno); - - protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_FGETXATTR, - hdr, hdrlen, NULL, 0, NULL); - - return 0; -} - - -/* - * server_setxattr_cbk - setxattr callback for server protocol - * @frame: call frame - * @cookie: - * @this: - * @op_ret: return value - * @op_errno: errno - * - * not for external reference - */ -static int -server_setxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_setxattr_rsp_t *rsp = NULL; - server_state_t *state = NULL; - size_t hdrlen = 0; - int32_t gf_errno = 0; - - state = CALL_STATE (frame); - - hdrlen = gf_hdr_len (rsp, 0); - hdr = gf_hdr_new (rsp, 0); - rsp = gf_param (hdr); - - hdr->rsp.op_ret = hton32 (op_ret); - gf_errno = gf_errno_to_error (op_errno); - hdr->rsp.op_errno = hton32 (gf_errno); - - protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_SETXATTR, - hdr, hdrlen, NULL, 0, NULL); - - return 0; -} - - -static int -server_fsetxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_fsetxattr_rsp_t *rsp = NULL; - server_state_t *state = NULL; - size_t hdrlen = 0; - int32_t gf_errno = 0; - - state = CALL_STATE(frame); - - hdrlen = gf_hdr_len (rsp, 0); - hdr = gf_hdr_new (rsp, 0); - rsp = gf_param (hdr); - - hdr->rsp.op_ret = hton32 (op_ret); - gf_errno = gf_errno_to_error (op_errno); - hdr->rsp.op_errno = hton32 (gf_errno); - - protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_FSETXATTR, - hdr, hdrlen, NULL, 0, NULL); - - return 0; -} - - -/* - * server_rename_cbk - rename callback for server protocol - * @frame: call frame - * @cookie: - * @this: - * @op_ret: return value - * @op_errno: errno - * - * not for external reference - */ -static int -server_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) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_rename_rsp_t *rsp = NULL; - server_state_t *state = NULL; - size_t hdrlen = 0; - int32_t gf_errno = 0; - - state = CALL_STATE(frame); - - hdrlen = gf_hdr_len (rsp, 0); - hdr = gf_hdr_new (rsp, 0); - rsp = gf_param (hdr); - - hdr->rsp.op_ret = hton32 (op_ret); - gf_errno = gf_errno_to_error (op_errno); - hdr->rsp.op_errno = hton32 (gf_errno); - - if (op_ret == 0) { - stbuf->ia_ino = state->loc.inode->ino; - stbuf->ia_type = state->loc.inode->ia_type; - - gf_log (state->bound_xl->name, GF_LOG_TRACE, - "%"PRId64": RENAME_CBK (%"PRId64") %"PRId64"/%s " - "==> %"PRId64"/%s", - frame->root->unique, state->loc.inode->ino, - state->loc.parent->ino, state->loc.name, - state->loc2.parent->ino, state->loc2.name); - - inode_rename (state->itable, - state->loc.parent, state->loc.name, - state->loc2.parent, state->loc2.name, - state->loc.inode, stbuf); - gf_stat_from_iatt (&rsp->stat, stbuf); - - gf_stat_from_iatt (&rsp->preoldparent, preoldparent); - gf_stat_from_iatt (&rsp->postoldparent, postoldparent); - - gf_stat_from_iatt (&rsp->prenewparent, prenewparent); - gf_stat_from_iatt (&rsp->postnewparent, postnewparent); - } - - protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_RENAME, - hdr, hdrlen, NULL, 0, NULL); - - return 0; -} - - -/* - * server_unlink_cbk - unlink callback for server protocol - * @frame: call frame - * @cookie: - * @this: - * @op_ret: return value - * @op_errno: errno - * - * not for external reference - */ -static int -server_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) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_unlink_rsp_t *rsp = NULL; - server_state_t *state = NULL; - size_t hdrlen = 0; - int32_t gf_errno = 0; - inode_t *parent = NULL; - - state = CALL_STATE(frame); - - if (op_ret == 0) { - gf_log (state->bound_xl->name, GF_LOG_TRACE, - "%"PRId64": UNLINK_CBK %"PRId64"/%s (%"PRId64")", - frame->root->unique, state->loc.parent->ino, - state->loc.name, state->loc.inode->ino); - - inode_unlink (state->loc.inode, state->loc.parent, - state->loc.name); - - parent = inode_parent (state->loc.inode, 0, NULL); - if (parent) - inode_unref (parent); - else - inode_forget (state->loc.inode, 0); - } else { - gf_log (this->name, GF_LOG_DEBUG, - "%"PRId64": UNLINK %s (%"PRId64") ==> %"PRId32" (%s)", - frame->root->unique, state->loc.path, - state->loc.inode ? state->loc.inode->ino : 0, - op_ret, strerror (op_errno)); - } - - hdrlen = gf_hdr_len (rsp, 0); - hdr = gf_hdr_new (rsp, 0); - rsp = gf_param (hdr); - - hdr->rsp.op_ret = hton32 (op_ret); - gf_errno = gf_errno_to_error (op_errno); - hdr->rsp.op_errno = hton32 (gf_errno); - - if (op_ret == 0) { - gf_stat_from_iatt (&rsp->preparent, preparent); - gf_stat_from_iatt (&rsp->postparent, postparent); - } - - protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_UNLINK, - hdr, hdrlen, NULL, 0, NULL); - - return 0; -} - -/* - * server_symlink_cbk - symlink callback for server protocol - * @frame: call frame - * @cookie: - * @this: - * @op_ret: return value - * @op_errno: errno - * - * not for external reference - */ -static int -server_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) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_symlink_rsp_t *rsp = NULL; - server_state_t *state = NULL; - size_t hdrlen = 0; - int32_t gf_errno = 0; - inode_t *link_inode = NULL; - - state = CALL_STATE(frame); - - hdrlen = gf_hdr_len (rsp, 0); - hdr = gf_hdr_new (rsp, 0); - rsp = gf_param (hdr); - - hdr->rsp.op_ret = hton32 (op_ret); - gf_errno = gf_errno_to_error (op_errno); - hdr->rsp.op_errno = hton32 (gf_errno_to_error (op_errno)); - - if (op_ret >= 0) { - gf_stat_from_iatt (&rsp->stat, stbuf); - gf_stat_from_iatt (&rsp->preparent, preparent); - gf_stat_from_iatt (&rsp->postparent, postparent); - - link_inode = inode_link (inode, state->loc.parent, - state->loc.name, stbuf); - inode_lookup (link_inode); - inode_unref (link_inode); - } else { - gf_log (this->name, GF_LOG_DEBUG, - "%"PRId64": SYMLINK %s (%"PRId64") ==> %"PRId32" (%s)", - frame->root->unique, state->loc.path, - state->loc.inode ? state->loc.inode->ino : 0, - op_ret, strerror (op_errno)); - } - - protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_SYMLINK, - hdr, hdrlen, NULL, 0, NULL); - - return 0; -} - - -/* - * server_link_cbk - link callback for server protocol - * @frame: call frame - * @this: - * @op_ret: - * @op_errno: - * @stbuf: - * - * not for external reference - */ -static int -server_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) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_link_rsp_t *rsp = NULL; - server_state_t *state = NULL; - int32_t gf_errno = 0; - size_t hdrlen = 0; - inode_t *link_inode = NULL; - - state = CALL_STATE(frame); - - hdrlen = gf_hdr_len (rsp, 0); - hdr = gf_hdr_new (rsp, 0); - rsp = gf_param (hdr); - - hdr->rsp.op_ret = hton32 (op_ret); - gf_errno = gf_errno_to_error (op_errno); - hdr->rsp.op_errno = hton32 (gf_errno); - - if (op_ret == 0) { - stbuf->ia_ino = state->loc.inode->ino; - - gf_stat_from_iatt (&rsp->stat, stbuf); - gf_stat_from_iatt (&rsp->preparent, preparent); - gf_stat_from_iatt (&rsp->postparent, postparent); - - gf_log (state->bound_xl->name, GF_LOG_TRACE, - "%"PRId64": LINK (%"PRId64") %"PRId64"/%s ==> %"PRId64"/%s", - frame->root->unique, inode->ino, - state->loc2.parent->ino, - state->loc2.name, state->loc.parent->ino, - state->loc.name); - - link_inode = inode_link (inode, state->loc2.parent, - state->loc2.name, stbuf); - inode_unref (link_inode); - } else { - gf_log (state->bound_xl->name, GF_LOG_DEBUG, - "%"PRId64": LINK (%"PRId64") %"PRId64"/%s ==> %"PRId64"/%s " - " ==> %"PRId32" (%s)", - frame->root->unique, state->resolve2.ino, - state->resolve2.par, - state->resolve2.bname, state->resolve.par, - state->resolve.bname, - op_ret, strerror (op_errno)); - } - - protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_LINK, - hdr, hdrlen, NULL, 0, NULL); - - return 0; -} - - -/* - * server_truncate_cbk - truncate callback for server protocol - * @frame: call frame - * @cookie: - * @this: - * @op_ret: - * @op_errno: - * @stbuf: - * - * not for external reference - */ -static int -server_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) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_truncate_rsp_t *rsp = NULL; - server_state_t *state = NULL; - size_t hdrlen = 0; - int32_t gf_errno = 0; - - state = CALL_STATE (frame); - - hdrlen = gf_hdr_len (rsp, 0); - hdr = gf_hdr_new (rsp, 0); - rsp = gf_param (hdr); - - hdr->rsp.op_ret = hton32 (op_ret); - gf_errno = gf_errno_to_error (op_errno); - hdr->rsp.op_errno = hton32 (gf_errno); - - if (op_ret == 0) { - gf_stat_from_iatt (&rsp->prestat, prebuf); - gf_stat_from_iatt (&rsp->poststat, postbuf); - } else { - gf_log (this->name, GF_LOG_DEBUG, - "%"PRId64": TRUNCATE %s (%"PRId64") ==> %"PRId32" (%s)", - frame->root->unique, state->loc.path, - state->loc.inode ? state->loc.inode->ino : 0, - op_ret, strerror (op_errno)); - } - - protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_TRUNCATE, - hdr, hdrlen, NULL, 0, NULL); - - return 0; -} - -/* - * server_fstat_cbk - fstat callback for server protocol - * @frame: call frame - * @cookie: - * @this: - * @op_ret: - * @op_errno: - * @stbuf: - * - * not for external reference - */ -static int -server_fstat_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct iatt *stbuf) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_fstat_rsp_t *rsp = NULL; - size_t hdrlen = 0; - int32_t gf_errno = 0; - server_state_t *state = NULL; - - hdrlen = gf_hdr_len (rsp, 0); - hdr = gf_hdr_new (rsp, 0); - rsp = gf_param (hdr); - - hdr->rsp.op_ret = hton32 (op_ret); - gf_errno = gf_errno_to_error (op_errno); - hdr->rsp.op_errno = hton32 (gf_errno); - - if (op_ret == 0) { - gf_stat_from_iatt (&rsp->stat, stbuf); - } else { - state = CALL_STATE(frame); - - gf_log (this->name, GF_LOG_DEBUG, - "%"PRId64": FSTAT %"PRId64" (%"PRId64") ==> %"PRId32" (%s)", - frame->root->unique, state->resolve.fd_no, - state->fd ? state->fd->inode->ino : 0, op_ret, - strerror (op_errno)); - } - - protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_FSTAT, - hdr, hdrlen, NULL, 0, NULL); - - return 0; -} - -/* - * server_ftruncate_cbk - ftruncate callback for server protocol - * @frame: call frame - * @cookie: - * @this: - * @op_ret: - * @op_errno: - * @stbuf: - * - * not for external reference - */ -static int -server_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) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_ftruncate_rsp_t *rsp = NULL; - size_t hdrlen = 0; - int32_t gf_errno = 0; - server_state_t *state = NULL; - - hdrlen = gf_hdr_len (rsp, 0); - hdr = gf_hdr_new (rsp, 0); - rsp = gf_param (hdr); - - hdr->rsp.op_ret = hton32 (op_ret); - gf_errno = gf_errno_to_error (op_errno); - hdr->rsp.op_errno = hton32 (gf_errno); - - if (op_ret == 0) { - gf_stat_from_iatt (&rsp->prestat, prebuf); - gf_stat_from_iatt (&rsp->poststat, postbuf); - } else { - state = CALL_STATE (frame); - - gf_log (this->name, GF_LOG_DEBUG, - "%"PRId64": FTRUNCATE %"PRId64" (%"PRId64") ==> %"PRId32" (%s)", - frame->root->unique, state->resolve.fd_no, - state->fd ? state->fd->inode->ino : 0, op_ret, - strerror (op_errno)); - } - - protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_FTRUNCATE, - hdr, hdrlen, NULL, 0, NULL); - - return 0; -} - - -/* - * server_flush_cbk - flush callback for server protocol - * @frame: call frame - * @cookie: - * @this: - * @op_ret: - * @op_errno: - * - * not for external reference - */ -static int -server_flush_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_flush_rsp_t *rsp = NULL; - size_t hdrlen = 0; - int32_t gf_errno = 0; - server_state_t *state = NULL; - - if (op_ret < 0) { - state = CALL_STATE(frame); - - gf_log (this->name, GF_LOG_DEBUG, - "%"PRId64": FLUSH %"PRId64" (%"PRId64") ==> %"PRId32" (%s)", - frame->root->unique, state->resolve.fd_no, - state->fd ? state->fd->inode->ino : 0, op_ret, - strerror (op_errno)); - } - - hdrlen = gf_hdr_len (rsp, 0); - hdr = gf_hdr_new (rsp, 0); - - hdr->rsp.op_ret = hton32 (op_ret); - gf_errno = gf_errno_to_error (op_errno); - hdr->rsp.op_errno = hton32 (gf_errno); - - protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_FLUSH, - hdr, hdrlen, NULL, 0, NULL); - - return 0; -} - -/* - * server_fsync_cbk - fsync callback for server protocol - * @frame: call frame - * @cookie: - * @this: - * @op_ret: - * @op_errno: - * - * not for external reference - */ -static int -server_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) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_fsync_rsp_t *rsp = NULL; - size_t hdrlen = 0; - int32_t gf_errno = 0; - server_state_t *state = NULL; - - if (op_ret < 0) { - state = CALL_STATE(frame); - - gf_log (this->name, GF_LOG_DEBUG, - "%"PRId64": FSYNC %"PRId64" (%"PRId64") ==> %"PRId32" (%s)", - frame->root->unique, state->resolve.fd_no, - state->fd ? state->fd->inode->ino : 0, op_ret, - strerror (op_errno)); - } - - hdrlen = gf_hdr_len (rsp, 0); - hdr = gf_hdr_new (rsp, 0); - rsp = gf_param (hdr); - - hdr->rsp.op_ret = hton32 (op_ret); - gf_errno = gf_errno_to_error (op_errno); - hdr->rsp.op_errno = hton32 (gf_errno); - - if (op_ret >= 0) { - gf_stat_from_iatt (&(rsp->prestat), prebuf); - gf_stat_from_iatt (&(rsp->poststat), postbuf); - } - - protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_FSYNC, - hdr, hdrlen, NULL, 0, NULL); - - return 0; -} - -/* - * server_release_cbk - rleease callback for server protocol - * @frame: call frame - * @cookie: - * @this: - * @op_ret: - * @op_errno: - * - * not for external reference - */ -static int -server_release_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno) -{ - gf_hdr_common_t *hdr = NULL; - gf_cbk_release_rsp_t *rsp = NULL; - size_t hdrlen = 0; - int32_t gf_errno = 0; - - hdrlen = gf_hdr_len (rsp, 0); - hdr = gf_hdr_new (rsp, 0); - - hdr->rsp.op_ret = hton32 (op_ret); - gf_errno = gf_errno_to_error (op_errno); - hdr->rsp.op_errno = hton32 (gf_errno); - - protocol_server_reply (frame, GF_OP_TYPE_CBK_REPLY, GF_CBK_RELEASE, - hdr, hdrlen, NULL, 0, NULL); - - return 0; -} - - -/* - * server_writev_cbk - writev callback for server protocol - * @frame: call frame - * @cookie: - * @this: - * @op_ret: - * @op_errno: - * - * not for external reference - */ - -static int -server_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) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_write_rsp_t *rsp = NULL; - size_t hdrlen = 0; - int32_t gf_errno = 0; - server_state_t *state = NULL; - - hdrlen = gf_hdr_len (rsp, 0); - hdr = gf_hdr_new (rsp, 0); - rsp = gf_param (hdr); - - hdr->rsp.op_ret = hton32 (op_ret); - gf_errno = gf_errno_to_error (op_errno); - hdr->rsp.op_errno = hton32 (gf_errno_to_error (op_errno)); - - if (op_ret >= 0) { - gf_stat_from_iatt (&rsp->prestat, prebuf); - gf_stat_from_iatt (&rsp->poststat, postbuf); - } else { - state = CALL_STATE(frame); - - gf_log (this->name, GF_LOG_DEBUG, - "%"PRId64": WRITEV %"PRId64" (%"PRId64") ==> %"PRId32" (%s)", - frame->root->unique, state->resolve.fd_no, - state->fd ? state->fd->inode->ino : 0, op_ret, - strerror (op_errno)); - } - - protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_WRITE, - hdr, hdrlen, NULL, 0, NULL); - - return 0; -} - - -/* - * server_readv_cbk - readv callback for server protocol - * @frame: call frame - * @cookie: - * @this: - * @op_ret: - * @op_errno: - * @vector: - * @count: - * - * not for external reference - */ -static int -server_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) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_read_rsp_t *rsp = NULL; - size_t hdrlen = 0; - int32_t gf_errno = 0; - server_state_t *state = NULL; - - hdrlen = gf_hdr_len (rsp, 0); - hdr = gf_hdr_new (rsp, 0); - rsp = gf_param (hdr); - - hdr->rsp.op_ret = hton32 (op_ret); - gf_errno = gf_errno_to_error (op_errno); - hdr->rsp.op_errno = hton32 (gf_errno); - - if (op_ret >= 0) { - gf_stat_from_iatt (&rsp->stat, stbuf); - } else { - state = CALL_STATE(frame); - - gf_log (this->name, GF_LOG_DEBUG, - "%"PRId64": READV %"PRId64" (%"PRId64") ==> %"PRId32" (%s)", - frame->root->unique, state->resolve.fd_no, - state->fd ? state->fd->inode->ino : 0, op_ret, - strerror (op_errno)); - } - - protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_READ, - hdr, hdrlen, vector, count, iobref); - - return 0; -} - - -/* - * server_open_cbk - open callback for server protocol - * @frame: call frame - * @cookie: - * @this: - * @op_ret: - * @op_errno: - * @fd: - * - * not for external reference - */ -static int -server_open_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, fd_t *fd) -{ - server_connection_t *conn = NULL; - gf_hdr_common_t *hdr = NULL; - gf_fop_open_rsp_t *rsp = NULL; - server_state_t *state = NULL; - size_t hdrlen = 0; - int32_t gf_errno = 0; - uint64_t fd_no = 0; - - conn = SERVER_CONNECTION (frame); - - state = CALL_STATE (frame); - - if (op_ret >= 0) { - fd_bind (fd); - - fd_no = gf_fd_unused_get (conn->fdtable, fd); - fd_ref (fd); - } else { - gf_log (this->name, GF_LOG_DEBUG, - "%"PRId64": OPEN %s (%"PRId64") ==> %"PRId32" (%s)", - frame->root->unique, state->loc.path, - state->loc.inode ? state->loc.inode->ino : 0, - op_ret, strerror (op_errno)); - } - - hdrlen = gf_hdr_len (rsp, 0); - hdr = gf_hdr_new (rsp, 0); - rsp = gf_param (hdr); - - hdr->rsp.op_ret = hton32 (op_ret); - gf_errno = gf_errno_to_error (op_errno); - hdr->rsp.op_errno = hton32 (gf_errno); - rsp->fd = hton64 (fd_no); - - protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_OPEN, - hdr, hdrlen, NULL, 0, NULL); - - return 0; -} - - -/* - * server_create_cbk - create callback for server - * @frame: call frame - * @cookie: - * @this: translator structure - * @op_ret: - * @op_errno: - * @fd: file descriptor - * @inode: inode structure - * @stbuf: struct iatt of created file - * - * not for external reference - */ -static int -server_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) -{ - server_connection_t *conn = NULL; - gf_hdr_common_t *hdr = NULL; - gf_fop_create_rsp_t *rsp = NULL; - server_state_t *state = NULL; - size_t hdrlen = 0; - int32_t gf_errno = 0; - uint64_t fd_no = 0; - inode_t *link_inode = NULL; - - conn = SERVER_CONNECTION (frame); - - state = CALL_STATE (frame); - - if (op_ret >= 0) { - gf_log (state->bound_xl->name, GF_LOG_TRACE, - "%"PRId64": CREATE %"PRId64"/%s (%"PRId64")", - frame->root->unique, state->loc.parent->ino, - state->loc.name, stbuf->ia_ino); - - link_inode = inode_link (inode, state->loc.parent, - state->loc.name, stbuf); - - if (link_inode != inode) { - - /* - VERY racy code (if used anywhere else) - -- don't do this without understanding - */ - - inode_unref (fd->inode); - fd->inode = inode_ref (link_inode); - } - - inode_lookup (link_inode); - inode_unref (link_inode); - - fd_bind (fd); - - fd_no = gf_fd_unused_get (conn->fdtable, fd); - fd_ref (fd); - - if ((fd_no < 0) || (fd == 0)) { - op_ret = fd_no; - op_errno = errno; - } - } else { - gf_log (this->name, GF_LOG_DEBUG, - "%"PRId64": CREATE %s (%"PRId64") ==> %"PRId32" (%s)", - frame->root->unique, state->loc.path, - state->loc.inode ? state->loc.inode->ino : 0, - op_ret, strerror (op_errno)); - } - - hdrlen = gf_hdr_len (rsp, 0); - hdr = gf_hdr_new (rsp, 0); - rsp = gf_param (hdr); - - hdr->rsp.op_ret = hton32 (op_ret); - gf_errno = gf_errno_to_error (op_errno); - hdr->rsp.op_errno = hton32 (gf_errno); - rsp->fd = hton64 (fd_no); - - if (op_ret >= 0) { - gf_stat_from_iatt (&rsp->stat, stbuf); - gf_stat_from_iatt (&rsp->preparent, preparent); - gf_stat_from_iatt (&rsp->postparent, postparent); - } - - protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_CREATE, - hdr, hdrlen, NULL, 0, NULL); - - return 0; -} - -/* - * server_readlink_cbk - readlink callback for server protocol - * @frame: call frame - * @cookie: - * @this: - * @op_ret: - * @op_errno: - * @buf: - * - * not for external reference - */ -static int -server_readlink_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, const char *buf, - struct iatt *sbuf) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_readlink_rsp_t *rsp = NULL; - server_state_t *state = NULL; - size_t hdrlen = 0; - size_t linklen = 0; - int32_t gf_errno = 0; - - state = CALL_STATE(frame); - - if (op_ret >= 0) { - linklen = strlen (buf) + 1; - } else { - gf_log (this->name, GF_LOG_DEBUG, - "%"PRId64": READLINK %s (%"PRId64") ==> %"PRId32" (%s)", - frame->root->unique, state->loc.path, - state->loc.inode ? state->loc.inode->ino : 0, - op_ret, strerror (op_errno)); - } - - hdrlen = gf_hdr_len (rsp, linklen); - hdr = gf_hdr_new (rsp, linklen); - rsp = gf_param (hdr); - - hdr->rsp.op_ret = hton32 (op_ret); - gf_errno = gf_errno_to_error (op_errno); - hdr->rsp.op_errno = hton32 (gf_errno_to_error (op_errno)); - - if (op_ret >= 0) { - gf_stat_from_iatt (&(rsp->buf), sbuf); - strcpy (rsp->path, buf); - } - - protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_READLINK, - hdr, hdrlen, NULL, 0, NULL); - - return 0; -} - -/* - * server_stat_cbk - stat callback for server protocol - * @frame: call frame - * @cookie: - * @this: - * @op_ret: - * @op_errno: - * @stbuf: - * - * not for external reference - */ -static int -server_stat_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct iatt *stbuf) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_stat_rsp_t *rsp = NULL; - server_state_t *state = NULL; - size_t hdrlen = 0; - int32_t gf_errno = 0; - - state = CALL_STATE (frame); - - hdrlen = gf_hdr_len (rsp, 0); - hdr = gf_hdr_new (rsp, 0); - rsp = gf_param (hdr); - - hdr->rsp.op_ret = hton32 (op_ret); - gf_errno = gf_errno_to_error (op_errno); - hdr->rsp.op_errno = hton32 (gf_errno_to_error (op_errno)); - - if (op_ret == 0) { - gf_stat_from_iatt (&rsp->stat, stbuf); - } else { - gf_log (this->name, GF_LOG_DEBUG, - "%"PRId64": STAT %s (%"PRId64") ==> %"PRId32" (%s)", - frame->root->unique, state->loc.path, - state->loc.inode ? state->loc.inode->ino : 0, - op_ret, strerror (op_errno)); - } - - protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_STAT, - hdr, hdrlen, NULL, 0, NULL); - - return 0; -} - -/* - * server_setattr_cbk - setattr callback for server protocol - * @frame: call frame - * @cookie: - * @this: - * @op_ret: - * @op_errno: - * @stbuf: - * - * not for external reference - */ - -static int -server_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) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_setattr_rsp_t *rsp = NULL; - server_state_t *state = NULL; - size_t hdrlen = 0; - int32_t gf_errno = 0; - - state = CALL_STATE (frame); - - hdrlen = gf_hdr_len (rsp, 0); - hdr = gf_hdr_new (rsp, 0); - rsp = gf_param (hdr); - - hdr->rsp.op_ret = hton32 (op_ret); - gf_errno = gf_errno_to_error (op_errno); - hdr->rsp.op_errno = hton32 (gf_errno_to_error (op_errno)); - - if (op_ret == 0) { - gf_stat_from_iatt (&rsp->statpre, statpre); - gf_stat_from_iatt (&rsp->statpost, statpost); - } else { - gf_log (this->name, GF_LOG_DEBUG, - "%"PRId64": SETATTR %s (%"PRId64") ==> %"PRId32" (%s)", - frame->root->unique, state->loc.path, - state->loc.inode ? state->loc.inode->ino : 0, - op_ret, strerror (op_errno)); - } - - protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_SETATTR, - hdr, hdrlen, NULL, 0, NULL); - - return 0; -} - -/* - * server_setattr_cbk - setattr callback for server protocol - * @frame: call frame - * @cookie: - * @this: - * @op_ret: - * @op_errno: - * @stbuf: - * - * not for external reference - */ -static int -server_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) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_fsetattr_rsp_t *rsp = NULL; - server_state_t *state = NULL; - size_t hdrlen = 0; - int32_t gf_errno = 0; - - state = CALL_STATE (frame); - - hdrlen = gf_hdr_len (rsp, 0); - hdr = gf_hdr_new (rsp, 0); - rsp = gf_param (hdr); - - hdr->rsp.op_ret = hton32 (op_ret); - gf_errno = gf_errno_to_error (op_errno); - hdr->rsp.op_errno = hton32 (gf_errno_to_error (op_errno)); - - if (op_ret == 0) { - gf_stat_from_iatt (&rsp->statpre, statpre); - gf_stat_from_iatt (&rsp->statpost, statpost); - } else { - gf_log (this->name, GF_LOG_DEBUG, - "%"PRId64": FSETATTR %"PRId64" (%"PRId64") ==> " - "%"PRId32" (%s)", - frame->root->unique, state->resolve.fd_no, - state->fd ? state->fd->inode->ino : 0, - op_ret, strerror (op_errno)); - } - - protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_FSETATTR, - hdr, hdrlen, NULL, 0, NULL); - - return 0; -} - - -/* - * server_lookup_cbk - lookup callback for server protocol - * @frame: call frame - * @cookie: - * @this: - * @op_ret: - * @op_errno: - * @inode: - * @stbuf: - * - * not for external reference - */ -static int -server_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 *dict, - struct iatt *postparent) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_lookup_rsp_t *rsp = NULL; - server_state_t *state = NULL; - inode_t *root_inode = NULL; - int32_t dict_len = 0; - size_t hdrlen = 0; - int32_t gf_errno = 0; - int32_t ret = -1; - inode_t *link_inode = NULL; - loc_t fresh_loc = {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 = inode_new (state->itable); - - STACK_WIND (frame, server_lookup_cbk, - BOUND_XL (frame), BOUND_XL (frame)->fops->lookup, - &fresh_loc, state->dict); - - loc_wipe (&fresh_loc); - return 0; - } - - if (dict) { - dict_len = dict_serialized_length (dict); - if (dict_len < 0) { - gf_log (this->name, GF_LOG_ERROR, - "%s (%"PRId64"): failed to get serialized " - "length of reply dict", - state->loc.path, state->loc.inode->ino); - op_ret = -1; - op_errno = EINVAL; - dict_len = 0; - } - } - - hdrlen = gf_hdr_len (rsp, dict_len); - hdr = gf_hdr_new (rsp, dict_len); - rsp = gf_param (hdr); - - if ((op_ret >= 0) && dict) { - ret = dict_serialize (dict, rsp->dict); - if (ret < 0) { - gf_log (this->name, GF_LOG_ERROR, - "%s (%"PRId64"): failed to serialize reply dict", - state->loc.path, state->loc.inode->ino); - op_ret = -1; - op_errno = -ret; - dict_len = 0; - } - } - rsp->dict_len = hton32 (dict_len); - - hdr->rsp.op_ret = hton32 (op_ret); - gf_errno = gf_errno_to_error (op_errno); - hdr->rsp.op_errno = hton32 (gf_errno); - - if (postparent) - gf_stat_from_iatt (&rsp->postparent, postparent); - - if (op_ret == 0) { - root_inode = BOUND_XL(frame)->itable->root; - if (inode == root_inode) { - /* we just looked up root ("/") */ - stbuf->ia_ino = 1; - if (inode->ia_type == 0) - inode->ia_type = stbuf->ia_type; - } - - gf_stat_from_iatt (&rsp->stat, stbuf); - - if (inode->ino != 1) { - link_inode = inode_link (inode, state->loc.parent, - state->loc.name, stbuf); - inode_lookup (link_inode); - inode_unref (link_inode); - } - } else { - if (state->is_revalidate && op_errno == ENOENT) { - if (state->loc.inode->ino != 1) { - inode_unlink (state->loc.inode, - state->loc.parent, - state->loc.name); - } - } - - gf_log (this->name, - (op_errno == ENOENT ? GF_LOG_TRACE : GF_LOG_DEBUG), - "%"PRId64": LOOKUP %s (%"PRId64") ==> %"PRId32" (%s)", - frame->root->unique, state->loc.path, - state->loc.inode ? state->loc.inode->ino : 0, - op_ret, strerror (op_errno)); - } - - protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_LOOKUP, - hdr, hdrlen, NULL, 0, NULL); - - return 0; -} - - -static int -server_xattrop_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, dict_t *dict) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_xattrop_rsp_t *rsp = NULL; - server_state_t *state = NULL; - size_t hdrlen = 0; - int32_t len = 0; - int32_t gf_errno = 0; - int32_t ret = -1; - - state = CALL_STATE (frame); - - if (op_ret < 0) { - gf_log (this->name, GF_LOG_DEBUG, - "%"PRId64": XATTROP %s (%"PRId64") ==> %"PRId32" (%s)", - frame->root->unique, state->loc.path, - state->loc.inode ? state->loc.inode->ino : 0, - op_ret, strerror (op_errno)); - } - - if ((op_ret >= 0) && dict) { - len = dict_serialized_length (dict); - if (len < 0) { - gf_log (this->name, GF_LOG_ERROR, - "%s (%"PRId64"): failed to get serialized length" - " for reply dict", - state->loc.path, state->loc.inode->ino); - op_ret = -1; - op_errno = EINVAL; - len = 0; - } - } - - hdrlen = gf_hdr_len (rsp, len + 1); - hdr = gf_hdr_new (rsp, len + 1); - rsp = gf_param (hdr); - - if ((op_ret >= 0) && dict) { - ret = dict_serialize (dict, rsp->dict); - if (ret < 0) { - gf_log (this->name, GF_LOG_ERROR, - "%s (%"PRId64"): failed to serialize reply dict", - state->loc.path, state->loc.inode->ino); - op_ret = -1; - op_errno = -ret; - len = 0; - } - } - rsp->dict_len = hton32 (len); - - hdr->rsp.op_ret = hton32 (op_ret); - gf_errno = gf_errno_to_error (op_errno); - hdr->rsp.op_errno = hton32 (gf_errno); - - protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_XATTROP, - hdr, hdrlen, NULL, 0, NULL); - - return 0; -} - - -static int -server_fxattrop_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, dict_t *dict) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_xattrop_rsp_t *rsp = NULL; - size_t hdrlen = 0; - int32_t len = 0; - int32_t gf_errno = 0; - int32_t ret = -1; - server_state_t *state = NULL; - - state = CALL_STATE(frame); - - if (op_ret < 0) { - gf_log (this->name, GF_LOG_DEBUG, - "%"PRId64": FXATTROP %"PRId64" (%"PRId64") ==> %"PRId32" (%s)", - frame->root->unique, state->resolve.fd_no, - state->fd ? state->fd->inode->ino : 0, op_ret, - strerror (op_errno)); - } - - if ((op_ret >= 0) && dict) { - len = dict_serialized_length (dict); - if (len < 0) { - gf_log (this->name, GF_LOG_ERROR, - "fd - %"PRId64" (%"PRId64"): failed to get " - "serialized length for reply dict", - state->resolve.fd_no, state->fd->inode->ino); - op_ret = -1; - op_errno = EINVAL; - len = 0; - } - } - - hdrlen = gf_hdr_len (rsp, len + 1); - hdr = gf_hdr_new (rsp, len + 1); - rsp = gf_param (hdr); - - if ((op_ret >= 0) && dict) { - ret = dict_serialize (dict, rsp->dict); - if (ret < 0) { - gf_log (this->name, GF_LOG_ERROR, - "fd - %"PRId64" (%"PRId64"): failed to " - "serialize reply dict", - state->resolve.fd_no, state->fd->inode->ino); - op_ret = -1; - op_errno = -ret; - len = 0; - } - } - rsp->dict_len = hton32 (len); - - hdr->rsp.op_ret = hton32 (op_ret); - gf_errno = gf_errno_to_error (op_errno); - hdr->rsp.op_errno = hton32 (gf_errno); - - - protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_FXATTROP, - hdr, hdrlen, NULL, 0, NULL); - - return 0; -} - - -static int -server_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 = inode_new (state->itable); - else - state->is_revalidate = 1; - - STACK_WIND (frame, server_lookup_cbk, - bound_xl, bound_xl->fops->lookup, - &state->loc, state->dict); - - return 0; -err: - server_lookup_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno, NULL, NULL, NULL, NULL); - - return 0; -} - - -static int -server_lookup (call_frame_t *frame, xlator_t *bound_xl, - gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_fop_lookup_req_t *req = NULL; - server_state_t *state = NULL; - int32_t ret = -1; - size_t pathlen = 0; - size_t baselen = 0; - size_t dictlen = 0; - dict_t *xattr_req = NULL; - char *req_dictbuf = NULL; - - req = gf_param (hdr); - - state = CALL_STATE (frame); - - pathlen = STRLEN_0 (req->path); - dictlen = ntoh32 (req->dictlen); - - /* NOTE: lookup() uses req->ino only to identify if a lookup() - * is requested for 'root' or not - */ - state->resolve.ino = ntoh64 (req->ino); - if (state->resolve.ino != 1) - state->resolve.ino = 0; - - state->resolve.type = RESOLVE_DONTCARE; - state->resolve.par = ntoh64 (req->par); - state->resolve.gen = ntoh64 (req->gen); - state->resolve.path = gf_strdup (req->path); - - if (IS_NOT_ROOT (pathlen)) { - state->resolve.bname = gf_strdup (req->bname + pathlen); - baselen = STRLEN_0 (state->resolve.bname); - } - - if (dictlen) { - /* Unserialize the dictionary */ - req_dictbuf = memdup (req->dict + pathlen + baselen, dictlen); - - xattr_req = dict_new (); - - ret = dict_unserialize (req_dictbuf, dictlen, &xattr_req); - if (ret < 0) { - gf_log (bound_xl->name, GF_LOG_ERROR, - "%"PRId64": %s (%"PRId64"): failed to " - "unserialize req-buffer to dictionary", - frame->root->unique, state->resolve.path, - state->resolve.ino); - GF_FREE (req_dictbuf); - goto err; - } - - xattr_req->extra_free = req_dictbuf; - state->dict = xattr_req; - } - - gf_resolve_and_resume (frame, server_lookup_resume); - - return 0; -err: - if (xattr_req) - dict_unref (xattr_req); - - server_lookup_cbk (frame, NULL, frame->this, -1, EINVAL, NULL, NULL, - NULL, NULL); - return 0; -} - - -/* - * server_forget - forget function for server protocol - * - * not for external reference - */ -static int -server_forget (call_frame_t *frame, xlator_t *bound_xl, - gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_log ("forget", GF_LOG_CRITICAL, "function not implemented"); - return 0; -} - - -static int -server_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, server_stat_cbk, - bound_xl, bound_xl->fops->stat, &state->loc); - return 0; -err: - server_stat_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno, NULL); - return 0; -} - - -static int -server_stat (call_frame_t *frame, xlator_t *bound_xl, - gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_fop_stat_req_t *req = NULL; - server_state_t *state = NULL; - - req = gf_param (hdr); - state = CALL_STATE (frame); - { - state->resolve.type = RESOLVE_MUST; - state->resolve.ino = ntoh64 (req->ino); - state->resolve.gen = ntoh64 (req->gen); - state->resolve.path = gf_strdup (req->path); - } - - gf_resolve_and_resume (frame, server_stat_resume); - - return 0; -} - - -static int -server_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, server_setattr_cbk, - bound_xl, bound_xl->fops->setattr, - &state->loc, &state->stbuf, state->valid); - return 0; -err: - server_setattr_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno, NULL, NULL); - - return 0; -} - - -static int -server_setattr (call_frame_t *frame, xlator_t *bound_xl, - gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_fop_setattr_req_t *req = NULL; - server_state_t *state = NULL; - - req = gf_param (hdr); - state = CALL_STATE (frame); - - state->resolve.type = RESOLVE_MUST; - state->resolve.ino = ntoh64 (req->ino); - state->resolve.gen = ntoh64 (req->gen); - state->resolve.path = gf_strdup (req->path); - - gf_stat_to_iatt (&req->stbuf, &state->stbuf); - state->valid = ntoh32 (req->valid); - - gf_resolve_and_resume (frame, server_setattr_resume); - - return 0; -} - - -static int -server_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, server_fsetattr_cbk, - bound_xl, bound_xl->fops->fsetattr, - state->fd, &state->stbuf, state->valid); - return 0; -err: - server_fsetattr_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno, NULL, NULL); - - return 0; -} - - -static int -server_fsetattr (call_frame_t *frame, xlator_t *bound_xl, - gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_fop_fsetattr_req_t *req = NULL; - server_state_t *state = NULL; - - - req = gf_param (hdr); - state = CALL_STATE (frame); - - state->resolve.type = RESOLVE_MUST; - state->resolve.fd_no = ntoh64 (req->fd); - - gf_stat_to_iatt (&req->stbuf, &state->stbuf); - state->valid = ntoh32 (req->valid); - - gf_resolve_and_resume (frame, server_fsetattr_resume); - - return 0; -} - - -static int -server_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, server_readlink_cbk, - bound_xl, bound_xl->fops->readlink, - &state->loc, state->size); - return 0; -err: - server_readlink_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno, NULL, NULL); - return 0; -} - - -static int -server_readlink (call_frame_t *frame, xlator_t *bound_xl, - gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_fop_readlink_req_t *req = NULL; - server_state_t *state = NULL; - - req = gf_param (hdr); - state = CALL_STATE (frame); - - state->resolve.type = RESOLVE_MUST; - state->resolve.ino = ntoh64 (req->ino); - state->resolve.gen = ntoh64 (req->gen); - state->resolve.path = gf_strdup (req->path); - - state->size = ntoh32 (req->size); - - gf_resolve_and_resume (frame, server_readlink_resume); - - return 0; -} - - -static int -server_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); - state->fd->flags = state->flags; - - STACK_WIND (frame, server_create_cbk, - bound_xl, bound_xl->fops->create, - &(state->loc), state->flags, state->mode, - state->fd, state->params); - - return 0; -err: - server_create_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno, NULL, NULL, NULL, - NULL, NULL); - return 0; -} - - -static int -server_create (call_frame_t *frame, xlator_t *bound_xl, - gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_fop_create_req_t *req = NULL; - server_state_t *state = NULL; - int pathlen = 0; - - req = gf_param (hdr); - state = CALL_STATE (frame); - - pathlen = STRLEN_0 (req->path); - - state->resolve.type = RESOLVE_NOT; - state->resolve.par = ntoh64 (req->par); - state->resolve.gen = ntoh64 (req->gen); - state->resolve.path = gf_strdup (req->path); - state->resolve.bname = gf_strdup (req->bname + pathlen); - state->mode = ntoh32 (req->mode); - state->flags = gf_flags_to_flags (ntoh32 (req->flags)); - - gf_resolve_and_resume (frame, server_create_resume); - - return 0; -} - - -static int -server_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, server_open_cbk, - bound_xl, bound_xl->fops->open, - &state->loc, state->flags, state->fd, 0); - - return 0; -err: - server_open_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno, NULL); - return 0; -} - - -static int -server_open (call_frame_t *frame, xlator_t *bound_xl, - gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_fop_open_req_t *req = NULL; - server_state_t *state = NULL; - - req = gf_param (hdr); - state = CALL_STATE (frame); - - state->resolve.type = RESOLVE_MUST; - state->resolve.ino = ntoh64 (req->ino); - state->resolve.gen = ntoh64 (req->gen); - state->resolve.path = gf_strdup (req->path); - - state->flags = gf_flags_to_flags (ntoh32 (req->flags)); - - gf_resolve_and_resume (frame, server_open_resume); - - return 0; -} - - -static int -server_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, server_readv_cbk, - bound_xl, bound_xl->fops->readv, - state->fd, state->size, state->offset); - - return 0; -err: - server_readv_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno, NULL, 0, NULL, NULL); - return 0; -} - - -static int -server_readv (call_frame_t *frame, xlator_t *bound_xl, - gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_fop_read_req_t *req = NULL; - server_state_t *state = NULL; - - req = gf_param (hdr); - state = CALL_STATE (frame); - - state->resolve.type = RESOLVE_MUST; - state->resolve.fd_no = ntoh64 (req->fd); - state->size = ntoh32 (req->size); - state->offset = ntoh64 (req->offset); - - gf_resolve_and_resume (frame, server_readv_resume); - - return 0; -} - - -static int -server_writev_resume (call_frame_t *frame, xlator_t *bound_xl) -{ - server_state_t *state = NULL; - struct iovec iov = {0, }; - - state = CALL_STATE (frame); - - if (state->resolve.op_ret != 0) - goto err; - - iov.iov_len = state->size; - - if (state->iobuf) { - iov.iov_base = state->iobuf->ptr; - } - - STACK_WIND (frame, server_writev_cbk, - bound_xl, bound_xl->fops->writev, - state->fd, &iov, 1, state->offset, state->iobref); - - return 0; -err: - server_writev_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno, NULL, NULL); - return 0; -} - - -static int -server_writev (call_frame_t *frame, xlator_t *bound_xl, - gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_fop_write_req_t *req = NULL; - server_state_t *state = NULL; - struct iobref *iobref = NULL; - - req = gf_param (hdr); - state = CALL_STATE (frame); - - state->resolve.type = RESOLVE_MUST; - state->resolve.fd_no = ntoh64 (req->fd); - state->offset = ntoh64 (req->offset); - state->size = ntoh32 (req->size); - - if (iobuf) { - iobref = iobref_new (); - iobref_add (iobref, iobuf); - - state->iobuf = iobuf; - state->iobref = iobref; - } - - gf_resolve_and_resume (frame, server_writev_resume); - - return 0; -} - - -static int -server_release (call_frame_t *frame, xlator_t *bound_xl, - gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_cbk_release_req_t *req = NULL; - server_state_t *state = NULL; - server_connection_t *conn = NULL; - - conn = SERVER_CONNECTION (frame); - state = CALL_STATE (frame); - req = gf_param (hdr); - - state->resolve.fd_no = ntoh64 (req->fd); - - gf_fd_put (conn->fdtable, state->resolve.fd_no); - - server_release_cbk (frame, NULL, frame->this, 0, 0); - - return 0; -} - - -static int -server_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, server_fsync_cbk, - bound_xl, bound_xl->fops->fsync, - state->fd, state->flags); - return 0; -err: - server_fsync_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno, NULL, NULL); - - return 0; -} - - -static int -server_fsync (call_frame_t *frame, xlator_t *bound_xl, - gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_fop_fsync_req_t *req = NULL; - server_state_t *state = NULL; - - req = gf_param (hdr); - state = CALL_STATE (frame); - - state->resolve.type = RESOLVE_MUST; - state->resolve.fd_no = ntoh64 (req->fd); - state->flags = ntoh32 (req->data); - - gf_resolve_and_resume (frame, server_fsync_resume); - - return 0; -} - - - -static int -server_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, server_flush_cbk, - bound_xl, bound_xl->fops->flush, state->fd); - return 0; -err: - server_flush_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno); - - return 0; -} - - -static int -server_flush (call_frame_t *frame, xlator_t *bound_xl, - gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_fop_fsync_req_t *req = NULL; - server_state_t *state = NULL; - - req = gf_param (hdr); - state = CALL_STATE (frame); - - state->resolve.type = RESOLVE_MUST; - state->resolve.fd_no = ntoh64 (req->fd); - - gf_resolve_and_resume (frame, server_flush_resume); - - return 0; -} - - - -static int -server_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, server_ftruncate_cbk, - bound_xl, bound_xl->fops->ftruncate, - state->fd, state->offset); - return 0; -err: - server_ftruncate_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno, NULL, NULL); - - return 0; -} - - -static int -server_ftruncate (call_frame_t *frame, xlator_t *bound_xl, - gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_fop_ftruncate_req_t *req = NULL; - server_state_t *state = NULL; - - req = gf_param (hdr); - state = CALL_STATE (frame); - - state->resolve.type = RESOLVE_MUST; - state->resolve.fd_no = ntoh64 (req->fd); - state->offset = ntoh64 (req->offset); - - gf_resolve_and_resume (frame, server_ftruncate_resume); - - return 0; -} - - -static int -server_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, server_fstat_cbk, - bound_xl, bound_xl->fops->fstat, - state->fd); - return 0; -err: - server_fstat_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno, NULL); - return 0; -} - - -static int -server_fstat (call_frame_t *frame, xlator_t *bound_xl, - gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_fop_fstat_req_t *req = NULL; - server_state_t *state = NULL; - - req = gf_param (hdr); - state = CALL_STATE (frame); - - state->resolve.type = RESOLVE_MUST; - state->resolve.fd_no = ntoh64 (req->fd); - - gf_resolve_and_resume (frame, server_fstat_resume); - - return 0; -} - - -static int -server_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, server_truncate_cbk, - bound_xl, bound_xl->fops->truncate, - &state->loc, state->offset); - return 0; -err: - server_truncate_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno, NULL, NULL); - return 0; -} - - - -static int -server_truncate (call_frame_t *frame, xlator_t *bound_xl, - gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_fop_truncate_req_t *req = NULL; - server_state_t *state = NULL; - - req = gf_param (hdr); - state = CALL_STATE (frame); - - state->resolve.type = RESOLVE_MUST; - state->resolve.path = gf_strdup (req->path); - state->resolve.ino = ntoh64 (req->ino); - state->resolve.gen = ntoh64 (req->gen); - state->offset = ntoh64 (req->offset); - - gf_resolve_and_resume (frame, server_truncate_resume); - - return 0; -} - - -static int -server_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, server_unlink_cbk, - bound_xl, bound_xl->fops->unlink, - &state->loc); - return 0; -err: - server_unlink_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno, NULL, NULL); - return 0; -} - - -static int -server_unlink (call_frame_t *frame, xlator_t *bound_xl, - gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_fop_unlink_req_t *req = NULL; - server_state_t *state = NULL; - int pathlen = 0; - - req = gf_param (hdr); - state = CALL_STATE (frame); - - pathlen = STRLEN_0 (req->path); - - state->resolve.type = RESOLVE_MUST; - state->resolve.par = ntoh64 (req->par); - state->resolve.gen = ntoh64 (req->gen); - state->resolve.path = gf_strdup (req->path); - state->resolve.bname = gf_strdup (req->bname + pathlen); - - gf_resolve_and_resume (frame, server_unlink_resume); - - return 0; -} - - -static int -server_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, server_setxattr_cbk, - bound_xl, bound_xl->fops->setxattr, - &state->loc, state->dict, state->flags); - return 0; -err: - server_setxattr_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno); - - return 0; -} - - -static int -server_setxattr (call_frame_t *frame, xlator_t *bound_xl, - gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_fop_setxattr_req_t *req = NULL; - server_state_t *state = NULL; - dict_t *dict = NULL; - int32_t ret = -1; - size_t dict_len = 0; - char *req_dictbuf = NULL; - - req = gf_param (hdr); - state = CALL_STATE (frame); - - dict_len = ntoh32 (req->dict_len); - - state->resolve.type = RESOLVE_MUST; - state->resolve.path = gf_strdup (req->path + dict_len); - state->resolve.ino = ntoh64 (req->ino); - state->resolve.gen = ntoh64 (req->gen); - state->flags = ntoh32 (req->flags); - - if (dict_len) { - req_dictbuf = memdup (req->dict, dict_len); - - dict = dict_new (); - - ret = dict_unserialize (req_dictbuf, dict_len, &dict); - if (ret < 0) { - gf_log (bound_xl->name, GF_LOG_ERROR, - "%"PRId64": %s (%"PRId64"): failed to " - "unserialize request buffer to dictionary", - frame->root->unique, state->loc.path, - state->resolve.ino); - GF_FREE (req_dictbuf); - goto err; - } - - dict->extra_free = req_dictbuf; - state->dict = dict; - } - - gf_resolve_and_resume (frame, server_setxattr_resume); - - return 0; -err: - if (dict) - dict_unref (dict); - - server_setxattr_cbk (frame, NULL, frame->this, -1, EINVAL); - - return 0; - -} - - -static int -server_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, server_setxattr_cbk, - bound_xl, bound_xl->fops->fsetxattr, - state->fd, state->dict, state->flags); - return 0; -err: - server_fsetxattr_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno); - - return 0; -} - - -static int -server_fsetxattr (call_frame_t *frame, xlator_t *bound_xl, - gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_fop_fsetxattr_req_t *req = NULL; - server_state_t *state = NULL; - dict_t *dict = NULL; - int32_t ret = -1; - size_t dict_len = 0; - char *req_dictbuf = NULL; - - req = gf_param (hdr); - state = CALL_STATE (frame); - - dict_len = ntoh32 (req->dict_len); - - state->resolve.type = RESOLVE_MUST; - state->resolve.fd_no = ntoh64 (req->fd); - state->flags = ntoh32 (req->flags); - - if (dict_len) { - req_dictbuf = memdup (req->dict, dict_len); - - dict = dict_new (); - - ret = dict_unserialize (req_dictbuf, dict_len, &dict); - if (ret < 0) { - gf_log (bound_xl->name, GF_LOG_ERROR, - "%"PRId64": %s (%"PRId64"): failed to " - "unserialize request buffer to dictionary", - frame->root->unique, state->loc.path, - state->resolve.ino); - GF_FREE (req_dictbuf); - goto err; - } - - dict->extra_free = req_dictbuf; - state->dict = dict; - } - - gf_resolve_and_resume (frame, server_fsetxattr_resume); - - return 0; -err: - if (dict) - dict_unref (dict); - - server_setxattr_cbk (frame, NULL, frame->this, -1, EINVAL); - - return 0; -} - - -static int -server_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, server_fxattrop_cbk, - bound_xl, bound_xl->fops->fxattrop, - state->fd, state->flags, state->dict); - return 0; -err: - server_fxattrop_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno, NULL); - return 0; -} - - -static int -server_fxattrop (call_frame_t *frame, xlator_t *bound_xl, - gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_fop_fxattrop_req_t *req = NULL; - dict_t *dict = NULL; - server_state_t *state = NULL; - size_t dict_len = 0; - char *req_dictbuf = NULL; - int32_t ret = -1; - - req = gf_param (hdr); - state = CALL_STATE(frame); - - dict_len = ntoh32 (req->dict_len); - - state->resolve.type = RESOLVE_MUST; - state->resolve.fd_no = ntoh64 (req->fd); - - state->resolve.ino = ntoh64 (req->ino); - state->resolve.gen = ntoh64 (req->gen); - state->flags = ntoh32 (req->flags); - - if (dict_len) { - /* Unserialize the dictionary */ - req_dictbuf = memdup (req->dict, dict_len); - - dict = dict_new (); - - ret = dict_unserialize (req_dictbuf, dict_len, &dict); - if (ret < 0) { - gf_log (bound_xl->name, GF_LOG_ERROR, - "fd - %"PRId64" (%"PRId64"): failed to unserialize " - "request buffer to dictionary", - state->resolve.fd_no, state->fd->inode->ino); - GF_FREE (req_dictbuf); - goto fail; - } - dict->extra_free = req_dictbuf; - state->dict = dict; - dict = NULL; - } - - gf_resolve_and_resume (frame, server_fxattrop_resume); - - return 0; - -fail: - if (dict) - dict_unref (dict); - - server_fxattrop_cbk (frame, NULL, frame->this, -1, EINVAL, NULL); - return 0; -} - - -static int -server_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, server_xattrop_cbk, - bound_xl, bound_xl->fops->xattrop, - &state->loc, state->flags, state->dict); - return 0; -err: - server_xattrop_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno, NULL); - return 0; -} - - -static int -server_xattrop (call_frame_t *frame, xlator_t *bound_xl, - gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_fop_xattrop_req_t *req = NULL; - dict_t *dict = NULL; - server_state_t *state = NULL; - size_t dict_len = 0; - char *req_dictbuf = NULL; - int32_t ret = -1; - - req = gf_param (hdr); - state = CALL_STATE(frame); - - dict_len = ntoh32 (req->dict_len); - - state->resolve.type = RESOLVE_MUST; - state->resolve.path = gf_strdup (req->path + dict_len); - state->resolve.ino = ntoh64 (req->ino); - state->resolve.gen = ntoh64 (req->gen); - state->flags = ntoh32 (req->flags); - - if (dict_len) { - /* Unserialize the dictionary */ - req_dictbuf = memdup (req->dict, dict_len); - - dict = dict_new (); - - ret = dict_unserialize (req_dictbuf, dict_len, &dict); - if (ret < 0) { - gf_log (bound_xl->name, GF_LOG_ERROR, - "fd - %"PRId64" (%"PRId64"): failed to unserialize " - "request buffer to dictionary", - state->resolve.fd_no, state->fd->inode->ino); - GF_FREE (req_dictbuf); - goto fail; - } - dict->extra_free = req_dictbuf; - state->dict = dict; - dict = NULL; - } - - gf_resolve_and_resume (frame, server_xattrop_resume); - - return 0; - -fail: - if (dict) - dict_unref (dict); - - server_xattrop_cbk (frame, NULL, frame->this, -1, EINVAL, NULL); - return 0; -} - - -static int -server_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, server_getxattr_cbk, - bound_xl, bound_xl->fops->getxattr, - &state->loc, state->name); - return 0; -err: - server_getxattr_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno, NULL); - return 0; -} - - -static int -server_getxattr (call_frame_t *frame, xlator_t *bound_xl, - gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_fop_getxattr_req_t *req = NULL; - server_state_t *state = NULL; - size_t namelen = 0; - size_t pathlen = 0; - - req = gf_param (hdr); - state = CALL_STATE (frame); - - pathlen = STRLEN_0 (req->path); - - state->resolve.type = RESOLVE_MUST; - state->resolve.path = gf_strdup (req->path); - state->resolve.ino = ntoh64 (req->ino); - state->resolve.gen = ntoh64 (req->gen); - - namelen = ntoh32 (req->namelen); - if (namelen) - state->name = gf_strdup (req->name + pathlen); - - gf_resolve_and_resume (frame, server_getxattr_resume); - - return 0; -} - - -static int -server_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, server_fgetxattr_cbk, - bound_xl, bound_xl->fops->fgetxattr, - state->fd, state->name); - return 0; -err: - server_fgetxattr_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno, NULL); - return 0; -} - - -static int -server_fgetxattr (call_frame_t *frame, xlator_t *bound_xl, - gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_fop_fgetxattr_req_t *req = NULL; - server_state_t *state = NULL; - size_t namelen = 0; - - req = gf_param (hdr); - state = CALL_STATE (frame); - - state->resolve.type = RESOLVE_MUST; - state->resolve.fd_no = ntoh64 (req->fd); - - namelen = ntoh32 (req->namelen); - if (namelen) - state->name = gf_strdup (req->name); - - gf_resolve_and_resume (frame, server_fgetxattr_resume); - - return 0; -} - - -static int -server_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, server_removexattr_cbk, - bound_xl, bound_xl->fops->removexattr, - &state->loc, state->name); - return 0; -err: - server_removexattr_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno); - return 0; -} - - -static int -server_removexattr (call_frame_t *frame, xlator_t *bound_xl, - gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_fop_removexattr_req_t *req = NULL; - server_state_t *state = NULL; - size_t pathlen = 0; - - req = gf_param (hdr); - state = CALL_STATE (frame); - pathlen = STRLEN_0 (req->path); - - state->resolve.type = RESOLVE_MUST; - state->resolve.path = gf_strdup (req->path); - state->resolve.ino = ntoh64 (req->ino); - state->resolve.gen = ntoh64 (req->gen); - state->name = gf_strdup (req->name + pathlen); - - gf_resolve_and_resume (frame, server_removexattr_resume); - - return 0; -} - - -static int -server_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, server_statfs_cbk, - bound_xl, bound_xl->fops->statfs, - &state->loc); - return 0; - -err: - server_statfs_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno, NULL); - return 0; -} - - -static int -server_statfs (call_frame_t *frame, xlator_t *bound_xl, - gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_fop_statfs_req_t *req = NULL; - server_state_t *state = NULL; - - req = gf_param (hdr); - - state = CALL_STATE (frame); - - state->resolve.type = RESOLVE_MUST; - state->resolve.ino = ntoh64 (req->ino); - if (!state->resolve.ino) - state->resolve.ino = 1; - state->resolve.gen = ntoh64 (req->gen); - state->resolve.path = gf_strdup (req->path); - - gf_resolve_and_resume (frame, server_statfs_resume); - - return 0; -} - - -static int -server_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); - - STACK_WIND (frame, server_opendir_cbk, - bound_xl, bound_xl->fops->opendir, - &state->loc, state->fd); - return 0; -err: - server_opendir_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno, NULL); - return 0; -} - - -static int -server_opendir (call_frame_t *frame, xlator_t *bound_xl, - gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_fop_opendir_req_t *req = NULL; - server_state_t *state = NULL; - - req = gf_param (hdr); - state = CALL_STATE (frame); - - state->resolve.type = RESOLVE_MUST; - state->resolve.path = gf_strdup (req->path); - state->resolve.ino = ntoh64 (req->ino); - state->resolve.gen = ntoh64 (req->gen); - - gf_resolve_and_resume (frame, server_opendir_resume); - - return 0; -} - - -static int -server_releasedir (call_frame_t *frame, xlator_t *bound_xl, - gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_cbk_releasedir_req_t *req = NULL; - server_connection_t *conn = NULL; - uint64_t fd_no = 0; - - conn = SERVER_CONNECTION (frame); - - req = gf_param (hdr); - - fd_no = ntoh64 (req->fd); - - gf_fd_put (conn->fdtable, fd_no); - - server_releasedir_cbk (frame, NULL, frame->this, 0, 0); - - return 0; -} - -/* - * server_readdirp_cbk - getdents callback for server protocol - * @frame: call frame - * @cookie: - * @this: - * @op_ret: - * @op_errno: - * - * not for external reference - */ -static int -server_readdirp_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, gf_dirent_t *entries) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_readdirp_rsp_t *rsp = NULL; - size_t hdrlen = 0; - size_t buf_size = 0; - int32_t gf_errno = 0; - server_state_t *state = NULL; - - if (op_ret > 0) - buf_size = gf_dirent_serialize (entries, NULL, 0); - - hdrlen = gf_hdr_len (rsp, buf_size); - hdr = gf_hdr_new (rsp, buf_size); - rsp = gf_param (hdr); - - hdr->rsp.op_ret = hton32 (op_ret); - gf_errno = gf_errno_to_error (op_errno); - hdr->rsp.op_errno = hton32 (gf_errno); - - if (op_ret > 0) { - rsp->size = hton32 (buf_size); - gf_dirent_serialize (entries, rsp->buf, buf_size); - } else { - state = CALL_STATE(frame); - - gf_log (this->name, GF_LOG_TRACE, - "%"PRId64": READDIRP %"PRId64" (%"PRId64") ==>" - "%"PRId32" (%s)", - frame->root->unique, state->resolve.fd_no, - state->fd ? state->fd->inode->ino : 0, op_ret, - strerror (op_errno)); - } - - protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_READDIRP, - hdr, hdrlen, NULL, 0, NULL); - - return 0; -} - -static int -server_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, server_readdirp_cbk, bound_xl, - bound_xl->fops->readdirp, state->fd, state->size, - state->offset); - - return 0; -err: - server_readdirp_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno, NULL); - return 0; -} - -/* - * server_readdirp - readdirp function for server protocol - * @frame: call frame - * @bound_xl: - * @params: parameter dictionary - * - * not for external reference - */ -static int -server_readdirp (call_frame_t *frame, xlator_t *bound_xl, gf_hdr_common_t *hdr, - size_t hdrlen, struct iobuf *iobuf) -{ - gf_fop_readdirp_req_t *req = NULL; - server_state_t *state = NULL; - server_connection_t *conn = NULL; - - conn = SERVER_CONNECTION(frame); - - req = gf_param (hdr); - state = CALL_STATE(frame); - - state->resolve.type = RESOLVE_MUST; - state->resolve.fd_no = ntoh64 (req->fd); - state->size = ntoh32 (req->size); - state->offset = ntoh64 (req->offset); - - gf_resolve_and_resume (frame, server_readdirp_resume); - - return 0; -} - - -static int - server_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; - - STACK_WIND (frame, server_readdir_cbk, - bound_xl, - bound_xl->fops->readdir, - state->fd, state->size, state->offset); - - return 0; -err: - server_readdir_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno, NULL); - return 0; -} -/* - * server_readdir - readdir function for server protocol - * @frame: call frame - * @bound_xl: - * @params: parameter dictionary - * - * not for external reference - */ -static int -server_readdir (call_frame_t *frame, xlator_t *bound_xl, - gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_fop_readdir_req_t *req = NULL; - server_state_t *state = NULL; - server_connection_t *conn = NULL; - - conn = SERVER_CONNECTION(frame); - - req = gf_param (hdr); - state = CALL_STATE(frame); - - state->resolve.type = RESOLVE_MUST; - state->resolve.fd_no = ntoh64 (req->fd); - state->size = ntoh32 (req->size); - state->offset = ntoh64 (req->offset); - - gf_resolve_and_resume (frame, server_readdir_resume); - - return 0; -} - -static int -server_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, server_fsyncdir_cbk, - bound_xl, - bound_xl->fops->fsyncdir, - state->fd, state->flags); - return 0; - -err: - server_fsyncdir_cbk (frame, NULL, frame->this, - state->resolve.op_ret, - state->resolve.op_errno); - return 0; -} - -/* - * server_fsyncdir - fsyncdir function for server protocol - * @frame: call frame - * @bound_xl: - * @params: parameter dictionary - * - * not for external reference - */ -static int -server_fsyncdir (call_frame_t *frame, xlator_t *bound_xl, - gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_fop_fsyncdir_req_t *req = NULL; - server_state_t *state = NULL; - server_connection_t *conn = NULL; - - conn = SERVER_CONNECTION (frame); - - req = gf_param (hdr); - state = CALL_STATE(frame); - - state->resolve.type = RESOLVE_MUST; - state->resolve.fd_no = ntoh64 (req->fd); - state->flags = ntoh32 (req->data); - - gf_resolve_and_resume (frame, server_fsyncdir_resume); - - return 0; -} - - -static int -server_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, server_mknod_cbk, - bound_xl, bound_xl->fops->mknod, - &(state->loc), state->mode, state->dev, - state->params); - - return 0; -err: - server_mknod_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno, NULL, NULL, NULL, NULL); - return 0; -} - - - -static int -server_mknod (call_frame_t *frame, xlator_t *bound_xl, - gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_fop_mknod_req_t *req = NULL; - server_state_t *state = NULL; - size_t pathlen = 0; - - req = gf_param (hdr); - state = CALL_STATE (frame); - pathlen = STRLEN_0 (req->path); - - state->resolve.type = RESOLVE_NOT; - state->resolve.par = ntoh64 (req->par); - state->resolve.gen = ntoh64 (req->gen); - state->resolve.path = gf_strdup (req->path); - state->resolve.bname = gf_strdup (req->bname + pathlen); - - state->mode = ntoh32 (req->mode); - state->dev = ntoh64 (req->dev); - - gf_resolve_and_resume (frame, server_mknod_resume); - - return 0; -} - - -static int -server_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, server_mkdir_cbk, - bound_xl, bound_xl->fops->mkdir, - &(state->loc), state->mode, - state->params); - - return 0; -err: - server_mkdir_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno, NULL, NULL, NULL, NULL); - return 0; -} - - -static int -server_mkdir (call_frame_t *frame, xlator_t *bound_xl, - gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_fop_mkdir_req_t *req = NULL; - server_state_t *state = NULL; - size_t pathlen = 0; - - req = gf_param (hdr); - state = CALL_STATE (frame); - pathlen = STRLEN_0 (req->path); - - state->resolve.type = RESOLVE_NOT; - state->resolve.par = ntoh64 (req->par); - state->resolve.gen = ntoh64 (req->gen); - state->resolve.path = gf_strdup (req->path); - state->resolve.bname = gf_strdup (req->bname + pathlen); - - state->mode = ntoh32 (req->mode); - - gf_resolve_and_resume (frame, server_mkdir_resume); - - return 0; -} - - -static int -server_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, server_rmdir_cbk, - bound_xl, bound_xl->fops->rmdir, &state->loc); - return 0; -err: - server_rmdir_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno, NULL, NULL); - return 0; -} - -static int -server_rmdir (call_frame_t *frame, xlator_t *bound_xl, - gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_fop_rmdir_req_t *req = NULL; - server_state_t *state = NULL; - int pathlen = 0; - - req = gf_param (hdr); - state = CALL_STATE (frame); - pathlen = STRLEN_0 (req->path); - - state->resolve.type = RESOLVE_MUST; - state->resolve.par = ntoh64 (req->par); - state->resolve.gen = ntoh64 (req->gen); - state->resolve.path = gf_strdup (req->path); - state->resolve.bname = gf_strdup (req->bname + pathlen); - - gf_resolve_and_resume (frame, server_rmdir_resume); - - return 0; -} - - -static int -server_inodelk_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, server_inodelk_cbk, - bound_xl, bound_xl->fops->inodelk, - state->volume, &state->loc, state->cmd, &state->flock); - return 0; -err: - server_inodelk_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno); - return 0; -} - - -static int -server_inodelk (call_frame_t *frame, xlator_t *bound_xl, - gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_fop_inodelk_req_t *req = NULL; - server_state_t *state = NULL; - size_t pathlen = 0; - size_t vollen = 0; - int cmd = 0; - - req = gf_param (hdr); - state = CALL_STATE (frame); - pathlen = STRLEN_0 (req->path); - vollen = STRLEN_0 (req->volume + pathlen); - - state->resolve.type = RESOLVE_EXACT; - state->resolve.ino = ntoh64 (req->ino); - state->resolve.gen = ntoh64 (req->gen); - state->resolve.path = gf_strdup (req->path); - - cmd = ntoh32 (req->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 = ntoh32 (req->type); - state->volume = gf_strdup (req->volume + pathlen); - - gf_flock_to_flock (&req->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; - } - - gf_resolve_and_resume (frame, server_inodelk_resume); - - return 0; -} - -static int -server_finodelk_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, server_finodelk_cbk, - BOUND_XL(frame), - BOUND_XL(frame)->fops->finodelk, - state->volume, state->fd, state->cmd, &state->flock); - - return 0; -err: - server_finodelk_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno); - - return 0; -} - -static int -server_finodelk (call_frame_t *frame, xlator_t *bound_xl, - gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_fop_finodelk_req_t *req = NULL; - server_state_t *state = NULL; - server_connection_t *conn = NULL; - - conn = SERVER_CONNECTION(frame); - - req = gf_param (hdr); - state = CALL_STATE(frame); - - state->resolve.type = RESOLVE_EXACT; - state->volume = gf_strdup (req->volume); - state->resolve.fd_no = ntoh64 (req->fd); - state->cmd = ntoh32 (req->cmd); - - 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 = ntoh32 (req->type); - - gf_flock_to_flock (&req->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; - } - - gf_resolve_and_resume (frame, server_finodelk_resume); - - return 0; -} - - -static int -server_entrylk_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, server_entrylk_cbk, - bound_xl, bound_xl->fops->entrylk, - state->volume, &state->loc, state->name, - state->cmd, state->type); - return 0; -err: - server_entrylk_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno); - return 0; -} - - -static int -server_entrylk (call_frame_t *frame, xlator_t *bound_xl, - gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_fop_entrylk_req_t *req = NULL; - server_state_t *state = NULL; - size_t pathlen = 0; - size_t namelen = 0; - size_t vollen = 0; - - req = gf_param (hdr); - state = CALL_STATE (frame); - pathlen = STRLEN_0 (req->path); - namelen = ntoh64 (req->namelen); - vollen = STRLEN_0(req->volume + pathlen + namelen); - - state->resolve.type = RESOLVE_EXACT; - state->resolve.path = gf_strdup (req->path); - state->resolve.ino = ntoh64 (req->ino); - state->resolve.gen = ntoh64 (req->gen); - - if (namelen) - state->name = gf_strdup (req->name + pathlen); - state->volume = gf_strdup (req->volume + pathlen + namelen); - - state->cmd = ntoh32 (req->cmd); - state->type = ntoh32 (req->type); - - gf_resolve_and_resume (frame, server_entrylk_resume); - - return 0; -} - -static int -server_fentrylk_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, server_fentrylk_cbk, - BOUND_XL(frame), - BOUND_XL(frame)->fops->fentrylk, - state->volume, state->fd, state->name, - state->cmd, state->type); - - return 0; -err: - server_fentrylk_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno); - return 0; -} - -static int -server_fentrylk (call_frame_t *frame, xlator_t *bound_xl, - gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_fop_fentrylk_req_t *req = NULL; - server_state_t *state = NULL; - size_t namelen = 0; - size_t vollen = 0; - server_connection_t *conn = NULL; - - conn = SERVER_CONNECTION (frame); - - req = gf_param (hdr); - state = CALL_STATE(frame); - vollen = STRLEN_0(req->volume + namelen); - - state->resolve.type = RESOLVE_EXACT; - state->resolve.fd_no = ntoh64 (req->fd); - state->cmd = ntoh32 (req->cmd); - state->type = ntoh32 (req->type); - namelen = ntoh64 (req->namelen); - if (namelen) - state->name = req->name; - state->volume = gf_strdup (req->volume + namelen); - - - gf_resolve_and_resume (frame, server_fentrylk_resume); - - return 0; -} - - -static int -server_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, server_access_cbk, - bound_xl, bound_xl->fops->access, - &state->loc, state->mask); - return 0; -err: - server_access_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno); - return 0; -} - - -static int -server_access (call_frame_t *frame, xlator_t *bound_xl, - gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_fop_access_req_t *req = NULL; - server_state_t *state = NULL; - - req = gf_param (hdr); - state = CALL_STATE (frame); - - state->resolve.type = RESOLVE_MUST; - state->resolve.ino = hton64 (req->ino); - state->resolve.gen = hton64 (req->gen); - state->resolve.path = gf_strdup (req->path); - - state->mask = ntoh32 (req->mask); - - gf_resolve_and_resume (frame, server_access_resume); - - return 0; -} - - -static int -server_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, server_symlink_cbk, - bound_xl, bound_xl->fops->symlink, - state->name, &state->loc, state->params); - - return 0; -err: - server_symlink_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno, NULL, NULL, NULL, NULL); - return 0; -} - - - -static int -server_symlink (call_frame_t *frame, xlator_t *bound_xl, - gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - server_state_t *state = NULL; - gf_fop_symlink_req_t *req = NULL; - size_t pathlen = 0; - size_t baselen = 0; - - req = gf_param (hdr); - state = CALL_STATE (frame); - pathlen = STRLEN_0 (req->path); - baselen = STRLEN_0 (req->bname + pathlen); - - state->resolve.type = RESOLVE_NOT; - state->resolve.par = ntoh64 (req->par); - state->resolve.gen = ntoh64 (req->gen); - state->resolve.path = gf_strdup (req->path); - state->resolve.bname = gf_strdup (req->bname + pathlen); - state->name = gf_strdup (req->linkname + pathlen + baselen); - - gf_resolve_and_resume (frame, server_symlink_resume); - - return 0; -} - - -static int -server_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, server_link_cbk, - bound_xl, bound_xl->fops->link, - &state->loc, &state->loc2); - return 0; -err: - server_link_cbk (frame, NULL, frame->this, op_ret, op_errno, - NULL, NULL, NULL, NULL); - return 0; -} - - -static int -server_link (call_frame_t *frame, xlator_t *this, - gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_fop_link_req_t *req = NULL; - server_state_t *state = NULL; - size_t oldpathlen = 0; - size_t newpathlen = 0; - size_t newbaselen = 0; - - req = gf_param (hdr); - state = CALL_STATE (frame); - oldpathlen = STRLEN_0 (req->oldpath); - newpathlen = STRLEN_0 (req->newpath + oldpathlen); - newbaselen = STRLEN_0 (req->newbname + oldpathlen + newpathlen); - - state->resolve.type = RESOLVE_MUST; - state->resolve.path = gf_strdup (req->oldpath); - state->resolve.ino = ntoh64 (req->oldino); - state->resolve.gen = ntoh64 (req->oldgen); - - state->resolve2.type = RESOLVE_NOT; - state->resolve2.path = gf_strdup (req->newpath + oldpathlen); - state->resolve2.bname = gf_strdup (req->newbname + oldpathlen + newpathlen); - state->resolve2.par = ntoh64 (req->newpar); - state->resolve2.gen = ntoh64 (req->newgen); - - gf_resolve_and_resume (frame, server_link_resume); - - return 0; -} - - -static int -server_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, server_rename_cbk, - bound_xl, bound_xl->fops->rename, - &state->loc, &state->loc2); - return 0; -err: - server_rename_cbk (frame, NULL, frame->this, op_ret, op_errno, - NULL, NULL, NULL, NULL, NULL); - return 0; -} - - -static int -server_rename (call_frame_t *frame, xlator_t *bound_xl, - gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_fop_rename_req_t *req = NULL; - server_state_t *state = NULL; - size_t oldpathlen = 0; - size_t oldbaselen = 0; - size_t newpathlen = 0; - size_t newbaselen = 0; - - req = gf_param (hdr); - - state = CALL_STATE (frame); - oldpathlen = STRLEN_0 (req->oldpath); - oldbaselen = STRLEN_0 (req->oldbname + oldpathlen); - newpathlen = STRLEN_0 (req->newpath + oldpathlen + oldbaselen); - newbaselen = STRLEN_0 (req->newbname + oldpathlen + - oldbaselen + newpathlen); - - state->resolve.type = RESOLVE_MUST; - state->resolve.path = gf_strdup (req->oldpath); - state->resolve.bname = gf_strdup (req->oldbname + oldpathlen); - state->resolve.par = ntoh64 (req->oldpar); - state->resolve.gen = ntoh64 (req->oldgen); - - state->resolve2.type = RESOLVE_MAY; - state->resolve2.path = gf_strdup (req->newpath + oldpathlen + oldbaselen); - state->resolve2.bname = gf_strdup (req->newbname + oldpathlen + oldbaselen + - newpathlen); - state->resolve2.par = ntoh64 (req->newpar); - state->resolve2.gen = ntoh64 (req->newgen); - - gf_resolve_and_resume (frame, server_rename_resume); - - return 0; -} - -static int -server_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, server_lk_cbk, - BOUND_XL(frame), - BOUND_XL(frame)->fops->lk, - state->fd, state->cmd, &state->flock); - - return 0; - -err: - server_lk_cbk (frame, NULL, frame->this, - state->resolve.op_ret, - state->resolve.op_errno, - NULL); - return 0; -} - -/* - * server_lk - lk function for server protocol - * @frame: call frame - * @bound_xl: - * @params: parameter dictionary - * - * not for external reference - */ - -static int -server_lk (call_frame_t *frame, xlator_t *bound_xl, - gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_fop_lk_req_t *req = NULL; - server_state_t *state = NULL; - server_connection_t *conn = NULL; - - conn = SERVER_CONNECTION (frame); - - req = gf_param (hdr); - state = CALL_STATE (frame); - - state->resolve.fd_no = ntoh64 (req->fd); - state->cmd = ntoh32 (req->cmd); - state->type = ntoh32 (req->type); - - 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; - } - - gf_flock_to_flock (&req->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_log (bound_xl->name, GF_LOG_ERROR, - "fd - %"PRId64" (%"PRId64"): Unknown lock type: %"PRId32"!", - state->resolve.fd_no, state->fd->inode->ino, state->type); - break; - } - - - gf_resolve_and_resume (frame, server_lk_resume); - - return 0; -} - -/* xxx_MOPS */ -static int -_volfile_update_checksum (xlator_t *this, char *key, uint32_t checksum) -{ - server_conf_t *conf = NULL; - struct _volfile_ctx *temp_volfile = NULL; - - conf = this->private; - temp_volfile = conf->volfile; - - while (temp_volfile) { - if ((NULL == key) && (NULL == temp_volfile->key)) - break; - if ((NULL == key) || (NULL == temp_volfile->key)) { - temp_volfile = temp_volfile->next; - continue; - } - if (strcmp (temp_volfile->key, key) == 0) - break; - temp_volfile = temp_volfile->next; - } - - if (!temp_volfile) { - temp_volfile = GF_CALLOC (1, sizeof (struct _volfile_ctx), - gf_server_mt_volfile_ctx); - if (!temp_volfile) - goto out; - temp_volfile->next = conf->volfile; - temp_volfile->key = (key)? gf_strdup (key): NULL; - temp_volfile->checksum = checksum; - - conf->volfile = temp_volfile; - goto out; - } - - if (temp_volfile->checksum != checksum) { - gf_log (this->name, GF_LOG_CRITICAL, - "the volume file got modified between earlier access " - "and now, this may lead to inconsistency between " - "clients, advised to remount client"); - temp_volfile->checksum = checksum; - } - - out: - return 0; -} - - -size_t -build_volfile_path (xlator_t *this, const char *key, char *path, - size_t path_len) -{ - int ret = -1; - int free_filename = 0; - int free_conf_dir = 0; - char *filename = NULL; - char *conf_dir = CONFDIR; - struct stat buf = {0,}; - data_t * conf_dir_data = NULL; - char data_key[256] = {0,}; - - /* Inform users that this option is changed now */ - ret = dict_get_str (this->options, "client-volume-filename", - &filename); - if (ret == 0) { - gf_log (this->name, GF_LOG_WARNING, - "option 'client-volume-filename' is changed to " - "'volume-filename.<key>' which now takes 'key' as an " - "option to choose/fetch different files from server. " - "Refer documentation or contact developers for more " - "info. Currently defaulting to given file '%s'", - filename); - } - - if (key && !filename) { - sprintf (data_key, "volume-filename.%s", key); - ret = dict_get_str (this->options, data_key, &filename); - - if (ret < 0) { - - conf_dir_data = dict_get (this->options, "conf-dir"); - if (conf_dir_data) { - /* Check whether the specified directory exists, - or directory specified is non standard */ - ret = stat (conf_dir_data->data, &buf); - if ((ret != 0) || !S_ISDIR (buf.st_mode)) { - gf_log (this->name, GF_LOG_ERROR, - "Directory '%s' doesn't" - "exist, exiting.", - conf_dir_data->data); - ret = -1; - goto out; - } - /* Make sure that conf-dir doesn't - * contain ".." in path - */ - if ((gf_strstr (conf_dir_data->data, - "/", "..")) == -1) { - ret = -1; - gf_log (this->name, GF_LOG_ERROR, - "%s: invalid conf_dir", - conf_dir_data->data); - goto out; - } - - /* Make sure that key doesn't - * contain "../" in path - */ - - if ((gf_strstr (key, "/", "..")) == -1) { - ret = -1; - gf_log (this->name, GF_LOG_ERROR, - "%s: invalid key", key); - goto out; - } - - conf_dir = gf_strdup (conf_dir_data->data); - free_conf_dir = 1; - } - - ret = gf_asprintf (&filename, "%s/%s.vol", - conf_dir, key); - if (-1 == ret) - goto out; - - free_filename = 1; - } - } - - if (!filename) { - ret = dict_get_str (this->options, - "volume-filename.default", &filename); - if (ret < 0) { - gf_log (this->name, GF_LOG_DEBUG, - "no default volume filename given, " - "defaulting to %s", DEFAULT_VOLUME_FILE_PATH); - filename = DEFAULT_VOLUME_FILE_PATH; - } - } - - ret = -1; - - if ((filename) && (path_len > strlen (filename))) { - strcpy (path, filename); - ret = strlen (filename); - } - -out: - if (free_conf_dir) - GF_FREE (conf_dir); - - if (free_filename) - GF_FREE (filename); - - return ret; -} - -static int -_validate_volfile_checksum (xlator_t *this, char *key, - uint32_t checksum) -{ - char filename[ZR_PATH_MAX] = {0,}; - server_conf_t *conf = NULL; - struct _volfile_ctx *temp_volfile = NULL; - int ret = 0; - uint32_t local_checksum = 0; - - conf = this->private; - temp_volfile = conf->volfile; - - if (!checksum) - goto out; - - if (!temp_volfile) { - ret = build_volfile_path (this, key, filename, - sizeof (filename)); - if (ret <= 0) - goto out; - ret = open (filename, O_RDONLY); - if (-1 == ret) { - ret = 0; - gf_log (this->name, GF_LOG_DEBUG, - "failed to open volume file (%s) : %s", - filename, strerror (errno)); - goto out; - } - get_checksum_for_file (ret, &local_checksum); - _volfile_update_checksum (this, key, local_checksum); - close (ret); - } - - temp_volfile = conf->volfile; - while (temp_volfile) { - if ((NULL == key) && (NULL == temp_volfile->key)) - break; - if ((NULL == key) || (NULL == temp_volfile->key)) { - temp_volfile = temp_volfile->next; - continue; - } - if (strcmp (temp_volfile->key, key) == 0) - break; - temp_volfile = temp_volfile->next; - } - - if (!temp_volfile) - goto out; - - if ((temp_volfile->checksum) && - (checksum != temp_volfile->checksum)) - ret = -1; - -out: - return ret; -} - -/* Management Calls */ -/* - * mop_getspec - getspec function for server protocol - * @frame: call frame - * @bound_xl: - * @params: - * - */ -static int -mop_getspec (call_frame_t *frame, xlator_t *bound_xl, - gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_hdr_common_t *_hdr = NULL; - gf_mop_getspec_rsp_t *rsp = NULL; - int32_t ret = -1; - int32_t op_errno = ENOENT; - int32_t gf_errno = 0; - int32_t spec_fd = -1; - size_t file_len = 0; - size_t _hdrlen = 0; - char filename[ZR_PATH_MAX] = {0,}; - struct stat stbuf = {0,}; - gf_mop_getspec_req_t *req = NULL; - uint32_t checksum = 0; - uint32_t flags = 0; - uint32_t keylen = 0; - char *key = NULL; - server_conf_t *conf = NULL; - - req = gf_param (hdr); - flags = ntoh32 (req->flags); - keylen = ntoh32 (req->keylen); - if (keylen) { - key = req->key; - } - - conf = frame->this->private; - - ret = build_volfile_path (frame->this, key, filename, - sizeof (filename)); - if (ret > 0) { - /* to allocate the proper buffer to hold the file data */ - ret = stat (filename, &stbuf); - if (ret < 0){ - gf_log (frame->this->name, GF_LOG_ERROR, - "Unable to stat %s (%s)", - filename, strerror (errno)); - goto fail; - } - - spec_fd = open (filename, O_RDONLY); - if (spec_fd < 0) { - gf_log (frame->this->name, GF_LOG_ERROR, - "Unable to open %s (%s)", - filename, strerror (errno)); - goto fail; - } - ret = 0; - file_len = stbuf.st_size; - if (conf->verify_volfile_checksum) { - get_checksum_for_file (spec_fd, &checksum); - _volfile_update_checksum (frame->this, key, checksum); - } - } else { - errno = ENOENT; - } - -fail: - op_errno = errno; - - _hdrlen = gf_hdr_len (rsp, file_len + 1); - _hdr = gf_hdr_new (rsp, file_len + 1); - rsp = gf_param (_hdr); - - _hdr->rsp.op_ret = hton32 (ret); - gf_errno = gf_errno_to_error (op_errno); - _hdr->rsp.op_errno = hton32 (gf_errno); - - if (file_len) { - ret = read (spec_fd, rsp->spec, file_len); - close (spec_fd); - } - protocol_server_reply (frame, GF_OP_TYPE_MOP_REPLY, GF_MOP_GETSPEC, - _hdr, _hdrlen, NULL, 0, NULL); - - return 0; -} - - - -static int -server_checksum (call_frame_t *frame, xlator_t *bound_xl, - gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_hdr_common_t *rsp_hdr = NULL; - gf_mop_ping_rsp_t *rsp = NULL; /* Using for NULL */ - size_t rsp_hdrlen = 0; - int32_t gf_errno = 0; - - rsp_hdrlen = gf_hdr_len (rsp, 0); - rsp_hdr = gf_hdr_new (rsp, 0); - - gf_errno = gf_errno_to_error (ENOSYS); - hdr->rsp.op_errno = hton32 (gf_errno); - hdr->rsp.op_ret = -1; - - protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_CHECKSUM, - rsp_hdr, rsp_hdrlen, NULL, 0, NULL); - - return 0; -} - - -static int -server_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) -{ - gf_hdr_common_t *hdr = NULL; - gf_fop_rchecksum_rsp_t *rsp = NULL; - size_t hdrlen = 0; - int32_t gf_errno = 0; - - hdrlen = gf_hdr_len (rsp, MD5_DIGEST_LEN + 1); - hdr = gf_hdr_new (rsp, MD5_DIGEST_LEN + 1); - rsp = gf_param (hdr); - - hdr->rsp.op_ret = hton32 (op_ret); - gf_errno = gf_errno_to_error (op_errno); - hdr->rsp.op_errno = hton32 (gf_errno); - - if (op_ret >= 0) { - rsp->weak_checksum = weak_checksum; - - memcpy (rsp->strong_checksum, - strong_checksum, MD5_DIGEST_LEN); - - rsp->strong_checksum[MD5_DIGEST_LEN] = '\0'; - } - - protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_RCHECKSUM, - hdr, hdrlen, NULL, 0, NULL); - - return 0; -} - -static int -server_rchecksum_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; - } - - STACK_WIND (frame, server_rchecksum_cbk, - bound_xl, - bound_xl->fops->rchecksum, - state->fd, state->offset, state->size); - - return 0; -err: - server_rchecksum_cbk (frame, NULL, frame->this, -1, EINVAL, 0, NULL); - - return 0; - -} - -static int -server_rchecksum (call_frame_t *frame, xlator_t *bound_xl, - gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_fop_rchecksum_req_t *req = NULL; - server_state_t *state = NULL; - server_connection_t *conn = NULL; - - conn = SERVER_CONNECTION(frame); - - req = gf_param (hdr); - - state = CALL_STATE(frame); - - state->resolve.type = RESOLVE_MAY; - state->resolve.fd_no = ntoh64 (req->fd); - state->offset = ntoh64 (req->offset); - state->size = ntoh32 (req->len); - - gf_resolve_and_resume (frame, server_rchecksum_resume); - - return 0; -} - - -/* - * mop_unlock - unlock management function for server protocol - * @frame: call frame - * @bound_xl: - * @params: parameter dictionary - * - */ -static int -mop_getvolume (call_frame_t *frame, xlator_t *bound_xl, - gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - return 0; -} - -struct __get_xl_struct { - const char *name; - xlator_t *reply; -}; - -static void __check_and_set (xlator_t *each, void *data) -{ - if (!strcmp (each->name, - ((struct __get_xl_struct *) data)->name)) - ((struct __get_xl_struct *) data)->reply = each; -} - -static xlator_t * -get_xlator_by_name (xlator_t *some_xl, const char *name) -{ - struct __get_xl_struct get = { - .name = name, - .reply = NULL - }; - - xlator_foreach (some_xl, __check_and_set, &get); - - return get.reply; -} - - -/* - * mop_setvolume - setvolume management function for server protocol - * @frame: call frame - * @bound_xl: - * @params: parameter dictionary - * - */ -static int -mop_setvolume (call_frame_t *frame, xlator_t *bound_xl, - gf_hdr_common_t *req_hdr, size_t req_hdrlen, - struct iobuf *iobuf) -{ - server_connection_t *conn = NULL; - server_conf_t *conf = NULL; - gf_hdr_common_t *rsp_hdr = NULL; - gf_mop_setvolume_req_t *req = NULL; - gf_mop_setvolume_rsp_t *rsp = NULL; - peer_info_t *peerinfo = NULL; - int32_t ret = -1; - int32_t op_ret = -1; - int32_t op_errno = EINVAL; - int32_t gf_errno = 0; - dict_t *reply = NULL; - dict_t *config_params = NULL; - dict_t *params = NULL; - char *name = NULL; - char *version = NULL; - char *process_uuid = NULL; - xlator_t *xl = NULL; - transport_t *trans = NULL; - size_t rsp_hdrlen = -1; - size_t dict_len = -1; - size_t req_dictlen = -1; - char *msg = NULL; - char *volfile_key = NULL; - uint32_t checksum = 0; - int32_t lru_limit = 1024; - - params = dict_new (); - reply = dict_new (); - - req = gf_param (req_hdr); - req_dictlen = ntoh32 (req->dict_len); - ret = dict_unserialize (req->buf, req_dictlen, ¶ms); - - config_params = dict_copy_with_ref (frame->this->options, NULL); - trans = TRANSPORT_FROM_FRAME(frame); - conf = SERVER_CONF(frame); - - if (ret < 0) { - ret = dict_set_str (reply, "ERROR", - "Internal error: failed to unserialize " - "request dictionary"); - if (ret < 0) - gf_log (bound_xl->name, GF_LOG_DEBUG, - "failed to set error msg \"%s\"", - "Internal error: failed to unserialize " - "request dictionary"); - - op_ret = -1; - op_errno = EINVAL; - goto fail; - } - - ret = dict_get_str (params, "process-uuid", &process_uuid); - if (ret < 0) { - ret = dict_set_str (reply, "ERROR", - "UUID not specified"); - if (ret < 0) - gf_log (bound_xl->name, GF_LOG_DEBUG, - "failed to set error msg"); - - op_ret = -1; - op_errno = EINVAL; - goto fail; - } - - - conn = gf_server_connection_get (frame->this, process_uuid); - if (trans->xl_private != conn) - trans->xl_private = conn; - - ret = dict_get_str (params, "protocol-version", &version); - if (ret < 0) { - ret = dict_set_str (reply, "ERROR", - "No version number specified"); - if (ret < 0) - gf_log (trans->xl->name, GF_LOG_DEBUG, - "failed to set error msg"); - - op_ret = -1; - op_errno = EINVAL; - goto fail; - } - - ret = strcmp (version, GF_PROTOCOL_VERSION); - if (ret != 0) { - ret = gf_asprintf (&msg, "protocol version mismatch: client(%s) " - "- server(%s)", version, GF_PROTOCOL_VERSION); - if (-1 == ret) { - gf_log (trans->xl->name, GF_LOG_ERROR, - "gf_asprintf failed while setting up error msg"); - goto fail; - } - ret = dict_set_dynstr (reply, "ERROR", msg); - if (ret < 0) - gf_log (trans->xl->name, GF_LOG_DEBUG, - "failed to set error msg"); - - op_ret = -1; - op_errno = EINVAL; - goto fail; - } - - ret = dict_get_str (params, - "remote-subvolume", &name); - if (ret < 0) { - ret = dict_set_str (reply, "ERROR", - "No remote-subvolume option specified"); - if (ret < 0) - gf_log (trans->xl->name, GF_LOG_DEBUG, - "failed to set error msg"); - - op_ret = -1; - op_errno = EINVAL; - goto fail; - } - - xl = get_xlator_by_name (frame->this, name); - if (xl == NULL) { - ret = gf_asprintf (&msg, "remote-subvolume \"%s\" is not found", - name); - if (-1 == ret) { - gf_log (trans->xl->name, GF_LOG_ERROR, - "gf_asprintf failed while setting error msg"); - goto fail; - } - ret = dict_set_dynstr (reply, "ERROR", msg); - if (ret < 0) - gf_log (trans->xl->name, GF_LOG_DEBUG, - "failed to set error msg"); - - op_ret = -1; - op_errno = ENOENT; - goto fail; - } - - if (conf->verify_volfile_checksum) { - ret = dict_get_uint32 (params, "volfile-checksum", &checksum); - if (ret == 0) { - ret = dict_get_str (params, "volfile-key", - &volfile_key); - - ret = _validate_volfile_checksum (trans->xl, - volfile_key, - checksum); - if (-1 == ret) { - ret = dict_set_str (reply, "ERROR", - "volume-file checksum " - "varies from earlier " - "access"); - if (ret < 0) - gf_log (trans->xl->name, GF_LOG_DEBUG, - "failed to set error msg"); - - op_ret = -1; - op_errno = ESTALE; - goto fail; - } - } - } - - - peerinfo = &trans->peerinfo; - ret = dict_set_static_ptr (params, "peer-info", peerinfo); - if (ret < 0) - gf_log (trans->xl->name, GF_LOG_DEBUG, - "failed to set peer-info"); - ret = dict_set_str (params, "peer-info-name", peerinfo->identifier); - if (ret < 0) - gf_log (trans->xl->name, GF_LOG_DEBUG, - "failed to set peer-info-name"); - - if (conf->auth_modules == NULL) { - gf_log (trans->xl->name, GF_LOG_ERROR, - "Authentication module not initialized"); - } - - ret = gf_authenticate (params, config_params, - conf->auth_modules); - if (ret == AUTH_ACCEPT) { - gf_log (trans->xl->name, GF_LOG_INFO, - "accepted client from %s", - peerinfo->identifier); - op_ret = 0; - conn->bound_xl = xl; - ret = dict_set_str (reply, "ERROR", "Success"); - if (ret < 0) - gf_log (trans->xl->name, GF_LOG_DEBUG, - "failed to set error msg"); - } else { - gf_log (trans->xl->name, GF_LOG_ERROR, - "Cannot authenticate client from %s", - peerinfo->identifier); - op_ret = -1; - op_errno = EACCES; - ret = dict_set_str (reply, "ERROR", "Authentication failed"); - if (ret < 0) - gf_log (bound_xl->name, GF_LOG_DEBUG, - "failed to set error msg"); - - goto fail; - } - - if (conn->bound_xl == NULL) { - ret = dict_set_str (reply, "ERROR", - "Check volfile and handshake " - "options in protocol/client"); - if (ret < 0) - gf_log (trans->xl->name, GF_LOG_DEBUG, - "failed to set error msg"); - - op_ret = -1; - op_errno = EACCES; - goto fail; - } - - if ((conn->bound_xl != NULL) && - (ret >= 0) && - (conn->bound_xl->itable == NULL)) { - /* create inode table for this bound_xl, if one doesn't - already exist */ - lru_limit = INODE_LRU_LIMIT (frame->this); - - gf_log (trans->xl->name, GF_LOG_TRACE, - "creating inode table with lru_limit=%"PRId32", " - "xlator=%s", lru_limit, conn->bound_xl->name); - - conn->bound_xl->itable = - inode_table_new (lru_limit, - conn->bound_xl); - } - - ret = dict_set_str (reply, "process-uuid", - xl->ctx->process_uuid); - - ret = dict_set_uint64 (reply, "transport-ptr", - ((uint64_t) (long) trans)); - -fail: - dict_len = dict_serialized_length (reply); - if (dict_len < 0) { - gf_log ("server", GF_LOG_DEBUG, - "failed to get serialized length of reply dict"); - op_ret = -1; - op_errno = EINVAL; - dict_len = 0; - } - - rsp_hdr = gf_hdr_new (rsp, dict_len); - rsp_hdrlen = gf_hdr_len (rsp, dict_len); - rsp = gf_param (rsp_hdr); - - if (dict_len) { - ret = dict_serialize (reply, rsp->buf); - if (ret < 0) { - gf_log ("server", GF_LOG_DEBUG, - "failed to serialize reply dict"); - op_ret = -1; - op_errno = -ret; - } - } - rsp->dict_len = hton32 (dict_len); - - rsp_hdr->rsp.op_ret = hton32 (op_ret); - gf_errno = gf_errno_to_error (op_errno); - rsp_hdr->rsp.op_errno = hton32 (gf_errno); - - protocol_server_reply (frame, GF_OP_TYPE_MOP_REPLY, GF_MOP_SETVOLUME, - rsp_hdr, rsp_hdrlen, NULL, 0, NULL); - - dict_unref (params); - dict_unref (reply); - dict_unref (config_params); - - return 0; -} - - -static int -mop_ping (call_frame_t *frame, xlator_t *bound_xl, - gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_hdr_common_t *rsp_hdr = NULL; - gf_mop_ping_rsp_t *rsp = NULL; - size_t rsp_hdrlen = 0; - - rsp_hdrlen = gf_hdr_len (rsp, 0); - rsp_hdr = gf_hdr_new (rsp, 0); - - hdr->rsp.op_ret = 0; - - protocol_server_reply (frame, GF_OP_TYPE_MOP_REPLY, GF_MOP_PING, - rsp_hdr, rsp_hdrlen, NULL, 0, NULL); - - return 0; -} - - -static int -mop_log (call_frame_t *frame, xlator_t *bound_xl, - gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_mop_log_req_t * req = NULL; - char * msg = NULL; - uint32_t msglen = 0; - - transport_t * trans = NULL; - - trans = TRANSPORT_FROM_FRAME (frame); - - req = gf_param (hdr); - msglen = ntoh32 (req->msglen); - - if (msglen) - msg = req->msg; - - gf_log_from_client (msg, trans->peerinfo.identifier); - - return 0; -} - - -/* ENOSYS operations (for backword compatibility) */ -static int -server_setdents (call_frame_t *frame, xlator_t *bound_xl, - gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_hdr_common_t *rsp_hdr = NULL; - gf_mop_ping_rsp_t *rsp = NULL; /* Using for NULL */ - size_t rsp_hdrlen = 0; - int32_t gf_errno = 0; - - rsp_hdrlen = gf_hdr_len (rsp, 0); - rsp_hdr = gf_hdr_new (rsp, 0); - - gf_errno = gf_errno_to_error (ENOSYS); - hdr->rsp.op_errno = hton32 (gf_errno); - hdr->rsp.op_ret = -1; - - protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_SETDENTS, - rsp_hdr, rsp_hdrlen, NULL, 0, NULL); - - return 0; -} - -/* */ -static int -server_getdents (call_frame_t *frame, xlator_t *bound_xl, - gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_hdr_common_t *rsp_hdr = NULL; - gf_mop_ping_rsp_t *rsp = NULL; /* Using for NULL */ - size_t rsp_hdrlen = 0; - int32_t gf_errno = 0; - - rsp_hdrlen = gf_hdr_len (rsp, 0); - rsp_hdr = gf_hdr_new (rsp, 0); - - gf_errno = gf_errno_to_error (ENOSYS); - hdr->rsp.op_errno = hton32 (gf_errno); - hdr->rsp.op_ret = -1; - - protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_GETDENTS, - rsp_hdr, rsp_hdrlen, NULL, 0, NULL); - - return 0; -} - -/* */ -static int -server_lock_notify (call_frame_t *frame, xlator_t *bound_xl, - gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_hdr_common_t *rsp_hdr = NULL; - gf_mop_ping_rsp_t *rsp = NULL; /* Using for NULL */ - size_t rsp_hdrlen = 0; - int32_t gf_errno = 0; - - rsp_hdrlen = gf_hdr_len (rsp, 0); - rsp_hdr = gf_hdr_new (rsp, 0); - - gf_errno = gf_errno_to_error (ENOSYS); - hdr->rsp.op_errno = hton32 (gf_errno); - hdr->rsp.op_ret = -1; - - protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_LOCK_NOTIFY, - rsp_hdr, rsp_hdrlen, NULL, 0, NULL); - - return 0; -} - -/* */ -static int -server_lock_fnotify (call_frame_t *frame, xlator_t *bound_xl, - gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_hdr_common_t *rsp_hdr = NULL; - gf_mop_ping_rsp_t *rsp = NULL; /* Using for NULL */ - size_t rsp_hdrlen = 0; - int32_t gf_errno = 0; - - rsp_hdrlen = gf_hdr_len (rsp, 0); - rsp_hdr = gf_hdr_new (rsp, 0); - - gf_errno = gf_errno_to_error (ENOSYS); - hdr->rsp.op_errno = hton32 (gf_errno); - hdr->rsp.op_ret = -1; - - protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_LOCK_FNOTIFY, - rsp_hdr, rsp_hdrlen, NULL, 0, NULL); - - return 0; -} - - -static int -mop_stats (call_frame_t *frame, xlator_t *bound_xl, - gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf) -{ - gf_hdr_common_t *rsp_hdr = NULL; - gf_mop_ping_rsp_t *rsp = NULL; /* Using for NULL */ - size_t rsp_hdrlen = 0; - int32_t gf_errno = 0; - - rsp_hdrlen = gf_hdr_len (rsp, 0); - rsp_hdr = gf_hdr_new (rsp, 0); - - gf_errno = gf_errno_to_error (ENOSYS); - hdr->rsp.op_errno = hton32 (gf_errno); - hdr->rsp.op_ret = -1; - - protocol_server_reply (frame, GF_OP_TYPE_MOP_REPLY, GF_MOP_STATS, - rsp_hdr, rsp_hdrlen, NULL, 0, NULL); - - return 0; -} - - -/* - * get_frame_for_transport - get call frame for specified transport object - * - * @trans: transport object - * - */ -static call_frame_t * -get_frame_for_transport (transport_t *trans) -{ - call_frame_t *frame = NULL; - call_pool_t *pool = NULL; - server_connection_t *conn = NULL; - server_state_t *state = NULL;; - - GF_VALIDATE_OR_GOTO("server", trans, out); - - if (trans->xl && trans->xl->ctx) - pool = trans->xl->ctx->pool; - GF_VALIDATE_OR_GOTO("server", pool, out); - - frame = create_frame (trans->xl, pool); - GF_VALIDATE_OR_GOTO("server", frame, out); - - state = GF_CALLOC (1, sizeof (*state), - gf_server_mt_server_state_t); - GF_VALIDATE_OR_GOTO("server", state, out); - - conn = trans->xl_private; - if (conn) { - if (conn->bound_xl) - state->itable = conn->bound_xl->itable; - state->bound_xl = conn->bound_xl; - } - - state->trans = transport_ref (trans); - state->resolve.fd_no = -1; - state->resolve2.fd_no = -1; - - frame->root->trans = conn; - frame->root->state = state; /* which socket */ - frame->root->unique = 0; /* which call */ - -out: - return frame; -} - - -static int -server_decode_groups (call_frame_t *frame, gf_hdr_common_t *hdr) -{ - int i = 0; - - if ((!frame) || (!hdr)) - return 0; - - frame->root->ngrps = ntoh32 (hdr->req.ngrps); - if (frame->root->ngrps == 0) - return 0; - - if (frame->root->ngrps > GF_REQUEST_MAXGROUPS) - return -1; - - for (; i < frame->root->ngrps; ++i) - frame->root->groups[i] = ntoh32 (hdr->req.groups[i]); - - return 0; -} - - -/* - * get_frame_for_call - create a frame into the capable of - * generating and replying the reply packet by itself. - * By making a call with this frame, the last UNWIND - * function will have all needed state from its - * frame_t->root to send reply. - * @trans: - * @blk: - * @params: - * - * not for external reference - */ -static call_frame_t * -get_frame_for_call (transport_t *trans, gf_hdr_common_t *hdr) -{ - call_frame_t *frame = NULL; - int32_t ret = -1; - - frame = get_frame_for_transport (trans); - - frame->root->op = ntoh32 (hdr->op); - frame->root->type = ntoh32 (hdr->type); - - frame->root->uid = ntoh32 (hdr->req.uid); - frame->root->unique = ntoh64 (hdr->callid); /* which call */ - frame->root->gid = ntoh32 (hdr->req.gid); - frame->root->pid = ntoh32 (hdr->req.pid); - frame->root->lk_owner = ntoh64 (hdr->req.lk_owner); - ret = server_decode_groups (frame, hdr); - - if (ret) { - //FRAME_DESTROY (frame); - return NULL; - } - - return frame; -} - -/* - * prototype of operations function for each of mop and - * fop at server protocol level - * - * @frame: call frame pointer - * @bound_xl: the xlator that this frame is bound to - * @params: parameters dictionary - * - * to be used by protocol interpret, _not_ for exterenal reference - */ -typedef int32_t (*gf_op_t) (call_frame_t *frame, xlator_t *bould_xl, - gf_hdr_common_t *hdr, size_t hdrlen, - struct iobuf *iobuf); - - -static gf_op_t gf_fops[] = { - [GF_PROTO_FOP_STAT] = server_stat, - [GF_PROTO_FOP_READLINK] = server_readlink, - [GF_PROTO_FOP_MKNOD] = server_mknod, - [GF_PROTO_FOP_MKDIR] = server_mkdir, - [GF_PROTO_FOP_UNLINK] = server_unlink, - [GF_PROTO_FOP_RMDIR] = server_rmdir, - [GF_PROTO_FOP_SYMLINK] = server_symlink, - [GF_PROTO_FOP_RENAME] = server_rename, - [GF_PROTO_FOP_LINK] = server_link, - [GF_PROTO_FOP_TRUNCATE] = server_truncate, - [GF_PROTO_FOP_OPEN] = server_open, - [GF_PROTO_FOP_READ] = server_readv, - [GF_PROTO_FOP_WRITE] = server_writev, - [GF_PROTO_FOP_STATFS] = server_statfs, - [GF_PROTO_FOP_FLUSH] = server_flush, - [GF_PROTO_FOP_FSYNC] = server_fsync, - [GF_PROTO_FOP_SETXATTR] = server_setxattr, - [GF_PROTO_FOP_GETXATTR] = server_getxattr, - [GF_PROTO_FOP_FGETXATTR] = server_fgetxattr, - [GF_PROTO_FOP_FSETXATTR] = server_fsetxattr, - [GF_PROTO_FOP_REMOVEXATTR] = server_removexattr, - [GF_PROTO_FOP_OPENDIR] = server_opendir, - [GF_PROTO_FOP_FSYNCDIR] = server_fsyncdir, - [GF_PROTO_FOP_ACCESS] = server_access, - [GF_PROTO_FOP_CREATE] = server_create, - [GF_PROTO_FOP_FTRUNCATE] = server_ftruncate, - [GF_PROTO_FOP_FSTAT] = server_fstat, - [GF_PROTO_FOP_LK] = server_lk, - [GF_PROTO_FOP_LOOKUP] = server_lookup, - [GF_PROTO_FOP_READDIR] = server_readdir, - [GF_PROTO_FOP_READDIRP] = server_readdirp, - [GF_PROTO_FOP_INODELK] = server_inodelk, - [GF_PROTO_FOP_FINODELK] = server_finodelk, - [GF_PROTO_FOP_ENTRYLK] = server_entrylk, - [GF_PROTO_FOP_FENTRYLK] = server_fentrylk, - [GF_PROTO_FOP_CHECKSUM] = server_checksum, - [GF_PROTO_FOP_RCHECKSUM] = server_rchecksum, - [GF_PROTO_FOP_XATTROP] = server_xattrop, - [GF_PROTO_FOP_FXATTROP] = server_fxattrop, - [GF_PROTO_FOP_SETATTR] = server_setattr, - [GF_PROTO_FOP_FSETATTR] = server_fsetattr, - [GF_PROTO_FOP_SETDENTS] = server_setdents, - [GF_PROTO_FOP_GETDENTS] = server_getdents, - [GF_PROTO_FOP_LOCK_NOTIFY] = server_lock_notify, - [GF_PROTO_FOP_LOCK_FNOTIFY] = server_lock_fnotify, -}; - - - -static gf_op_t gf_mops[] = { - [GF_MOP_SETVOLUME] = mop_setvolume, - [GF_MOP_GETVOLUME] = mop_getvolume, - [GF_MOP_GETSPEC] = mop_getspec, - [GF_MOP_PING] = mop_ping, - [GF_MOP_LOG] = mop_log, - [GF_MOP_STATS] = mop_stats, -}; - -static gf_op_t gf_cbks[] = { - [GF_CBK_FORGET] = server_forget, - [GF_CBK_RELEASE] = server_release, - [GF_CBK_RELEASEDIR] = server_releasedir -}; - -static int -protocol_server_interpret (xlator_t *this, transport_t *trans, - char *hdr_p, size_t hdrlen, struct iobuf *iobuf) -{ - server_connection_t *conn = NULL; - gf_hdr_common_t *hdr = NULL; - xlator_t *bound_xl = NULL; - call_frame_t *frame = NULL; - peer_info_t *peerinfo = NULL; - int32_t type = -1; - int32_t op = -1; - int32_t ret = -1; - - hdr = (gf_hdr_common_t *)hdr_p; - type = ntoh32 (hdr->type); - op = ntoh32 (hdr->op); - - conn = trans->xl_private; - if (conn) - bound_xl = conn->bound_xl; - - peerinfo = &trans->peerinfo; - switch (type) { - case GF_OP_TYPE_FOP_REQUEST: - if ((op < 0) || (op >= GF_PROTO_FOP_MAXVALUE)) { - gf_log (this->name, GF_LOG_ERROR, - "invalid fop %"PRId32" from client %s", - op, peerinfo->identifier); - break; - } - if (bound_xl == NULL) { - gf_log (this->name, GF_LOG_ERROR, - "Received fop %"PRId32" before " - "authentication.", op); - break; - } - frame = get_frame_for_call (trans, hdr); - if (!frame) { - ret = -1; - goto out; - } - frame->op = op; - ret = gf_fops[op] (frame, bound_xl, hdr, hdrlen, iobuf); - break; - - case GF_OP_TYPE_MOP_REQUEST: - if ((op < 0) || (op >= GF_MOP_MAXVALUE)) { - gf_log (this->name, GF_LOG_ERROR, - "invalid mop %"PRId32" from client %s", - op, peerinfo->identifier); - break; - } - frame = get_frame_for_call (trans, hdr); - if (!frame) { - ret = -1; - goto out; - } - frame->op = op; - ret = gf_mops[op] (frame, bound_xl, hdr, hdrlen, iobuf); - break; - - case GF_OP_TYPE_CBK_REQUEST: - if ((op < 0) || (op >= GF_CBK_MAXVALUE)) { - gf_log (this->name, GF_LOG_ERROR, - "invalid cbk %"PRId32" from client %s", - op, peerinfo->identifier); - break; - } - if (bound_xl == NULL) { - gf_log (this->name, GF_LOG_ERROR, - "Received cbk %d before authentication.", op); - break; - } - - frame = get_frame_for_call (trans, hdr); - if (!frame) { - ret = -1; - goto out; - } - ret = gf_cbks[op] (frame, bound_xl, hdr, hdrlen, iobuf); - break; - - default: - break; - } -out: - return ret; -} - - -/* - * server_fd - fdtable dump function for server protocol - * @this: - * - */ -static int -server_fd (xlator_t *this) -{ - server_conf_t *conf = NULL; - server_connection_t *trav = NULL; - char key[GF_DUMP_MAX_BUF_LEN]; - int i = 1; - int ret = -1; - - if (!this) - return -1; - - conf = this->private; - if (!conf) { - gf_log (this->name, GF_LOG_WARNING, - "conf null in xlator"); - return -1; - } - - gf_proc_dump_add_section("xlator.protocol.server.conn"); - - ret = pthread_mutex_trylock (&conf->mutex); - if (ret) { - gf_log("", GF_LOG_WARNING, "Unable to dump fdtable" - " errno: %d", errno); - return -1; - } - - list_for_each_entry (trav, &conf->conns, list) { - if (trav->id) { - gf_proc_dump_build_key(key, - "xlator.protocol.server.conn", - "%d.id", i); - gf_proc_dump_write(key, "%s", trav->id); - } - - gf_proc_dump_build_key(key,"xlator.protocol.server.conn", - "%d.ref",i) - gf_proc_dump_write(key, "%d", trav->ref); - if (trav->bound_xl) { - gf_proc_dump_build_key(key, - "xlator.protocol.server.conn", - "%d.bound_xl", i); - gf_proc_dump_write(key, "%s", trav->bound_xl->name); - } - - gf_proc_dump_build_key(key, - "xlator.protocol.server.conn", - "%d.id", i); - fdtable_dump(trav->fdtable,key); - i++; - } - pthread_mutex_unlock (&conf->mutex); - - - return 0; - } - -static int -server_priv (xlator_t *this) -{ - return 0; -} - -static int -server_inode (xlator_t *this) -{ - server_conf_t *conf = NULL; - server_connection_t *trav = NULL; - char key[GF_DUMP_MAX_BUF_LEN]; - int i = 1; - int ret = -1; - - if (!this) - return -1; - - conf = this->private; - if (!conf) { - gf_log (this->name, GF_LOG_WARNING, - "conf null in xlator"); - return -1; - } - - ret = pthread_mutex_trylock (&conf->mutex); - if (ret) { - gf_log("", GF_LOG_WARNING, "Unable to dump itable" - " errno: %d", errno); - return -1; - } - - list_for_each_entry (trav, &conf->conns, list) { - if (trav->bound_xl && trav->bound_xl->itable) { - gf_proc_dump_build_key(key, - "xlator.protocol.server.conn", - "%d.bound_xl.%s", - i, trav->bound_xl->name); - inode_table_dump(trav->bound_xl->itable,key); - i++; - } - } - pthread_mutex_unlock (&conf->mutex); - - - return 0; -} - - -static void -get_auth_types (dict_t *this, char *key, data_t *value, void *data) -{ - dict_t *auth_dict = NULL; - char *saveptr = NULL; - char *tmp = NULL; - char *key_cpy = NULL; - int32_t ret = -1; - - auth_dict = data; - key_cpy = gf_strdup (key); - GF_VALIDATE_OR_GOTO("server", key_cpy, out); - - tmp = strtok_r (key_cpy, ".", &saveptr); - ret = strcmp (tmp, "auth"); - if (ret == 0) { - tmp = strtok_r (NULL, ".", &saveptr); - if (strcmp (tmp, "ip") == 0) { - /* TODO: backward compatibility, remove when - newer versions are available */ - tmp = "addr"; - gf_log ("server", GF_LOG_WARNING, - "assuming 'auth.ip' to be 'auth.addr'"); - } - ret = dict_set_dynptr (auth_dict, tmp, NULL, 0); - if (ret < 0) { - gf_log ("server", GF_LOG_DEBUG, - "failed to dict_set_dynptr"); - } - } - - GF_FREE (key_cpy); -out: - return; -} - - -static int -validate_auth_options (xlator_t *this, dict_t *dict) -{ - int ret = -1; - int error = 0; - xlator_list_t *trav = NULL; - data_pair_t *pair = NULL; - char *saveptr = NULL; - char *tmp = NULL; - char *key_cpy = NULL; - - trav = this->children; - while (trav) { - error = -1; - for (pair = dict->members_list; pair; pair = pair->next) { - key_cpy = gf_strdup (pair->key); - tmp = strtok_r (key_cpy, ".", &saveptr); - ret = strcmp (tmp, "auth"); - if (ret == 0) { - /* for module type */ - tmp = strtok_r (NULL, ".", &saveptr); - /* for volume name */ - tmp = strtok_r (NULL, ".", &saveptr); - } - - if (strcmp (tmp, trav->xlator->name) == 0) { - error = 0; - GF_FREE (key_cpy); - break; - } - GF_FREE (key_cpy); - } - if (-1 == error) { - gf_log (this->name, GF_LOG_ERROR, - "volume '%s' defined as subvolume, but no " - "authentication defined for the same", - trav->xlator->name); - break; - } - trav = trav->next; - } - - return error; -} - -int32_t -mem_acct_init (xlator_t *this) -{ - int ret = -1; - - if (!this) - return ret; - - ret = xlator_mem_acct_init (this, gf_server_mt_end + 1); - - if (ret != 0) { - gf_log (this->name, GF_LOG_ERROR, "Memory accounting init" - " failed"); - return ret; - } - - return ret; -} - - -/* - * init - called during server protocol initialization - * - * @this: - * - */ -int -init (xlator_t *this) -{ - int32_t ret = -1; - transport_t *trans = NULL; - server_conf_t *conf = NULL; - data_t *data = NULL; - data_t *trace = NULL; - - if (this->children == NULL) { - gf_log (this->name, GF_LOG_ERROR, - "protocol/server should have subvolume"); - goto out; - } - - trans = transport_load (this->options, this); - if (trans == NULL) { - gf_log (this->name, GF_LOG_ERROR, - "failed to load transport"); - goto out; - } - - ret = transport_listen (trans); - if (ret == -1) { - gf_log (this->name, GF_LOG_ERROR, - "failed to bind/listen on socket"); - goto out; - } - - conf = GF_CALLOC (1, sizeof (server_conf_t), - gf_server_mt_server_conf_t); - GF_VALIDATE_OR_GOTO(this->name, conf, out); - - INIT_LIST_HEAD (&conf->conns); - pthread_mutex_init (&conf->mutex, NULL); - - conf->trans = trans; - - conf->auth_modules = dict_new (); - GF_VALIDATE_OR_GOTO(this->name, conf->auth_modules, out); - - dict_foreach (this->options, get_auth_types, - conf->auth_modules); - ret = validate_auth_options (this, this->options); - if (ret == -1) { - /* logging already done in validate_auth_options function. */ - goto out; - } - - ret = gf_auth_init (this, conf->auth_modules); - if (ret) { - dict_unref (conf->auth_modules); - goto out; - } - - this->private = conf; - - ret = dict_get_int32 (this->options, "inode-lru-limit", - &conf->inode_lru_limit); - if (ret < 0) { - conf->inode_lru_limit = 1024; - } - - ret = dict_get_int32 (this->options, "limits.transaction-size", - &conf->max_block_size); - if (ret < 0) { - gf_log (this->name, GF_LOG_TRACE, - "defaulting limits.transaction-size to %d", - DEFAULT_BLOCK_SIZE); - conf->max_block_size = DEFAULT_BLOCK_SIZE; - } - - conf->verify_volfile_checksum = 1; - data = dict_get (this->options, "verify-volfile-checksum"); - if (data) { - ret = gf_string2boolean(data->data, - &conf->verify_volfile_checksum); - if (ret != 0) { - gf_log (this->name, GF_LOG_DEBUG, - "wrong value for verify-volfile-checksum"); - conf->verify_volfile_checksum = 1; - } - } - - trace = dict_get (this->options, "trace"); - if (trace) { - if (gf_string2boolean (trace->data, - &conf->trace) == -1) { - gf_log (this->name, GF_LOG_ERROR, - "'trace' takes on only boolean values."); - return -1; - } - } - -#ifndef GF_DARWIN_HOST_OS - { - struct rlimit lim; - - lim.rlim_cur = 1048576; - lim.rlim_max = 1048576; - - if (setrlimit (RLIMIT_NOFILE, &lim) == -1) { - gf_log (this->name, GF_LOG_WARNING, - "WARNING: Failed to set 'ulimit -n 1M': %s", - strerror(errno)); - lim.rlim_cur = 65536; - lim.rlim_max = 65536; - - if (setrlimit (RLIMIT_NOFILE, &lim) == -1) { - gf_log (this->name, GF_LOG_WARNING, - "Failed to set max open fd to 64k: %s", - strerror(errno)); - } else { - gf_log (this->name, GF_LOG_TRACE, - "max open fd set to 64k"); - } - } - } -#endif - this->graph->top = this; - - ret = 0; -out: - return ret; -} - - - -static int -protocol_server_pollin (xlator_t *this, transport_t *trans) -{ - char *hdr = NULL; - size_t hdrlen = 0; - int ret = -1; - struct iobuf *iobuf = NULL; - - - ret = transport_receive (trans, &hdr, &hdrlen, &iobuf); - - if (ret == 0) - ret = protocol_server_interpret (this, trans, hdr, - hdrlen, iobuf); - - /* TODO: use mem-pool */ - GF_FREE (hdr); - - return ret; -} - - -/* - * fini - finish function for server protocol, called before - * unloading server protocol. - * - * @this: - * - */ -void -fini (xlator_t *this) -{ - server_conf_t *conf = this->private; - - GF_VALIDATE_OR_GOTO(this->name, conf, out); - - if (conf->auth_modules) { - dict_unref (conf->auth_modules); - } - - GF_FREE (conf); - this->private = NULL; -out: - return; -} - -/* - * server_protocol_notify - notify function for server protocol - * @this: - * @trans: - * @event: - * - */ -int -notify (xlator_t *this, int32_t event, void *data, ...) -{ - int ret = 0; - transport_t *trans = NULL; - peer_info_t *peerinfo = NULL; - peer_info_t *myinfo = NULL; - - THIS = this; - trans = data; - if (!trans) { - gf_log (this->name, GF_LOG_ERROR, "!trans"); - goto out; - } - - peerinfo = &(trans->peerinfo); - myinfo = &(trans->myinfo); - - switch (event) { - case GF_EVENT_POLLIN: - ret = protocol_server_pollin (this, trans); - break; - case GF_EVENT_POLLERR: - { - gf_log (trans->xl->name, GF_LOG_INFO, "%s disconnected", - peerinfo->identifier); - - ret = -1; - transport_disconnect (trans); - if (trans->xl_private == NULL) { - gf_log (this->name, GF_LOG_DEBUG, - "POLLERR received on (%s) even before " - "handshake with (%s) is successful", - myinfo->identifier, peerinfo->identifier); - } else { - /* - * FIXME: shouldn't we check for return value? - * what should be done if cleanup fails? - */ - gf_server_connection_cleanup (this, trans->xl_private); - } - } - break; - - case GF_EVENT_TRANSPORT_CLEANUP: - { - if (trans->xl_private) { - gf_server_connection_put (this, trans->xl_private); - } else { - gf_log (this->name, GF_LOG_DEBUG, - "transport (%s) cleaned up even before " - "handshake with (%s) is successful", - myinfo->identifier, peerinfo->identifier); - } - } - break; - - default: - default_notify (this, event, data); - break; - } -out: - return ret; -} - - -struct xlator_fops fops = { -}; - -struct xlator_cbks cbks = { -}; - -struct xlator_dumpops dumpops = { - .inode = server_inode, - .priv = server_priv, - .fd = server_fd, -}; - - -struct volume_options options[] = { - { .key = {"transport-type"}, - .value = {"tcp", "socket", "ib-verbs", "unix", "ib-sdp", - "tcp/server", "ib-verbs/server"}, - .type = GF_OPTION_TYPE_STR - }, - { .key = {"volume-filename.*"}, - .type = GF_OPTION_TYPE_PATH, - }, - { .key = {"inode-lru-limit"}, - .type = GF_OPTION_TYPE_INT, - .min = 0, - .max = (1 * GF_UNIT_MB) - }, - { .key = {"client-volume-filename"}, - .type = GF_OPTION_TYPE_PATH - }, - { .key = {"verify-volfile-checksum"}, - .type = GF_OPTION_TYPE_BOOL - }, - { .key = {"trace"}, - .type = GF_OPTION_TYPE_BOOL - }, - { .key = {"conf-dir"}, - .type = GF_OPTION_TYPE_PATH, - }, - - { .key = {NULL} }, -}; diff --git a/xlators/protocol/legacy/server/src/server-protocol.h b/xlators/protocol/legacy/server/src/server-protocol.h deleted file mode 100644 index 13691287132..00000000000 --- a/xlators/protocol/legacy/server/src/server-protocol.h +++ /dev/null @@ -1,191 +0,0 @@ -/* - Copyright (c) 2006-2009 Gluster, Inc. <http://www.gluster.com> - This file is part of GlusterFS. - - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. -*/ - -#ifndef _SERVER_PROTOCOL_H_ -#define _SERVER_PROTOCOL_H_ - -#ifndef _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif - -#include <pthread.h> - -#include "glusterfs.h" -#include "xlator.h" -#include "logging.h" -#include "call-stub.h" -#include "fd.h" -#include "byte-order.h" -#include "server-mem-types.h" -#include "authenticate.h" -#include "transport.h" - -#define DEFAULT_BLOCK_SIZE 4194304 /* 4MB */ -#define DEFAULT_VOLUME_FILE_PATH CONFDIR "/glusterfs.vol" - -typedef struct _server_state server_state_t; - -struct _locker { - struct list_head lockers; - char *volume; - loc_t loc; - fd_t *fd; - pid_t pid; -}; - -struct _lock_table { - struct list_head file_lockers; - struct list_head dir_lockers; - gf_lock_t lock; - size_t count; -}; - - -/* private structure per connection (transport object) - * used as transport_t->xl_private - */ -struct _server_connection { - struct list_head list; - char *id; - int ref; - int active_transports; - pthread_mutex_t lock; - char disconnected; - fdtable_t *fdtable; - struct _lock_table *ltable; - xlator_t *bound_xl; -}; - -typedef struct _server_connection server_connection_t; - - -server_connection_t * -gf_server_connection_get (xlator_t *this, const char *id); - -void -gf_server_connection_put (xlator_t *this, server_connection_t *conn); - -int -gf_server_connection_cleanup (xlator_t *this, server_connection_t *conn); - -struct _volfile_ctx { - struct _volfile_ctx *next; - char *key; - uint32_t checksum; -}; - -typedef struct { - struct _volfile_ctx *volfile; - - dict_t *auth_modules; - transport_t *trans; - int32_t max_block_size; - int32_t inode_lru_limit; - pthread_mutex_t mutex; - struct list_head conns; - gf_boolean_t verify_volfile_checksum; - gf_boolean_t trace; -} server_conf_t; - - -typedef enum { - RESOLVE_MUST = 1, - RESOLVE_NOT, - RESOLVE_MAY, - RESOLVE_DONTCARE, - RESOLVE_EXACT -} server_resolve_type_t; - - -struct resolve_comp { - char *basename; - ino_t ino; - uint64_t gen; - inode_t *inode; -}; - -typedef struct { - server_resolve_type_t type; - uint64_t fd_no; - ino_t ino; - uint64_t gen; - ino_t par; - char *path; - char *bname; - char *resolved; - int op_ret; - int op_errno; - loc_t deep_loc; - struct resolve_comp *components; - int comp_count; -} server_resolve_t; - - -typedef int (*server_resume_fn_t) (call_frame_t *frame, xlator_t *bound_xl); - -int -gf_resolve_and_resume (call_frame_t *frame, server_resume_fn_t fn); - -struct _server_state { - transport_t *trans; - xlator_t *bound_xl; - inode_table_t *itable; - - server_resume_fn_t resume_fn; - - loc_t loc; - loc_t loc2; - server_resolve_t resolve; - server_resolve_t resolve2; - - /* used within resolve_and_resume */ - loc_t *loc_now; - server_resolve_t *resolve_now; - - struct iatt stbuf; - int valid; - - fd_t *fd; - dict_t *params; - int flags; - int wbflags; - struct iobuf *iobuf; - struct iobref *iobref; - - size_t size; - off_t offset; - mode_t mode; - dev_t dev; - size_t nr_count; - int cmd; - int type; - char *name; - int name_len; - - int mask; - char is_revalidate; - dict_t *dict; - struct flock flock; - const char *volume; - dir_entry_t *entry; -}; - - -#endif diff --git a/xlators/protocol/legacy/server/src/server-resolve.c b/xlators/protocol/legacy/server/src/server-resolve.c deleted file mode 100644 index f08ec1c060c..00000000000 --- a/xlators/protocol/legacy/server/src/server-resolve.c +++ /dev/null @@ -1,658 +0,0 @@ -/* - Copyright (c) 2009 Gluster, Inc. <http://www.gluster.com> - This file is part of GlusterFS. - - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. -*/ - -#ifndef _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif - -#include "server-protocol.h" -#include "server-helpers.h" - -#include "compat-errno.h" - -void -gf_server_print_request (call_frame_t *frame); - -static int -server_resolve_all (call_frame_t *frame); -static int -resolve_entry_simple (call_frame_t *frame); -static int -resolve_inode_simple (call_frame_t *frame); -static int -resolve_path_simple (call_frame_t *frame); - - -static int -component_count (const char *path) -{ - int count = 0; - const char *trav = NULL; - - trav = path; - - for (trav = path; *trav; trav++) { - if (*trav == '/') - count++; - } - - return count + 2; -} - - -static int -prepare_components (call_frame_t *frame) -{ - server_state_t *state = NULL; - xlator_t *this = NULL; - server_resolve_t *resolve = NULL; - char *resolved = NULL; - int count = 0; - struct resolve_comp *components = NULL; - int i = 0; - char *trav = NULL; - - - state = CALL_STATE (frame); - this = frame->this; - resolve = state->resolve_now; - - resolved = gf_strdup (resolve->path); - resolve->resolved = resolved; - - count = component_count (resolve->path); - components = GF_CALLOC (sizeof (*components), count, - gf_server_mt_resolve_comp); - resolve->components = components; - - components[0].basename = ""; - components[0].ino = 1; - components[0].gen = 0; - components[0].inode = state->itable->root; - - i = 1; - for (trav = resolved; *trav; trav++) { - if (*trav == '/') { - components[i].basename = trav + 1; - *trav = 0; - i++; - } - } - - return 0; -} - - -static int -resolve_loc_touchup (call_frame_t *frame) -{ - server_state_t *state = NULL; - server_resolve_t *resolve = NULL; - loc_t *loc = NULL; - char *path = NULL; - int ret = 0; - - state = CALL_STATE (frame); - - resolve = state->resolve_now; - loc = state->loc_now; - - if (!loc->path) { - if (loc->parent && resolve->bname) { - ret = inode_path (loc->parent, resolve->bname, &path); - } else if (loc->inode) { - ret = inode_path (loc->inode, NULL, &path); - } - - if (!path) - path = gf_strdup (resolve->path); - - loc->path = path; - } - - loc->name = strrchr (loc->path, '/'); - if (loc->name) - loc->name++; - - if (!loc->parent && loc->inode) { - loc->parent = inode_parent (loc->inode, 0, NULL); - } - - return 0; -} - - -static int -resolve_deep_continue (call_frame_t *frame) -{ - server_state_t *state = NULL; - xlator_t *this = NULL; - server_resolve_t *resolve = NULL; - int ret = 0; - - state = CALL_STATE (frame); - this = frame->this; - resolve = state->resolve_now; - - resolve->op_ret = 0; - resolve->op_errno = 0; - - if (resolve->par) - ret = resolve_entry_simple (frame); - else if (resolve->ino) - ret = resolve_inode_simple (frame); - else if (resolve->path) - ret = resolve_path_simple (frame); - - resolve_loc_touchup (frame); - - server_resolve_all (frame); - - return 0; -} - - -static int -resolve_deep_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int op_ret, int op_errno, inode_t *inode, struct iatt *buf, - dict_t *xattr, struct iatt *postparent) -{ - server_state_t *state = NULL; - server_resolve_t *resolve = NULL; - struct resolve_comp *components = NULL; - int i = 0; - inode_t *link_inode = NULL; - - state = CALL_STATE (frame); - resolve = state->resolve_now; - components = resolve->components; - - i = (long) cookie; - - if (op_ret == -1) { - goto get_out_of_here; - } - - if (i != 0) { - /* no linking for root inode */ - link_inode = inode_link (inode, resolve->deep_loc.parent, - resolve->deep_loc.name, buf); - inode_lookup (link_inode); - components[i].inode = link_inode; - link_inode = NULL; - } - - loc_wipe (&resolve->deep_loc); - - i++; /* next component */ - - if (!components[i].basename) { - /* all components of the path are resolved */ - goto get_out_of_here; - } - - /* join the current component with the path resolved until now */ - *(components[i].basename - 1) = '/'; - - resolve->deep_loc.path = gf_strdup (resolve->resolved); - resolve->deep_loc.parent = inode_ref (components[i-1].inode); - resolve->deep_loc.inode = inode_new (state->itable); - resolve->deep_loc.name = components[i].basename; - - STACK_WIND_COOKIE (frame, resolve_deep_cbk, (void *) (long) i, - BOUND_XL (frame), BOUND_XL (frame)->fops->lookup, - &resolve->deep_loc, NULL); - return 0; - -get_out_of_here: - resolve_deep_continue (frame); - return 0; -} - - -static int -resolve_path_deep (call_frame_t *frame) -{ - server_state_t *state = NULL; - xlator_t *this = NULL; - server_resolve_t *resolve = NULL; - int i = 0; - - state = CALL_STATE (frame); - this = frame->this; - resolve = state->resolve_now; - - gf_log (BOUND_XL (frame)->name, GF_LOG_DEBUG, - "RESOLVE %s() seeking deep resolution of %s", - gf_fop_list[frame->root->op], resolve->path); - - prepare_components (frame); - - /* start from the root */ - resolve->deep_loc.inode = state->itable->root; - resolve->deep_loc.path = gf_strdup ("/"); - resolve->deep_loc.name = ""; - - STACK_WIND_COOKIE (frame, resolve_deep_cbk, (void *) (long) i, - BOUND_XL (frame), BOUND_XL (frame)->fops->lookup, - &resolve->deep_loc, NULL); - return 0; -} - - -static int -resolve_path_simple (call_frame_t *frame) -{ - server_state_t *state = NULL; - xlator_t *this = NULL; - server_resolve_t *resolve = NULL; - struct resolve_comp *components = NULL; - int ret = -1; - int par_idx = 0; - int ino_idx = 0; - int i = 0; - - state = CALL_STATE (frame); - this = frame->this; - resolve = state->resolve_now; - components = resolve->components; - - if (!components) { - resolve->op_ret = -1; - resolve->op_errno = ENOENT; - goto out; - } - - for (i = 0; components[i].basename; i++) { - par_idx = ino_idx; - ino_idx = i; - } - - if (!components[par_idx].inode) { - resolve->op_ret = -1; - resolve->op_errno = ENOENT; - goto out; - } - - if (!components[ino_idx].inode && - (resolve->type == RESOLVE_MUST || resolve->type == RESOLVE_EXACT)) { - resolve->op_ret = -1; - resolve->op_errno = ENOENT; - goto out; - } - - if (components[ino_idx].inode && resolve->type == RESOLVE_NOT) { - resolve->op_ret = -1; - resolve->op_errno = EEXIST; - goto out; - } - - if (components[ino_idx].inode) - state->loc_now->inode = inode_ref (components[ino_idx].inode); - state->loc_now->parent = inode_ref (components[par_idx].inode); - - ret = 0; - -out: - return ret; -} - -/* - Check if the requirements are fulfilled by entries in the inode cache itself - Return value: - <= 0 - simple resolution was decisive and complete (either success or failure) - > 0 - indecisive, need to perform deep resolution -*/ - -static int -resolve_entry_simple (call_frame_t *frame) -{ - server_state_t *state = NULL; - xlator_t *this = NULL; - server_resolve_t *resolve = NULL; - inode_t *parent = NULL; - inode_t *inode = NULL; - int ret = 0; - - state = CALL_STATE (frame); - this = frame->this; - resolve = state->resolve_now; - - parent = inode_get (state->itable, resolve->par, 0); - if (!parent) { - /* simple resolution is indecisive. need to perform - deep resolution */ - resolve->op_ret = -1; - resolve->op_errno = ENOENT; - ret = 1; - - inode = inode_grep (state->itable, parent, resolve->bname); - if (inode != NULL) { - gf_log (this->name, GF_LOG_DEBUG, "%"PRId64": inode " - "(pointer:%p ino: %"PRIu64") present but parent" - " is NULL for path (%s)", frame->root->unique, - inode, inode->ino, resolve->path); - inode_unref (inode); - } - goto out; - } - -// if (parent->ino != 1 && parent->generation != resolve->gen) { - if (0) { - /* simple resolution is decisive - request was for a - stale handle */ - resolve->op_ret = -1; - resolve->op_errno = ENOENT; - ret = -1; - goto out; - } - - /* expected @parent was found from the inode cache */ - state->loc_now->parent = inode_ref (parent); - - inode = inode_grep (state->itable, parent, resolve->bname); - if (!inode) { - switch (resolve->type) { - case RESOLVE_DONTCARE: - case RESOLVE_NOT: - ret = 0; - break; - case RESOLVE_MAY: - ret = 1; - break; - default: - resolve->op_ret = -1; - resolve->op_errno = ENOENT; - ret = 1; - break; - } - - goto out; - } - - if (resolve->type == RESOLVE_NOT) { - gf_log (this->name, GF_LOG_DEBUG, "inode (pointer: %p ino:%" - PRIu64") found for path (%s) while type is RESOLVE_NOT", - inode, inode->ino, resolve->path); - resolve->op_ret = -1; - resolve->op_errno = EEXIST; - ret = -1; - goto out; - } - - ret = 0; - - state->loc_now->inode = inode_ref (inode); - -out: - if (parent) - inode_unref (parent); - - if (inode) - inode_unref (inode); - - return ret; -} - - -static int -server_resolve_entry (call_frame_t *frame) -{ - server_state_t *state = NULL; - xlator_t *this = NULL; - server_resolve_t *resolve = NULL; - int ret = 0; - loc_t *loc = NULL; - - state = CALL_STATE (frame); - this = frame->this; - resolve = state->resolve_now; - loc = state->loc_now; - - ret = resolve_entry_simple (frame); - - if (ret > 0) { - loc_wipe (loc); - resolve_path_deep (frame); - return 0; - } - - if (ret == 0) - resolve_loc_touchup (frame); - - server_resolve_all (frame); - - return 0; -} - - -static int -resolve_inode_simple (call_frame_t *frame) -{ - server_state_t *state = NULL; - xlator_t *this = NULL; - server_resolve_t *resolve = NULL; - inode_t *inode = NULL; - int ret = 0; - - state = CALL_STATE (frame); - this = frame->this; - resolve = state->resolve_now; - - if (resolve->type == RESOLVE_EXACT) { - inode = inode_get (state->itable, resolve->ino, resolve->gen); - } else { - inode = inode_get (state->itable, resolve->ino, 0); - } - - if (!inode) { - resolve->op_ret = -1; - resolve->op_errno = ENOENT; - ret = 1; - goto out; - } - -// if (inode->ino != 1 && inode->generation != resolve->gen) { - if (0) { - resolve->op_ret = -1; - resolve->op_errno = ENOENT; - ret = -1; - goto out; - } - - ret = 0; - - state->loc_now->inode = inode_ref (inode); - -out: - if (inode) - inode_unref (inode); - - return ret; -} - - -static int -server_resolve_inode (call_frame_t *frame) -{ - server_state_t *state = NULL; - int ret = 0; - loc_t *loc = NULL; - - state = CALL_STATE (frame); - loc = state->loc_now; - - ret = resolve_inode_simple (frame); - - if (ret > 0) { - loc_wipe (loc); - resolve_path_deep (frame); - return 0; - } - - if (ret == 0) - resolve_loc_touchup (frame); - - server_resolve_all (frame); - - return 0; -} - - -static int -server_resolve_fd (call_frame_t *frame) -{ - server_state_t *state = NULL; - xlator_t *this = NULL; - server_resolve_t *resolve = NULL; - server_connection_t *conn = NULL; - uint64_t fd_no = -1; - - state = CALL_STATE (frame); - this = frame->this; - resolve = state->resolve_now; - conn = SERVER_CONNECTION (frame); - - fd_no = resolve->fd_no; - - state->fd = gf_fd_fdptr_get (conn->fdtable, fd_no); - - if (!state->fd) { - resolve->op_ret = -1; - resolve->op_errno = EBADFD; - } - - server_resolve_all (frame); - - return 0; -} - - -static int -server_resolve (call_frame_t *frame) -{ - server_state_t *state = NULL; - xlator_t *this = NULL; - server_resolve_t *resolve = NULL; - - state = CALL_STATE (frame); - this = frame->this; - resolve = state->resolve_now; - - if (resolve->fd_no != -1) { - - server_resolve_fd (frame); - - } else if (resolve->par) { - - server_resolve_entry (frame); - - } else if (resolve->ino) { - - server_resolve_inode (frame); - - } else if (resolve->path) { - - resolve_path_deep (frame); - - } else { - - resolve->op_ret = -1; - resolve->op_errno = EINVAL; - - server_resolve_all (frame); - } - - return 0; -} - - -static int -server_resolve_done (call_frame_t *frame) -{ - server_state_t *state = NULL; - xlator_t *bound_xl = NULL; - - state = CALL_STATE (frame); - bound_xl = BOUND_XL (frame); - - gf_server_print_request (frame); - - state->resume_fn (frame, bound_xl); - - return 0; -} - - -/* - * This function is called multiple times, once per resolving one location/fd. - * state->resolve_now is used to decide which location/fd is to be resolved now - */ -static int -server_resolve_all (call_frame_t *frame) -{ - server_state_t *state = NULL; - xlator_t *this = NULL; - - this = frame->this; - state = CALL_STATE (frame); - - if (state->resolve_now == NULL) { - - state->resolve_now = &state->resolve; - state->loc_now = &state->loc; - - server_resolve (frame); - - } else if (state->resolve_now == &state->resolve) { - - state->resolve_now = &state->resolve2; - state->loc_now = &state->loc2; - - server_resolve (frame); - - } else if (state->resolve_now == &state->resolve2) { - - server_resolve_done (frame); - - } else { - gf_log (this->name, GF_LOG_ERROR, - "Invalid pointer for state->resolve_now"); - } - - return 0; -} - - -int -gf_resolve_and_resume (call_frame_t *frame, server_resume_fn_t fn) -{ - server_state_t *state = NULL; - xlator_t *this = NULL; - - state = CALL_STATE (frame); - state->resume_fn = fn; - - this = frame->this; - - server_resolve_all (frame); - - return 0; -} diff --git a/xlators/protocol/legacy/transport/Makefile.am b/xlators/protocol/legacy/transport/Makefile.am deleted file mode 100644 index e2f97437c12..00000000000 --- a/xlators/protocol/legacy/transport/Makefile.am +++ /dev/null @@ -1,3 +0,0 @@ -SUBDIRS = socket $(IBVERBS_SUBDIR) - -CLEANFILES = diff --git a/xlators/protocol/legacy/transport/ib-verbs/Makefile.am b/xlators/protocol/legacy/transport/ib-verbs/Makefile.am deleted file mode 100644 index f963effea22..00000000000 --- a/xlators/protocol/legacy/transport/ib-verbs/Makefile.am +++ /dev/null @@ -1 +0,0 @@ -SUBDIRS = src
\ No newline at end of file diff --git a/xlators/protocol/legacy/transport/ib-verbs/src/Makefile.am b/xlators/protocol/legacy/transport/ib-verbs/src/Makefile.am deleted file mode 100644 index 3db7aff9871..00000000000 --- a/xlators/protocol/legacy/transport/ib-verbs/src/Makefile.am +++ /dev/null @@ -1,19 +0,0 @@ -# TODO : need to change transportdir - -transport_LTLIBRARIES = ib-verbs.la -transportdir = $(libdir)/glusterfs/$(PACKAGE_VERSION)/transport - -ib_verbs_la_LDFLAGS = -module -avoidversion - -ib_verbs_la_SOURCES = ib-verbs.c name.c -ib_verbs_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la \ - -libverbs $(top_builddir)/xlators/protocol/legacy/lib/src/libgfproto.la - -noinst_HEADERS = ib-verbs.h name.h ib-verbs-mem-types.h - -AM_CFLAGS = -fPIC -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -Wall -D$(GF_HOST_OS) \ - -I$(top_srcdir)/libglusterfs/src -shared -nostartfiles $(GF_CFLAGS) \ - -I$(top_srcdir)/xlators/protocol/legacy/transport/ib-verbs \ - -I$(top_srcdir)/xlators/protocol/legacy/lib/src - -CLEANFILES = *~ diff --git a/xlators/protocol/legacy/transport/ib-verbs/src/ib-verbs-mem-types.h b/xlators/protocol/legacy/transport/ib-verbs/src/ib-verbs-mem-types.h deleted file mode 100644 index bac559646fc..00000000000 --- a/xlators/protocol/legacy/transport/ib-verbs/src/ib-verbs-mem-types.h +++ /dev/null @@ -1,39 +0,0 @@ - -/* - Copyright (c) 2008-2009 Gluster, Inc. <http://www.gluster.com> - This file is part of GlusterFS. - - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. -*/ - - -#ifndef __IB_VERBS_MEM_TYPES_H__ -#define __IB_VERBS_MEM_TYPES_H__ - -#include "mem-types.h" - -enum gf_ib_verbs_mem_types_ { - gf_ibv_mt_ib_verbs_private_t = gf_common_mt_end + 1, - gf_ibv_mt_ib_verbs_ioq_t, - gf_ibv_mt_transport_t, - gf_ibv_mt_ib_verbs_local_t, - gf_ibv_mt_ib_verbs_post_t, - gf_ibv_mt_char, - gf_ibv_mt_qpent, - gf_ibv_mt_ib_verbs_device_t, - gf_ibv_mt_end -}; -#endif - diff --git a/xlators/protocol/legacy/transport/ib-verbs/src/ib-verbs.c b/xlators/protocol/legacy/transport/ib-verbs/src/ib-verbs.c deleted file mode 100644 index 0db996405e8..00000000000 --- a/xlators/protocol/legacy/transport/ib-verbs/src/ib-verbs.c +++ /dev/null @@ -1,2625 +0,0 @@ -/* - Copyright (c) 2006-2009 Gluster, Inc. <http://www.gluster.com> - This file is part of GlusterFS. - - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. -*/ - - -#ifndef _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif - -#include "dict.h" -#include "glusterfs.h" -#include "transport.h" -#include "protocol.h" -#include "logging.h" -#include "xlator.h" -#include "name.h" -#include "ib-verbs.h" -#include <signal.h> - -int32_t -gf_resolve_ip6 (const char *hostname, - uint16_t port, - int family, - void **dnscache, - struct addrinfo **addr_info); - -static uint16_t -ib_verbs_get_local_lid (struct ibv_context *context, - int32_t port) -{ - struct ibv_port_attr attr; - - if (ibv_query_port (context, port, &attr)) - return 0; - - return attr.lid; -} - -static const char * -get_port_state_str(enum ibv_port_state pstate) -{ - switch (pstate) { - case IBV_PORT_DOWN: return "PORT_DOWN"; - case IBV_PORT_INIT: return "PORT_INIT"; - case IBV_PORT_ARMED: return "PORT_ARMED"; - case IBV_PORT_ACTIVE: return "PORT_ACTIVE"; - case IBV_PORT_ACTIVE_DEFER: return "PORT_ACTIVE_DEFER"; - default: return "invalid state"; - } -} - -static int32_t -ib_check_active_port (struct ibv_context *ctx, uint8_t port) -{ - struct ibv_port_attr port_attr; - - int32_t ret = 0; - const char *state_str = NULL; - - if (!ctx) { - gf_log ("transport/ib-verbs", GF_LOG_ERROR, - "Error in supplied context"); - return -1; - } - - ret = ibv_query_port (ctx, port, &port_attr); - - if (ret) { - gf_log ("transport/ib-verbs", GF_LOG_ERROR, - "Failed to query port %u properties", port); - return -1; - } - - state_str = get_port_state_str (port_attr.state); - gf_log ("transport/ib-verbs", GF_LOG_TRACE, - "Infiniband PORT: (%u) STATE: (%s)", - port, state_str); - - if (port_attr.state == IBV_PORT_ACTIVE) - return 0; - - return -1; -} - -static int32_t -ib_get_active_port (struct ibv_context *ib_ctx) -{ - struct ibv_device_attr ib_device_attr; - - int32_t ret = -1; - uint8_t ib_port = 0; - - if (!ib_ctx) { - gf_log ("transport/ib-verbs", GF_LOG_ERROR, - "Error in supplied context"); - return -1; - } - if (ibv_query_device (ib_ctx, &ib_device_attr)) { - gf_log ("transport/ib-verbs", GF_LOG_ERROR, - "Failed to query device properties"); - return -1; - } - - for (ib_port = 1; ib_port <= ib_device_attr.phys_port_cnt; ++ib_port) { - ret = ib_check_active_port (ib_ctx, ib_port); - if (ret == 0) - return ib_port; - - gf_log ("transport/ib-verbs", GF_LOG_TRACE, - "Port:(%u) not active", ib_port); - continue; - } - return ret; -} - - - -static void -ib_verbs_put_post (ib_verbs_queue_t *queue, - ib_verbs_post_t *post) -{ - pthread_mutex_lock (&queue->lock); - if (post->prev) { - queue->active_count--; - post->prev->next = post->next; - } - if (post->next) - post->next->prev = post->prev; - post->prev = &queue->passive_posts; - post->next = post->prev->next; - post->prev->next = post; - post->next->prev = post; - queue->passive_count++; - pthread_mutex_unlock (&queue->lock); -} - - -static ib_verbs_post_t * -ib_verbs_new_post (ib_verbs_device_t *device, int32_t len) -{ - ib_verbs_post_t *post; - - post = (ib_verbs_post_t *) GF_CALLOC (1, sizeof (*post), - gf_ibv_mt_ib_verbs_post_t); - if (!post) - return NULL; - - post->buf_size = len; - - post->buf = valloc (len); - if (!post->buf) { - GF_FREE (post); - return NULL; - } - - post->mr = ibv_reg_mr (device->pd, - post->buf, - post->buf_size, - IBV_ACCESS_LOCAL_WRITE); - if (!post->mr) { - free (post->buf); - GF_FREE (post); - return NULL; - } - - return post; -} - - -static ib_verbs_post_t * -ib_verbs_get_post (ib_verbs_queue_t *queue) -{ - ib_verbs_post_t *post; - - pthread_mutex_lock (&queue->lock); - { - post = queue->passive_posts.next; - if (post == &queue->passive_posts) - post = NULL; - - if (post) { - if (post->prev) - post->prev->next = post->next; - if (post->next) - post->next->prev = post->prev; - post->prev = &queue->active_posts; - post->next = post->prev->next; - post->prev->next = post; - post->next->prev = post; - post->reused++; - queue->active_count++; - } - } - pthread_mutex_unlock (&queue->lock); - - return post; -} - -void -ib_verbs_destroy_post (ib_verbs_post_t *post) -{ - ibv_dereg_mr (post->mr); - free (post->buf); - GF_FREE (post); -} - - -static int32_t -__ib_verbs_quota_get (ib_verbs_peer_t *peer) -{ - int32_t ret = -1; - ib_verbs_private_t *priv = peer->trans->private; - - if (priv->connected && peer->quota > 0) { - ret = peer->quota--; - } - - return ret; -} - -/* - static int32_t - ib_verbs_quota_get (ib_verbs_peer_t *peer) - { - int32_t ret = -1; - ib_verbs_private_t *priv = peer->trans->private; - - pthread_mutex_lock (&priv->write_mutex); - { - ret = __ib_verbs_quota_get (peer); - } - pthread_mutex_unlock (&priv->write_mutex); - - return ret; - } -*/ - -static void -__ib_verbs_ioq_entry_free (ib_verbs_ioq_t *entry) -{ - list_del_init (&entry->list); - if (entry->iobref) - iobref_unref (entry->iobref); - - /* TODO: use mem-pool */ - GF_FREE (entry->buf); - - /* TODO: use mem-pool */ - GF_FREE (entry); -} - - -static void -__ib_verbs_ioq_flush (ib_verbs_peer_t *peer) -{ - ib_verbs_ioq_t *entry = NULL, *dummy = NULL; - - list_for_each_entry_safe (entry, dummy, &peer->ioq, list) { - __ib_verbs_ioq_entry_free (entry); - } -} - - -static int32_t -__ib_verbs_disconnect (transport_t *this) -{ - ib_verbs_private_t *priv = this->private; - int32_t ret = 0; - - if (priv->connected || priv->tcp_connected) { - fcntl (priv->sock, F_SETFL, O_NONBLOCK); - if (shutdown (priv->sock, SHUT_RDWR) != 0) { - gf_log ("transport/ib-verbs", - GF_LOG_DEBUG, - "shutdown () - error: %s", - strerror (errno)); - ret = -errno; - priv->tcp_connected = 0; - } - } - - return ret; -} - - -static int32_t -ib_verbs_post_send (struct ibv_qp *qp, - ib_verbs_post_t *post, - int32_t len) -{ - struct ibv_sge list = { - .addr = (unsigned long) post->buf, - .length = len, - .lkey = post->mr->lkey - }; - - struct ibv_send_wr wr = { - .wr_id = (unsigned long) post, - .sg_list = &list, - .num_sge = 1, - .opcode = IBV_WR_SEND, - .send_flags = IBV_SEND_SIGNALED, - }, *bad_wr; - - if (!qp) - return -1; - - return ibv_post_send (qp, &wr, &bad_wr); -} - - -static int32_t -__ib_verbs_ioq_churn_entry (ib_verbs_peer_t *peer, ib_verbs_ioq_t *entry) -{ - int32_t ret = 0, quota = 0; - ib_verbs_private_t *priv = peer->trans->private; - ib_verbs_device_t *device = priv->device; - ib_verbs_options_t *options = &priv->options; - ib_verbs_post_t *post = NULL; - int32_t len = 0; - - quota = __ib_verbs_quota_get (peer); - if (quota > 0) { - post = ib_verbs_get_post (&device->sendq); - if (!post) - post = ib_verbs_new_post (device, - (options->send_size + 2048)); - - len = iov_length ((const struct iovec *)&entry->vector, - entry->count); - if (len >= (options->send_size + 2048)) { - gf_log ("transport/ib-verbs", GF_LOG_ERROR, - "increase value of option 'transport.ib-verbs." - "work-request-send-size' (given=> %"PRId64") " - "to send bigger (%d) messages", - (options->send_size + 2048), len); - return -1; - } - - iov_unload (post->buf, - (const struct iovec *)&entry->vector, - entry->count); - - ret = ib_verbs_post_send (peer->qp, post, len); - if (!ret) { - __ib_verbs_ioq_entry_free (entry); - ret = len; - } else { - gf_log ("transport/ib-verbs", GF_LOG_DEBUG, - "ibv_post_send failed with ret = %d", ret); - ib_verbs_put_post (&device->sendq, post); - __ib_verbs_disconnect (peer->trans); - ret = -1; - } - } - - return ret; -} - - -static int32_t -__ib_verbs_ioq_churn (ib_verbs_peer_t *peer) -{ - ib_verbs_ioq_t *entry = NULL; - int32_t ret = 0; - - while (!list_empty (&peer->ioq)) - { - /* pick next entry */ - entry = peer->ioq_next; - - ret = __ib_verbs_ioq_churn_entry (peer, entry); - - if (ret <= 0) - break; - } - - /* - list_for_each_entry_safe (entry, dummy, &peer->ioq, list) { - ret = __ib_verbs_ioq_churn_entry (peer, entry); - if (ret <= 0) { - break; - } - } - */ - - return ret; -} - -static int32_t -__ib_verbs_quota_put (ib_verbs_peer_t *peer) -{ - int32_t ret; - - peer->quota++; - ret = peer->quota; - - if (!list_empty (&peer->ioq)) { - ret = __ib_verbs_ioq_churn (peer); - } - - return ret; -} - - -static int32_t -ib_verbs_quota_put (ib_verbs_peer_t *peer) -{ - int32_t ret; - ib_verbs_private_t *priv = peer->trans->private; - - pthread_mutex_lock (&priv->write_mutex); - { - ret = __ib_verbs_quota_put (peer); - } - pthread_mutex_unlock (&priv->write_mutex); - - return ret; -} - - -static int32_t -ib_verbs_post_recv (struct ibv_srq *srq, - ib_verbs_post_t *post) -{ - struct ibv_sge list = { - .addr = (unsigned long) post->buf, - .length = post->buf_size, - .lkey = post->mr->lkey - }; - - struct ibv_recv_wr wr = { - .wr_id = (unsigned long) post, - .sg_list = &list, - .num_sge = 1, - }, *bad_wr; - - return ibv_post_srq_recv (srq, &wr, &bad_wr); -} - - -static int32_t -ib_verbs_writev (transport_t *this, - ib_verbs_ioq_t *entry) -{ - int32_t ret = 0, need_append = 1; - ib_verbs_private_t *priv = this->private; - ib_verbs_peer_t *peer = NULL; - - pthread_mutex_lock (&priv->write_mutex); - { - if (!priv->connected) { - gf_log (this->xl->name, GF_LOG_DEBUG, - "ib-verbs is not connected to post a " - "send request"); - ret = -1; - goto unlock; - } - - peer = &priv->peer; - if (list_empty (&peer->ioq)) { - ret = __ib_verbs_ioq_churn_entry (peer, entry); - if (ret != 0) { - need_append = 0; - } - } - - if (need_append) { - list_add_tail (&entry->list, &peer->ioq); - } - } -unlock: - pthread_mutex_unlock (&priv->write_mutex); - return ret; -} - - -static ib_verbs_ioq_t * -ib_verbs_ioq_new (char *buf, int len, struct iovec *vector, - int count, struct iobref *iobref) -{ - ib_verbs_ioq_t *entry = NULL; - - /* TODO: use mem-pool */ - entry = GF_CALLOC (1, sizeof (*entry), gf_ibv_mt_ib_verbs_ioq_t); - - assert (count <= (MAX_IOVEC-2)); - - entry->header.colonO[0] = ':'; - entry->header.colonO[1] = 'O'; - entry->header.colonO[2] = '\0'; - entry->header.version = 42; - entry->header.size1 = hton32 (len); - entry->header.size2 = hton32 (iov_length (vector, count)); - - entry->vector[0].iov_base = &entry->header; - entry->vector[0].iov_len = sizeof (entry->header); - entry->count++; - - entry->vector[1].iov_base = buf; - entry->vector[1].iov_len = len; - entry->count++; - - if (vector && count) - { - memcpy (&entry->vector[2], vector, sizeof (*vector) * count); - entry->count += count; - } - - if (iobref) - entry->iobref = iobref_ref (iobref); - - entry->buf = buf; - - INIT_LIST_HEAD (&entry->list); - - return entry; -} - - -static int32_t -ib_verbs_submit (transport_t *this, char *buf, int32_t len, - struct iovec *vector, int count, struct iobref *iobref) -{ - int32_t ret = 0; - ib_verbs_ioq_t *entry = NULL; - - entry = ib_verbs_ioq_new (buf, len, vector, count, iobref); - ret = ib_verbs_writev (this, entry); - - if (ret > 0) { - ret = 0; - } - - return ret; -} - -static int -ib_verbs_receive (transport_t *this, char **hdr_p, size_t *hdrlen_p, - struct iobuf **iobuf_p) -{ - ib_verbs_private_t *priv = this->private; - /* TODO: return error if !priv->connected, check with locks */ - /* TODO: boundry checks for data_ptr/offset */ - char *copy_from = NULL; - ib_verbs_header_t *header = NULL; - uint32_t size1, size2, data_len = 0; - char *hdr = NULL; - struct iobuf *iobuf = NULL; - int32_t ret = 0; - - pthread_mutex_lock (&priv->recv_mutex); - { -/* - while (!priv->data_ptr) - pthread_cond_wait (&priv->recv_cond, &priv->recv_mutex); -*/ - - copy_from = priv->data_ptr + priv->data_offset; - - priv->data_ptr = NULL; - data_len = priv->data_len; - pthread_cond_broadcast (&priv->recv_cond); - } - pthread_mutex_unlock (&priv->recv_mutex); - - header = (ib_verbs_header_t *)copy_from; - if (strcmp (header->colonO, ":O")) { - gf_log ("transport/ib-verbs", GF_LOG_DEBUG, - "%s: corrupt header received", this->xl->name); - ret = -1; - goto err; - } - - size1 = ntoh32 (header->size1); - size2 = ntoh32 (header->size2); - - if (data_len != (size1 + size2 + sizeof (*header))) { - gf_log ("transport/ib-verbs", GF_LOG_DEBUG, - "%s: sizeof data read from transport is not equal " - "to the size specified in the header", - this->xl->name); - ret = -1; - goto err; - } - - copy_from += sizeof (*header); - - if (size1) { - hdr = GF_CALLOC (1, size1, gf_ibv_mt_char); - if (!hdr) { - gf_log (this->xl->name, GF_LOG_ERROR, - "unable to allocate header for peer %s", - this->peerinfo.identifier); - ret = -ENOMEM; - goto err; - } - memcpy (hdr, copy_from, size1); - copy_from += size1; - *hdr_p = hdr; - } - *hdrlen_p = size1; - - if (size2) { - iobuf = iobuf_get (this->xl->ctx->iobuf_pool); - if (!iobuf) { - gf_log (this->xl->name, GF_LOG_ERROR, - "unable to allocate IO buffer for peer %s", - this->peerinfo.identifier); - ret = -ENOMEM; - goto err; - } - memcpy (iobuf->ptr, copy_from, size2); - *iobuf_p = iobuf; - } - -err: - return ret; -} - - -static void -ib_verbs_destroy_cq (transport_t *this) -{ - ib_verbs_private_t *priv = this->private; - ib_verbs_device_t *device = priv->device; - - if (device->recv_cq) - ibv_destroy_cq (device->recv_cq); - device->recv_cq = NULL; - - if (device->send_cq) - ibv_destroy_cq (device->send_cq); - device->send_cq = NULL; - - return; -} - - -static int32_t -ib_verbs_create_cq (transport_t *this) -{ - ib_verbs_private_t *priv = this->private; - ib_verbs_options_t *options = &priv->options; - ib_verbs_device_t *device = priv->device; - int32_t ret = 0; - - device->recv_cq = ibv_create_cq (priv->device->context, - options->recv_count * 2, - device, - device->recv_chan, - 0); - if (!device->recv_cq) { - gf_log ("transport/ib-verbs", - GF_LOG_ERROR, - "%s: creation of CQ failed", - this->xl->name); - ret = -1; - } else if (ibv_req_notify_cq (device->recv_cq, 0)) { - gf_log ("transport/ib-verbs", - GF_LOG_ERROR, - "%s: ibv_req_notify_cq on CQ failed", - this->xl->name); - ret = -1; - } - - do { - /* TODO: make send_cq size dynamically adaptive */ - device->send_cq = ibv_create_cq (priv->device->context, - options->send_count * 1024, - device, - device->send_chan, - 0); - if (!device->send_cq) { - gf_log ("transport/ib-verbs", - GF_LOG_ERROR, - "%s: creation of send_cq failed", - this->xl->name); - ret = -1; - break; - } - - if (ibv_req_notify_cq (device->send_cq, 0)) { - gf_log ("transport/ib-verbs", - GF_LOG_ERROR, - "%s: ibv_req_notify_cq on send_cq failed", - this->xl->name); - ret = -1; - break; - } - } while (0); - - if (ret != 0) - ib_verbs_destroy_cq (this); - - return ret; -} - - -static void -ib_verbs_register_peer (ib_verbs_device_t *device, - int32_t qp_num, - ib_verbs_peer_t *peer) -{ - struct _qpent *ent; - ib_verbs_qpreg_t *qpreg = &device->qpreg; - int32_t hash = qp_num % 42; - - pthread_mutex_lock (&qpreg->lock); - ent = qpreg->ents[hash].next; - while ((ent != &qpreg->ents[hash]) && (ent->qp_num != qp_num)) - ent = ent->next; - if (ent->qp_num == qp_num) { - pthread_mutex_unlock (&qpreg->lock); - return; - } - ent = (struct _qpent *) GF_CALLOC (1, sizeof (*ent), gf_ibv_mt_qpent); - if (!ent) - return; - /* TODO: ref reg->peer */ - ent->peer = peer; - ent->next = &qpreg->ents[hash]; - ent->prev = ent->next->prev; - ent->next->prev = ent; - ent->prev->next = ent; - ent->qp_num = qp_num; - qpreg->count++; - pthread_mutex_unlock (&qpreg->lock); -} - - -static void -ib_verbs_unregister_peer (ib_verbs_device_t *device, - int32_t qp_num) -{ - struct _qpent *ent; - ib_verbs_qpreg_t *qpreg = &device->qpreg; - int32_t hash = qp_num % 42; - - pthread_mutex_lock (&qpreg->lock); - ent = qpreg->ents[hash].next; - while ((ent != &qpreg->ents[hash]) && (ent->qp_num != qp_num)) - ent = ent->next; - if (ent->qp_num != qp_num) { - pthread_mutex_unlock (&qpreg->lock); - return; - } - ent->prev->next = ent->next; - ent->next->prev = ent->prev; - /* TODO: unref reg->peer */ - GF_FREE (ent); - qpreg->count--; - pthread_mutex_unlock (&qpreg->lock); -} - - -static ib_verbs_peer_t * -__ib_verbs_lookup_peer (ib_verbs_device_t *device, int32_t qp_num) -{ - struct _qpent *ent = NULL; - ib_verbs_peer_t *peer = NULL; - ib_verbs_qpreg_t *qpreg = NULL; - int32_t hash = 0; - - qpreg = &device->qpreg; - hash = qp_num % 42; - ent = qpreg->ents[hash].next; - while ((ent != &qpreg->ents[hash]) && (ent->qp_num != qp_num)) - ent = ent->next; - - if (ent != &qpreg->ents[hash]) { - peer = ent->peer; - } - - return peer; -} - -/* -static ib_verbs_peer_t * -ib_verbs_lookup_peer (ib_verbs_device_t *device, - int32_t qp_num) -{ - ib_verbs_qpreg_t *qpreg = NULL; - ib_verbs_peer_t *peer = NULL; - - qpreg = &device->qpreg; - pthread_mutex_lock (&qpreg->lock); - { - peer = __ib_verbs_lookup_peer (device, qp_num); - } - pthread_mutex_unlock (&qpreg->lock); - - return peer; -} -*/ - - -static void -__ib_verbs_destroy_qp (transport_t *this) -{ - ib_verbs_private_t *priv = this->private; - - if (priv->peer.qp) { - ib_verbs_unregister_peer (priv->device, priv->peer.qp->qp_num); - ibv_destroy_qp (priv->peer.qp); - } - priv->peer.qp = NULL; - - return; -} - - -static int32_t -ib_verbs_create_qp (transport_t *this) -{ - ib_verbs_private_t *priv = this->private; - ib_verbs_options_t *options = &priv->options; - ib_verbs_device_t *device = priv->device; - int32_t ret = 0; - ib_verbs_peer_t *peer; - - peer = &priv->peer; - struct ibv_qp_init_attr init_attr = { - .send_cq = device->send_cq, - .recv_cq = device->recv_cq, - .srq = device->srq, - .cap = { - .max_send_wr = peer->send_count, - .max_recv_wr = peer->recv_count, - .max_send_sge = 1, - .max_recv_sge = 1 - }, - .qp_type = IBV_QPT_RC - }; - - struct ibv_qp_attr attr = { - .qp_state = IBV_QPS_INIT, - .pkey_index = 0, - .port_num = options->port, - .qp_access_flags = 0 - }; - - peer->qp = ibv_create_qp (device->pd, &init_attr); - if (!peer->qp) { - gf_log ("transport/ib-verbs", - GF_LOG_CRITICAL, - "%s: could not create QP", - this->xl->name); - ret = -1; - goto out; - } else if (ibv_modify_qp (peer->qp, &attr, - IBV_QP_STATE | - IBV_QP_PKEY_INDEX | - IBV_QP_PORT | - IBV_QP_ACCESS_FLAGS)) { - gf_log ("transport/ib-verbs", - GF_LOG_ERROR, - "%s: failed to modify QP to INIT state", - this->xl->name); - ret = -1; - goto out; - } - - peer->local_lid = ib_verbs_get_local_lid (device->context, - options->port); - peer->local_qpn = peer->qp->qp_num; - peer->local_psn = lrand48 () & 0xffffff; - - ib_verbs_register_peer (device, peer->qp->qp_num, peer); - -out: - if (ret == -1) - __ib_verbs_destroy_qp (this); - - return ret; -} - - -static void -ib_verbs_destroy_posts (transport_t *this) -{ - -} - - -static int32_t -__ib_verbs_create_posts (transport_t *this, - int32_t count, - int32_t size, - ib_verbs_queue_t *q) -{ - int32_t i; - int32_t ret = 0; - ib_verbs_private_t *priv = this->private; - ib_verbs_device_t *device = priv->device; - - for (i=0 ; i<count ; i++) { - ib_verbs_post_t *post; - - post = ib_verbs_new_post (device, size + 2048); - if (!post) { - gf_log ("transport/ib-verbs", - GF_LOG_ERROR, - "%s: post creation failed", - this->xl->name); - ret = -1; - break; - } - - ib_verbs_put_post (q, post); - } - return ret; -} - - -static int32_t -ib_verbs_create_posts (transport_t *this) -{ - int32_t i, ret; - ib_verbs_post_t *post = NULL; - ib_verbs_private_t *priv = this->private; - ib_verbs_options_t *options = &priv->options; - ib_verbs_device_t *device = priv->device; - - ret = __ib_verbs_create_posts (this, options->send_count, - options->send_size, - &device->sendq); - if (!ret) - ret = __ib_verbs_create_posts (this, options->recv_count, - options->recv_size, - &device->recvq); - - if (!ret) { - for (i=0 ; i<options->recv_count ; i++) { - post = ib_verbs_get_post (&device->recvq); - if (ib_verbs_post_recv (device->srq, post) != 0) { - ret = -1; - break; - } - } - } - - if (ret) - ib_verbs_destroy_posts (this); - - return ret; -} - - -static int32_t -ib_verbs_connect_qp (transport_t *this) -{ - ib_verbs_private_t *priv = this->private; - ib_verbs_options_t *options = &priv->options; - struct ibv_qp_attr attr = { - .qp_state = IBV_QPS_RTR, - .path_mtu = options->mtu, - .dest_qp_num = priv->peer.remote_qpn, - .rq_psn = priv->peer.remote_psn, - .max_dest_rd_atomic = 1, - .min_rnr_timer = 12, - .ah_attr = { - .is_global = 0, - .dlid = priv->peer.remote_lid, - .sl = 0, - .src_path_bits = 0, - .port_num = options->port - } - }; - if (ibv_modify_qp (priv->peer.qp, &attr, - IBV_QP_STATE | - IBV_QP_AV | - IBV_QP_PATH_MTU | - IBV_QP_DEST_QPN | - IBV_QP_RQ_PSN | - IBV_QP_MAX_DEST_RD_ATOMIC | - IBV_QP_MIN_RNR_TIMER)) { - gf_log ("transport/ib-verbs", - GF_LOG_CRITICAL, - "Failed to modify QP to RTR\n"); - return -1; - } - - /* TODO: make timeout and retry_cnt configurable from options */ - attr.qp_state = IBV_QPS_RTS; - attr.timeout = 14; - attr.retry_cnt = 7; - attr.rnr_retry = 7; - attr.sq_psn = priv->peer.local_psn; - attr.max_rd_atomic = 1; - if (ibv_modify_qp (priv->peer.qp, &attr, - IBV_QP_STATE | - IBV_QP_TIMEOUT | - IBV_QP_RETRY_CNT | - IBV_QP_RNR_RETRY | - IBV_QP_SQ_PSN | - IBV_QP_MAX_QP_RD_ATOMIC)) { - gf_log ("transport/ib-verbs", - GF_LOG_CRITICAL, - "Failed to modify QP to RTS\n"); - return -1; - } - - return 0; -} - -static int32_t -__ib_verbs_teardown (transport_t *this) -{ - ib_verbs_private_t *priv = this->private; - - __ib_verbs_destroy_qp (this); - - if (!list_empty (&priv->peer.ioq)) { - __ib_verbs_ioq_flush (&priv->peer); - } - - /* TODO: decrement cq size */ - return 0; -} - -/* - * return value: - * 0 = success (completed) - * -1 = error - * > 0 = incomplete - */ - -static int -__tcp_rwv (transport_t *this, struct iovec *vector, int count, - struct iovec **pending_vector, int *pending_count, - int write) -{ - ib_verbs_private_t *priv = NULL; - int sock = -1; - int ret = -1; - struct iovec *opvector = vector; - int opcount = count; - int moved = 0; - - priv = this->private; - sock = priv->sock; - - while (opcount) - { - if (write) - { - ret = writev (sock, opvector, opcount); - - if (ret == 0 || (ret == -1 && errno == EAGAIN)) - { - /* done for now */ - break; - } - } - else - { - ret = readv (sock, opvector, opcount); - - if (ret == -1 && errno == EAGAIN) - { - /* done for now */ - break; - } - } - - if (ret == 0) - { - gf_log (this->xl->name, GF_LOG_DEBUG, - "EOF from peer %s", this->peerinfo.identifier); - opcount = -1; - errno = ENOTCONN; - break; - } - - if (ret == -1) - { - if (errno == EINTR) - continue; - - gf_log (this->xl->name, GF_LOG_DEBUG, - "%s failed (%s)", write ? "writev" : "readv", - strerror (errno)); - if (write && !priv->connected && - (errno == ECONNREFUSED)) - gf_log (this->xl->name, GF_LOG_ERROR, - "possible mismatch of 'transport-type'" - " in protocol server and client. " - "check volume file"); - opcount = -1; - break; - } - - moved = 0; - - while (moved < ret) - { - if ((ret - moved) >= opvector[0].iov_len) - { - moved += opvector[0].iov_len; - opvector++; - opcount--; - } - else - { - opvector[0].iov_len -= (ret - moved); - opvector[0].iov_base += (ret - moved); - moved += (ret - moved); - } - while (opcount && !opvector[0].iov_len) - { - opvector++; - opcount--; - } - } - } - - if (pending_vector) - *pending_vector = opvector; - - if (pending_count) - *pending_count = opcount; - - return opcount; -} - - -static int -__tcp_readv (transport_t *this, struct iovec *vector, int count, - struct iovec **pending_vector, int *pending_count) -{ - int ret = -1; - - ret = __tcp_rwv (this, vector, count, - pending_vector, pending_count, 0); - - return ret; -} - - -static int -__tcp_writev (transport_t *this, struct iovec *vector, int count, - struct iovec **pending_vector, int *pending_count) -{ - int ret = -1; - ib_verbs_private_t *priv = this->private; - - ret = __tcp_rwv (this, vector, count, pending_vector, - pending_count, 1); - - if (ret > 0) { - /* TODO: Avoid multiple calls when socket is already - registered for POLLOUT */ - priv->idx = event_select_on (this->xl->ctx->event_pool, - priv->sock, priv->idx, -1, 1); - } else if (ret == 0) { - priv->idx = event_select_on (this->xl->ctx->event_pool, - priv->sock, - priv->idx, -1, 0); - } - - return ret; -} - - -static void * -ib_verbs_recv_completion_proc (void *data) -{ - struct ibv_comp_channel *chan = data; - ib_verbs_private_t *priv = NULL; - ib_verbs_device_t *device; - ib_verbs_post_t *post; - ib_verbs_peer_t *peer; - struct ibv_cq *event_cq; - struct ibv_wc wc; - void *event_ctx; - int32_t ret = 0; - - - while (1) { - ret = ibv_get_cq_event (chan, &event_cq, &event_ctx); - if (ret) { - gf_log ("transport/ib-verbs", GF_LOG_ERROR, - "ibv_get_cq_event failed, terminating recv " - "thread %d (%d)", ret, errno); - continue; - } - - device = event_ctx; - - ret = ibv_req_notify_cq (event_cq, 0); - if (ret) { - gf_log ("transport/ib-verbs", GF_LOG_ERROR, - "ibv_req_notify_cq on %s failed, terminating " - "recv thread: %d (%d)", - device->device_name, ret, errno); - continue; - } - - device = (ib_verbs_device_t *) event_ctx; - - while ((ret = ibv_poll_cq (event_cq, 1, &wc)) > 0) { - post = (ib_verbs_post_t *) (long) wc.wr_id; - - pthread_mutex_lock (&device->qpreg.lock); - { - peer = __ib_verbs_lookup_peer (device, - wc.qp_num); - - /* - * keep a refcount on transport so that it - * doesnot get freed because of some error - * indicated by wc.status till we are done - * with usage of peer and thereby that of trans. - */ - if (peer != NULL) { - transport_ref (peer->trans); - } - } - pthread_mutex_unlock (&device->qpreg.lock); - - if (wc.status != IBV_WC_SUCCESS) { - gf_log ("transport/ib-verbs", GF_LOG_ERROR, - "recv work request on `%s' returned " - "error (%d)", - device->device_name, - wc.status); - if (peer) { - transport_unref (peer->trans); - transport_disconnect (peer->trans); - } - - if (post) { - ib_verbs_post_recv (device->srq, post); - } - continue; - } - - if (peer) { - priv = peer->trans->private; - - pthread_mutex_lock (&priv->recv_mutex); - { - while (priv->data_ptr) - pthread_cond_wait (&priv->recv_cond, - &priv->recv_mutex); - - priv->data_ptr = post->buf; - priv->data_offset = 0; - priv->data_len = wc.byte_len; - - /*pthread_cond_broadcast (&priv->recv_cond);*/ - } - pthread_mutex_unlock (&priv->recv_mutex); - - if ((ret = xlator_notify (peer->trans->xl, GF_EVENT_POLLIN, - peer->trans, NULL)) == -1) { - gf_log ("transport/ib-verbs", - GF_LOG_DEBUG, - "pollin notification to %s " - "failed, disconnecting " - "transport", - peer->trans->xl->name); - transport_disconnect (peer->trans); - } - - transport_unref (peer->trans); - } else { - gf_log ("transport/ib-verbs", - GF_LOG_DEBUG, - "could not lookup peer for qp_num: %d", - wc.qp_num); - } - ib_verbs_post_recv (device->srq, post); - } - - if (ret < 0) { - gf_log ("transport/ib-verbs", - GF_LOG_ERROR, - "ibv_poll_cq on `%s' returned error " - "(ret = %d, errno = %d)", - device->device_name, ret, errno); - continue; - } - ibv_ack_cq_events (event_cq, 1); - } - return NULL; -} - - -static void * -ib_verbs_send_completion_proc (void *data) -{ - struct ibv_comp_channel *chan = data; - ib_verbs_post_t *post; - ib_verbs_peer_t *peer; - struct ibv_cq *event_cq; - void *event_ctx; - ib_verbs_device_t *device; - struct ibv_wc wc; - int32_t ret; - - while (1) { - ret = ibv_get_cq_event (chan, &event_cq, &event_ctx); - if (ret) { - gf_log ("transport/ib-verbs", GF_LOG_ERROR, - "ibv_get_cq_event on failed, terminating " - "send thread: %d (%d)", ret, errno); - continue; - } - - device = event_ctx; - - ret = ibv_req_notify_cq (event_cq, 0); - if (ret) { - gf_log ("transport/ib-verbs", GF_LOG_ERROR, - "ibv_req_notify_cq on %s failed, terminating " - "send thread: %d (%d)", - device->device_name, ret, errno); - continue; - } - - while ((ret = ibv_poll_cq (event_cq, 1, &wc)) > 0) { - post = (ib_verbs_post_t *) (long) wc.wr_id; - - pthread_mutex_lock (&device->qpreg.lock); - { - peer = __ib_verbs_lookup_peer (device, - wc.qp_num); - - /* - * keep a refcount on transport so that it - * doesnot get freed because of some error - * indicated by wc.status till we are done - * with usage of peer and thereby that of trans. - */ - if (peer != NULL) { - transport_ref (peer->trans); - } - } - pthread_mutex_unlock (&device->qpreg.lock); - - if (wc.status != IBV_WC_SUCCESS) { - gf_log ("transport/ib-verbs", GF_LOG_ERROR, - "send work request on `%s' returned " - "error wc.status = %d, wc.vendor_err " - "= %d, post->buf = %p, wc.byte_len = " - "%d, post->reused = %d", - device->device_name, wc.status, - wc.vendor_err, - post->buf, wc.byte_len, post->reused); - if (wc.status == IBV_WC_RETRY_EXC_ERR) - gf_log ("ib-verbs", GF_LOG_ERROR, - "connection between client and" - " server not working. check by" - " running 'ibv_srq_pingpong'. " - "also make sure subnet manager" - " is running (eg: 'opensm'), " - "or check if ib-verbs port is " - "valid (or active) by running " - " 'ibv_devinfo'. contact " - "Gluster Support Team if " - "the problem persists."); - if (peer) - transport_disconnect (peer->trans); - } - - if (post) { - ib_verbs_put_post (&device->sendq, post); - } - - if (peer) { - int quota_ret = ib_verbs_quota_put (peer); - if (quota_ret < 0) { - gf_log ("ib-verbs", GF_LOG_DEBUG, - "failed to send message"); - - } - - transport_unref (peer->trans); - } else { - gf_log ("transport/ib-verbs", GF_LOG_DEBUG, - "could not lookup peer for qp_num: %d", - wc.qp_num); - } - } - - if (ret < 0) { - gf_log ("transport/ib-verbs", GF_LOG_ERROR, - "ibv_poll_cq on `%s' returned error (ret = %d," - " errno = %d)", - device->device_name, ret, errno); - continue; - } - ibv_ack_cq_events (event_cq, 1); - } - - return NULL; -} - -static void -ib_verbs_options_init (transport_t *this) -{ - ib_verbs_private_t *priv = this->private; - ib_verbs_options_t *options = &priv->options; - int32_t mtu; - data_t *temp; - - /* TODO: validate arguments from options below */ - - options->send_size = this->xl->ctx->page_size * 4; /* 512 KB */ - options->recv_size = this->xl->ctx->page_size * 4; /* 512 KB */ - options->send_count = 32; - options->recv_count = 32; - - temp = dict_get (this->xl->options, - "transport.ib-verbs.work-request-send-count"); - if (temp) - options->send_count = data_to_int32 (temp); - - temp = dict_get (this->xl->options, - "transport.ib-verbs.work-request-recv-count"); - if (temp) - options->recv_count = data_to_int32 (temp); - - options->port = 0; - temp = dict_get (this->xl->options, - "transport.ib-verbs.port"); - if (temp) - options->port = data_to_uint64 (temp); - - options->mtu = mtu = IBV_MTU_2048; - temp = dict_get (this->xl->options, - "transport.ib-verbs.mtu"); - if (temp) - mtu = data_to_int32 (temp); - switch (mtu) { - case 256: options->mtu = IBV_MTU_256; - break; - case 512: options->mtu = IBV_MTU_512; - break; - case 1024: options->mtu = IBV_MTU_1024; - break; - case 2048: options->mtu = IBV_MTU_2048; - break; - case 4096: options->mtu = IBV_MTU_4096; - break; - default: - if (temp) - gf_log ("transport/ib-verbs", GF_LOG_WARNING, - "%s: unrecognized MTU value '%s', defaulting " - "to '2048'", this->xl->name, - data_to_str (temp)); - else - gf_log ("transport/ib-verbs", GF_LOG_TRACE, - "%s: defaulting MTU to '2048'", - this->xl->name); - options->mtu = IBV_MTU_2048; - break; - } - - temp = dict_get (this->xl->options, - "transport.ib-verbs.device-name"); - if (temp) - options->device_name = gf_strdup (temp->data); - - return; -} - -static void -ib_verbs_queue_init (ib_verbs_queue_t *queue) -{ - pthread_mutex_init (&queue->lock, NULL); - - queue->active_posts.next = &queue->active_posts; - queue->active_posts.prev = &queue->active_posts; - queue->passive_posts.next = &queue->passive_posts; - queue->passive_posts.prev = &queue->passive_posts; -} - - -static ib_verbs_device_t * -ib_verbs_get_device (transport_t *this, - struct ibv_context *ibctx) -{ - glusterfs_ctx_t *ctx = this->xl->ctx; - ib_verbs_private_t *priv = this->private; - ib_verbs_options_t *options = &priv->options; - char *device_name = priv->options.device_name; - uint32_t port = priv->options.port; - - uint8_t active_port = 0; - int32_t ret = 0; - int32_t i = 0; - - ib_verbs_device_t *trav; - - trav = ctx->ib; - while (trav) { - if ((!strcmp (trav->device_name, device_name)) && - (trav->port == port)) - break; - trav = trav->next; - } - - if (!trav) { - - trav = GF_CALLOC (1, sizeof (*trav), - gf_ibv_mt_ib_verbs_device_t); - if (!trav) - return NULL; - priv->device = trav; - - trav->context = ibctx; - - ret = ib_get_active_port (trav->context); - - if (ret < 0) { - if (!port) { - gf_log ("transport/ib-verbs", GF_LOG_ERROR, - "Failed to find any active ports and " - "none specified in volume file," - " exiting"); - return NULL; - } - } - - active_port = ret; - - if (port) { - ret = ib_check_active_port (trav->context, port); - if (ret < 0) { - gf_log ("transport/ib-verbs", GF_LOG_WARNING, - "On device %s: provided port:%u is " - "found to be offline, continuing to " - "use the same port", device_name, port); - } - } else { - priv->options.port = active_port; - port = active_port; - gf_log ("transport/ib-verbs", GF_LOG_TRACE, - "Port unspecified in volume file using active " - "port: %u", port); - } - - trav->device_name = gf_strdup (device_name); - trav->port = port; - - trav->next = ctx->ib; - ctx->ib = trav; - - trav->send_chan = ibv_create_comp_channel (trav->context); - if (!trav->send_chan) { - gf_log ("transport/ib-verbs", GF_LOG_ERROR, - "%s: could not create send completion channel", - device_name); - /* TODO: cleanup current mess */ - return NULL; - } - - trav->recv_chan = ibv_create_comp_channel (trav->context); - if (!trav->recv_chan) { - gf_log ("transport/ib-verbs", GF_LOG_ERROR, - "could not create recv completion channel"); - /* TODO: cleanup current mess */ - return NULL; - } - - if (ib_verbs_create_cq (this) < 0) { - gf_log ("transport/ib-verbs", GF_LOG_ERROR, - "%s: could not create CQ", - this->xl->name); - return NULL; - } - - /* protection domain */ - trav->pd = ibv_alloc_pd (trav->context); - - if (!trav->pd) { - gf_log ("transport/ib-verbs", GF_LOG_ERROR, - "%s: could not allocate protection domain", - this->xl->name); - return NULL; - } - - struct ibv_srq_init_attr attr = { - .attr = { - .max_wr = options->recv_count, - .max_sge = 1 - } - }; - trav->srq = ibv_create_srq (trav->pd, &attr); - - if (!trav->srq) { - gf_log ("transport/ib-verbs", GF_LOG_ERROR, - "%s: could not create SRQ", - this->xl->name); - return NULL; - } - - /* queue init */ - ib_verbs_queue_init (&trav->sendq); - ib_verbs_queue_init (&trav->recvq); - - if (ib_verbs_create_posts (this) < 0) { - gf_log ("transport/ib-verbs", GF_LOG_ERROR, - "%s: could not allocate posts", - this->xl->name); - return NULL; - } - - /* completion threads */ - ret = pthread_create (&trav->send_thread, - NULL, - ib_verbs_send_completion_proc, - trav->send_chan); - if (ret) { - gf_log ("transport/ib-verbs", GF_LOG_ERROR, - "could not create send completion thread"); - return NULL; - } - ret = pthread_create (&trav->recv_thread, - NULL, - ib_verbs_recv_completion_proc, - trav->recv_chan); - if (ret) { - gf_log ("transport/ib-verbs", GF_LOG_ERROR, - "could not create recv completion thread"); - return NULL; - } - - /* qpreg */ - pthread_mutex_init (&trav->qpreg.lock, NULL); - for (i=0; i<42; i++) { - trav->qpreg.ents[i].next = &trav->qpreg.ents[i]; - trav->qpreg.ents[i].prev = &trav->qpreg.ents[i]; - } - } - return trav; -} - -static int32_t -ib_verbs_init (transport_t *this) -{ - ib_verbs_private_t *priv = this->private; - ib_verbs_options_t *options = &priv->options; - struct ibv_device **dev_list; - struct ibv_context *ib_ctx = NULL; - int32_t ret = 0; - - ib_verbs_options_init (this); - - { - dev_list = ibv_get_device_list (NULL); - - if (!dev_list) { - gf_log ("transport/ib-verbs", - GF_LOG_CRITICAL, - "Failed to get IB devices"); - ret = -1; - goto cleanup; - } - - if (!*dev_list) { - gf_log ("transport/ib-verbs", - GF_LOG_CRITICAL, - "No IB devices found"); - ret = -1; - goto cleanup; - } - - if (!options->device_name) { - if (*dev_list) { - options->device_name = - gf_strdup (ibv_get_device_name (*dev_list)); - } else { - gf_log ("transport/ib-verbs", GF_LOG_CRITICAL, - "IB device list is empty. Check for " - "'ib_uverbs' module"); - return -1; - goto cleanup; - } - } - - while (*dev_list) { - if (!strcmp (ibv_get_device_name (*dev_list), - options->device_name)) { - ib_ctx = ibv_open_device (*dev_list); - - if (!ib_ctx) { - gf_log ("transport/ib-verbs", - GF_LOG_ERROR, - "Failed to get infiniband" - "device context"); - ret = -1; - goto cleanup; - } - break; - } - ++dev_list; - } - - priv->device = ib_verbs_get_device (this, ib_ctx); - - if (!priv->device) { - gf_log ("transport/ib-verbs", GF_LOG_ERROR, - "could not create ib_verbs device for %s", - options->device_name); - ret = -1; - goto cleanup; - } - } - - priv->peer.trans = this; - INIT_LIST_HEAD (&priv->peer.ioq); - - pthread_mutex_init (&priv->read_mutex, NULL); - pthread_mutex_init (&priv->write_mutex, NULL); - pthread_mutex_init (&priv->recv_mutex, NULL); - pthread_cond_init (&priv->recv_cond, NULL); - -cleanup: - if (-1 == ret) { - if (ib_ctx) - ibv_close_device (ib_ctx); - } - - if (dev_list) - ibv_free_device_list (dev_list); - - return ret; -} - - -static int32_t -ib_verbs_disconnect (transport_t *this) -{ - ib_verbs_private_t *priv = this->private; - int32_t ret = 0; - - pthread_mutex_lock (&priv->write_mutex); - { - ret = __ib_verbs_disconnect (this); - } - pthread_mutex_unlock (&priv->write_mutex); - - return ret; -} - - -static int32_t -__tcp_connect_finish (int fd) -{ - int ret = -1; - int optval = 0; - socklen_t optlen = sizeof (int); - - ret = getsockopt (fd, SOL_SOCKET, SO_ERROR, - (void *)&optval, &optlen); - - if (ret == 0 && optval) - { - errno = optval; - ret = -1; - } - - return ret; -} - -static inline void -ib_verbs_fill_handshake_data (char *buf, struct ib_verbs_nbio *nbio, - ib_verbs_private_t *priv) -{ - sprintf (buf, - "QP1:RECV_BLKSIZE=%08x:SEND_BLKSIZE=%08x\n" - "QP1:LID=%04x:QPN=%06x:PSN=%06x\n", - priv->peer.recv_size, - priv->peer.send_size, - priv->peer.local_lid, - priv->peer.local_qpn, - priv->peer.local_psn); - - nbio->vector.iov_base = buf; - nbio->vector.iov_len = strlen (buf) + 1; - nbio->count = 1; - return; -} - -static inline void -ib_verbs_fill_handshake_ack (char *buf, struct ib_verbs_nbio *nbio) -{ - sprintf (buf, "DONE\n"); - nbio->vector.iov_base = buf; - nbio->vector.iov_len = strlen (buf) + 1; - nbio->count = 1; - return; -} - -static int -ib_verbs_handshake_pollin (transport_t *this) -{ - int ret = 0; - ib_verbs_private_t *priv = this->private; - char *buf = priv->handshake.incoming.buf; - int32_t recv_buf_size, send_buf_size; - socklen_t sock_len; - - if (priv->handshake.incoming.state == IB_VERBS_HANDSHAKE_COMPLETE) { - return -1; - } - - pthread_mutex_lock (&priv->write_mutex); - { - while (priv->handshake.incoming.state != IB_VERBS_HANDSHAKE_COMPLETE) - { - switch (priv->handshake.incoming.state) - { - case IB_VERBS_HANDSHAKE_START: - buf = priv->handshake.incoming.buf = GF_CALLOC (1, 256, gf_ibv_mt_char); - ib_verbs_fill_handshake_data (buf, &priv->handshake.incoming, priv); - buf[0] = 0; - priv->handshake.incoming.state = IB_VERBS_HANDSHAKE_RECEIVING_DATA; - break; - - case IB_VERBS_HANDSHAKE_RECEIVING_DATA: - ret = __tcp_readv (this, - &priv->handshake.incoming.vector, - priv->handshake.incoming.count, - &priv->handshake.incoming.pending_vector, - &priv->handshake.incoming.pending_count); - if (ret == -1) { - goto unlock; - } - - if (ret > 0) { - gf_log (this->xl->name, GF_LOG_TRACE, - "partial header read on NB socket. continue later"); - goto unlock; - } - - if (!ret) { - priv->handshake.incoming.state = IB_VERBS_HANDSHAKE_RECEIVED_DATA; - } - break; - - case IB_VERBS_HANDSHAKE_RECEIVED_DATA: - ret = sscanf (buf, - "QP1:RECV_BLKSIZE=%08x:SEND_BLKSIZE=%08x\n" - "QP1:LID=%04x:QPN=%06x:PSN=%06x\n", - &recv_buf_size, - &send_buf_size, - &priv->peer.remote_lid, - &priv->peer.remote_qpn, - &priv->peer.remote_psn); - - if ((ret != 5) && (strncmp (buf, "QP1:", 4))) { - gf_log ("transport/ib-verbs", - GF_LOG_CRITICAL, - "%s: remote-host(%s)'s " - "transport type is different", - this->xl->name, - this->peerinfo.identifier); - ret = -1; - goto unlock; - } - - if (recv_buf_size < priv->peer.recv_size) - priv->peer.recv_size = recv_buf_size; - if (send_buf_size < priv->peer.send_size) - priv->peer.send_size = send_buf_size; - - gf_log ("transport/ib-verbs", GF_LOG_TRACE, - "%s: transacted recv_size=%d " - "send_size=%d", - this->xl->name, priv->peer.recv_size, - priv->peer.send_size); - - priv->peer.quota = priv->peer.send_count; - - if (ib_verbs_connect_qp (this)) { - gf_log ("transport/ib-verbs", - GF_LOG_ERROR, - "%s: failed to connect with " - "remote QP", this->xl->name); - ret = -1; - goto unlock; - } - ib_verbs_fill_handshake_ack (buf, &priv->handshake.incoming); - buf[0] = 0; - priv->handshake.incoming.state = IB_VERBS_HANDSHAKE_RECEIVING_ACK; - break; - - case IB_VERBS_HANDSHAKE_RECEIVING_ACK: - ret = __tcp_readv (this, - &priv->handshake.incoming.vector, - priv->handshake.incoming.count, - &priv->handshake.incoming.pending_vector, - &priv->handshake.incoming.pending_count); - if (ret == -1) { - goto unlock; - } - - if (ret > 0) { - gf_log (this->xl->name, GF_LOG_TRACE, - "partial header read on NB " - "socket. continue later"); - goto unlock; - } - - if (!ret) { - priv->handshake.incoming.state = IB_VERBS_HANDSHAKE_RECEIVED_ACK; - } - break; - - case IB_VERBS_HANDSHAKE_RECEIVED_ACK: - if (strncmp (buf, "DONE", 4)) { - gf_log ("transport/ib-verbs", - GF_LOG_DEBUG, - "%s: handshake-3 did not " - "return 'DONE' (%s)", - this->xl->name, buf); - ret = -1; - goto unlock; - } - ret = 0; - priv->connected = 1; - sock_len = sizeof (struct sockaddr_storage); - getpeername (priv->sock, - (struct sockaddr *) &this->peerinfo.sockaddr, - &sock_len); - - GF_FREE (priv->handshake.incoming.buf); - priv->handshake.incoming.buf = NULL; - priv->handshake.incoming.state = IB_VERBS_HANDSHAKE_COMPLETE; - } - } - } -unlock: - pthread_mutex_unlock (&priv->write_mutex); - - if (ret == -1) { - transport_disconnect (this); - } else { - ret = 0; - } - - if (!ret && priv->connected) { - ret = xlator_notify (this->xl, GF_EVENT_CHILD_UP, this); - } - - return ret; -} - -static int -ib_verbs_handshake_pollout (transport_t *this) -{ - ib_verbs_private_t *priv = this->private; - char *buf = priv->handshake.outgoing.buf; - int32_t ret = 0; - - if (priv->handshake.outgoing.state == IB_VERBS_HANDSHAKE_COMPLETE) { - return 0; - } - - pthread_mutex_unlock (&priv->write_mutex); - { - while (priv->handshake.outgoing.state != IB_VERBS_HANDSHAKE_COMPLETE) - { - switch (priv->handshake.outgoing.state) - { - case IB_VERBS_HANDSHAKE_START: - buf = priv->handshake.outgoing.buf = GF_CALLOC (1, 256, gf_ibv_mt_char); - ib_verbs_fill_handshake_data (buf, &priv->handshake.outgoing, priv); - priv->handshake.outgoing.state = IB_VERBS_HANDSHAKE_SENDING_DATA; - break; - - case IB_VERBS_HANDSHAKE_SENDING_DATA: - ret = __tcp_writev (this, - &priv->handshake.outgoing.vector, - priv->handshake.outgoing.count, - &priv->handshake.outgoing.pending_vector, - &priv->handshake.outgoing.pending_count); - if (ret == -1) { - goto unlock; - } - - if (ret > 0) { - gf_log (this->xl->name, GF_LOG_TRACE, - "partial header read on NB socket. continue later"); - goto unlock; - } - - if (!ret) { - priv->handshake.outgoing.state = IB_VERBS_HANDSHAKE_SENT_DATA; - } - break; - - case IB_VERBS_HANDSHAKE_SENT_DATA: - ib_verbs_fill_handshake_ack (buf, &priv->handshake.outgoing); - priv->handshake.outgoing.state = IB_VERBS_HANDSHAKE_SENDING_ACK; - break; - - case IB_VERBS_HANDSHAKE_SENDING_ACK: - ret = __tcp_writev (this, - &priv->handshake.outgoing.vector, - priv->handshake.outgoing.count, - &priv->handshake.outgoing.pending_vector, - &priv->handshake.outgoing.pending_count); - - if (ret == -1) { - goto unlock; - } - - if (ret > 0) { - gf_log (this->xl->name, GF_LOG_TRACE, - "partial header read on NB " - "socket. continue later"); - goto unlock; - } - - if (!ret) { - GF_FREE (priv->handshake.outgoing.buf); - priv->handshake.outgoing.buf = NULL; - priv->handshake.outgoing.state = IB_VERBS_HANDSHAKE_COMPLETE; - } - break; - } - } - } -unlock: - pthread_mutex_unlock (&priv->write_mutex); - - if (ret == -1) { - transport_disconnect (this); - } else { - ret = 0; - } - - return ret; -} - -static int -ib_verbs_handshake_pollerr (transport_t *this) -{ - ib_verbs_private_t *priv = this->private; - int32_t ret = 0; - char need_unref = 0; - - gf_log ("transport/ib-verbs", GF_LOG_DEBUG, - "%s: peer disconnected, cleaning up", - this->xl->name); - - pthread_mutex_lock (&priv->write_mutex); - { - __ib_verbs_teardown (this); - - if (priv->sock != -1) { - event_unregister (this->xl->ctx->event_pool, - priv->sock, priv->idx); - need_unref = 1; - - if (close (priv->sock) != 0) { - gf_log ("transport/ib-verbs", GF_LOG_ERROR, - "close () - error: %s", - strerror (errno)); - ret = -errno; - } - priv->tcp_connected = priv->connected = 0; - priv->sock = -1; - } - - if (priv->handshake.incoming.buf) { - GF_FREE (priv->handshake.incoming.buf); - priv->handshake.incoming.buf = NULL; - } - - priv->handshake.incoming.state = IB_VERBS_HANDSHAKE_START; - - if (priv->handshake.outgoing.buf) { - GF_FREE (priv->handshake.outgoing.buf); - priv->handshake.outgoing.buf = NULL; - } - - priv->handshake.outgoing.state = IB_VERBS_HANDSHAKE_START; - } - pthread_mutex_unlock (&priv->write_mutex); - - xlator_notify (this->xl, GF_EVENT_POLLERR, this, NULL); - - if (need_unref) - transport_unref (this); - - return 0; -} - - -static int -tcp_connect_finish (transport_t *this) -{ - ib_verbs_private_t *priv = this->private; - int error = 0, ret = 0; - - pthread_mutex_lock (&priv->write_mutex); - { - ret = __tcp_connect_finish (priv->sock); - - if (!ret) { - this->myinfo.sockaddr_len = - sizeof (this->myinfo.sockaddr); - ret = getsockname (priv->sock, - (struct sockaddr *)&this->myinfo.sockaddr, - &this->myinfo.sockaddr_len); - if (ret == -1) - { - gf_log (this->xl->name, GF_LOG_ERROR, - "getsockname on new client-socket %d " - "failed (%s)", - priv->sock, strerror (errno)); - close (priv->sock); - error = 1; - goto unlock; - } - - gf_ibverbs_get_transport_identifiers (this); - priv->tcp_connected = 1; - } - - if (ret == -1 && errno != EINPROGRESS) { - gf_log (this->xl->name, GF_LOG_ERROR, - "tcp connect to %s failed (%s)", - this->peerinfo.identifier, strerror (errno)); - error = 1; - } - } -unlock: - pthread_mutex_unlock (&priv->write_mutex); - - if (error) { - transport_disconnect (this); - } - - return ret; -} - -static int -ib_verbs_event_handler (int fd, int idx, void *data, - int poll_in, int poll_out, int poll_err) -{ - transport_t *this = data; - ib_verbs_private_t *priv = this->private; - ib_verbs_options_t *options = NULL; - int ret = 0; - - if (!priv->tcp_connected) { - ret = tcp_connect_finish (this); - if (priv->tcp_connected) { - options = &priv->options; - - priv->peer.send_count = options->send_count; - priv->peer.recv_count = options->recv_count; - priv->peer.send_size = options->send_size; - priv->peer.recv_size = options->recv_size; - - if ((ret = ib_verbs_create_qp (this)) < 0) { - gf_log ("transport/ib-verbs", GF_LOG_ERROR, - "%s: could not create QP", - this->xl->name); - transport_disconnect (this); - } - } - } - - if (!ret && poll_out && priv->tcp_connected) { - ret = ib_verbs_handshake_pollout (this); - } - - if (!ret && poll_in && priv->tcp_connected) { - if (priv->handshake.incoming.state == IB_VERBS_HANDSHAKE_COMPLETE) { - gf_log ("transport/ib-verbs", GF_LOG_ERROR, - "%s: pollin received on tcp socket (peer: %s) " - "after handshake is complete", - this->xl->name, this->peerinfo.identifier); - ib_verbs_handshake_pollerr (this); - return 0; - } - ret = ib_verbs_handshake_pollin (this); - } - - if (ret < 0 || poll_err) { - ret = ib_verbs_handshake_pollerr (this); - } - - return 0; -} - -static int -__tcp_nonblock (int fd) -{ - int flags = 0; - int ret = -1; - - flags = fcntl (fd, F_GETFL); - - if (flags != -1) - ret = fcntl (fd, F_SETFL, flags | O_NONBLOCK); - - return ret; -} - -static int32_t -ib_verbs_connect (struct transport *this) -{ - dict_t *options = this->xl->options; - - ib_verbs_private_t *priv = this->private; - - int32_t ret = 0; - gf_boolean_t non_blocking = 1; - struct sockaddr_storage sockaddr; - socklen_t sockaddr_len = 0; - - if (priv->connected) { - return 0; - } - - if (dict_get (options, "non-blocking-io")) { - char *nb_connect = data_to_str (dict_get (this->xl->options, - "non-blocking-io")); - - if (gf_string2boolean (nb_connect, &non_blocking) == -1) { - gf_log (this->xl->name, GF_LOG_ERROR, - "'non-blocking-io' takes only boolean " - "options, not taking any action"); - non_blocking = 1; - } - } - - ret = gf_ibverbs_client_get_remote_sockaddr (this, - (struct sockaddr *)&sockaddr, - &sockaddr_len); - if (ret != 0) { - gf_log (this->xl->name, GF_LOG_DEBUG, - "cannot get remote address to connect"); - return ret; - } - - pthread_mutex_lock (&priv->write_mutex); - { - if (priv->sock != -1) { - ret = 0; - goto unlock; - } - - priv->sock = socket (((struct sockaddr *)&sockaddr)->sa_family, - SOCK_STREAM, 0); - - if (priv->sock == -1) { - gf_log (this->xl->name, GF_LOG_ERROR, - "socket () - error: %s", strerror (errno)); - ret = -errno; - goto unlock; - } - - gf_log (this->xl->name, GF_LOG_TRACE, - "socket fd = %d", priv->sock); - - memcpy (&this->peerinfo.sockaddr, &sockaddr, sockaddr_len); - this->peerinfo.sockaddr_len = sockaddr_len; - - ((struct sockaddr *) &this->myinfo.sockaddr)->sa_family = - ((struct sockaddr *)&this->peerinfo.sockaddr)->sa_family; - - if (non_blocking) - { - ret = __tcp_nonblock (priv->sock); - - if (ret == -1) - { - gf_log (this->xl->name, GF_LOG_ERROR, - "could not set socket %d to non " - "blocking mode (%s)", - priv->sock, strerror (errno)); - close (priv->sock); - priv->sock = -1; - goto unlock; - } - } - - ret = gf_ibverbs_client_bind (this, - (struct sockaddr *)&this->myinfo.sockaddr, - &this->myinfo.sockaddr_len, priv->sock); - if (ret == -1) - { - gf_log (this->xl->name, GF_LOG_WARNING, - "client bind failed: %s", strerror (errno)); - close (priv->sock); - priv->sock = -1; - goto unlock; - } - - ret = connect (priv->sock, - (struct sockaddr *)&this->peerinfo.sockaddr, - this->peerinfo.sockaddr_len); - if (ret == -1 && errno != EINPROGRESS) - { - gf_log (this->xl->name, GF_LOG_ERROR, - "connection attempt failed (%s)", - strerror (errno)); - close (priv->sock); - priv->sock = -1; - goto unlock; - } - - priv->tcp_connected = priv->connected = 0; - - transport_ref (this); - - priv->handshake.incoming.state = IB_VERBS_HANDSHAKE_START; - priv->handshake.outgoing.state = IB_VERBS_HANDSHAKE_START; - - priv->idx = event_register (this->xl->ctx->event_pool, - priv->sock, ib_verbs_event_handler, - this, 1, 1); - } -unlock: - pthread_mutex_unlock (&priv->write_mutex); - - return ret; -} - -static int -ib_verbs_server_event_handler (int fd, int idx, void *data, - int poll_in, int poll_out, int poll_err) -{ - int32_t main_sock = -1; - transport_t *this, *trans = data; - ib_verbs_private_t *priv = NULL; - ib_verbs_private_t *trans_priv = (ib_verbs_private_t *) trans->private; - ib_verbs_options_t *options = NULL; - - if (!poll_in) - return 0; - - this = GF_CALLOC (1, sizeof (transport_t), - gf_ibv_mt_transport_t); - if (!this) - return 0; - - priv = GF_CALLOC (1, sizeof (ib_verbs_private_t), - gf_ibv_mt_ib_verbs_private_t); - if (!priv) { - GF_FREE (this); - return 0; - } - - this->private = priv; - /* Copy all the ib_verbs related values in priv, from trans_priv - as other than QP, all the values remain same */ - priv->device = trans_priv->device; - priv->options = trans_priv->options; - options = &priv->options; - - this->ops = trans->ops; - this->xl = trans->xl; - this->init = trans->init; - this->fini = trans->fini; - - memcpy (&this->myinfo.sockaddr, &trans->myinfo.sockaddr, - trans->myinfo.sockaddr_len); - this->myinfo.sockaddr_len = trans->myinfo.sockaddr_len; - - main_sock = (trans_priv)->sock; - this->peerinfo.sockaddr_len = sizeof (this->peerinfo.sockaddr); - priv->sock = accept (main_sock, - (struct sockaddr *)&this->peerinfo.sockaddr, - &this->peerinfo.sockaddr_len); - if (priv->sock == -1) { - gf_log ("ib-verbs/server", GF_LOG_ERROR, - "accept() failed: %s", - strerror (errno)); - GF_FREE (this->private); - GF_FREE (this); - return -1; - } - - priv->peer.trans = this; - transport_ref (this); - - gf_ibverbs_get_transport_identifiers (this); - - priv->tcp_connected = 1; - priv->handshake.incoming.state = IB_VERBS_HANDSHAKE_START; - priv->handshake.outgoing.state = IB_VERBS_HANDSHAKE_START; - - priv->peer.send_count = options->send_count; - priv->peer.recv_count = options->recv_count; - priv->peer.send_size = options->send_size; - priv->peer.recv_size = options->recv_size; - INIT_LIST_HEAD (&priv->peer.ioq); - - if (ib_verbs_create_qp (this) < 0) { - gf_log ("transport/ib-verbs", GF_LOG_ERROR, - "%s: could not create QP", - this->xl->name); - transport_disconnect (this); - return -1; - } - - priv->idx = event_register (this->xl->ctx->event_pool, priv->sock, - ib_verbs_event_handler, this, 1, 1); - - pthread_mutex_init (&priv->read_mutex, NULL); - pthread_mutex_init (&priv->write_mutex, NULL); - pthread_mutex_init (&priv->recv_mutex, NULL); - /* pthread_cond_init (&priv->recv_cond, NULL); */ - - return 0; -} - -static int32_t -ib_verbs_listen (transport_t *this) -{ - struct sockaddr_storage sockaddr; - socklen_t sockaddr_len; - ib_verbs_private_t *priv = this->private; - int opt = 1, ret = 0; - char service[NI_MAXSERV], host[NI_MAXHOST]; - - memset (&sockaddr, 0, sizeof (sockaddr)); - ret = gf_ibverbs_server_get_local_sockaddr (this, - (struct sockaddr *)&sockaddr, - &sockaddr_len); - if (ret != 0) { - gf_log (this->xl->name, GF_LOG_DEBUG, - "cannot find network address of server to bind to"); - goto err; - } - - priv->sock = socket (((struct sockaddr *)&sockaddr)->sa_family, - SOCK_STREAM, 0); - if (priv->sock == -1) { - gf_log ("ib-verbs/server", GF_LOG_CRITICAL, - "init: failed to create socket, error: %s", - strerror (errno)); - GF_FREE (this->private); - ret = -1; - goto err; - } - - memcpy (&this->myinfo.sockaddr, &sockaddr, sockaddr_len); - this->myinfo.sockaddr_len = sockaddr_len; - - ret = getnameinfo ((struct sockaddr *)&this->myinfo.sockaddr, - this->myinfo.sockaddr_len, - host, sizeof (host), - service, sizeof (service), - NI_NUMERICHOST); - if (ret != 0) { - gf_log (this->xl->name, GF_LOG_ERROR, - "getnameinfo failed (%s)", gai_strerror (ret)); - goto err; - } - sprintf (this->myinfo.identifier, "%s:%s", host, service); - - setsockopt (priv->sock, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof (opt)); - if (bind (priv->sock, - (struct sockaddr *)&sockaddr, - sockaddr_len) != 0) { - ret = -1; - gf_log ("ib-verbs/server", GF_LOG_ERROR, - "init: failed to bind to socket for %s (%s)", - this->myinfo.identifier, strerror (errno)); - goto err; - } - - if (listen (priv->sock, 10) != 0) { - gf_log ("ib-verbs/server", GF_LOG_ERROR, - "init: listen () failed on socket for %s (%s)", - this->myinfo.identifier, strerror (errno)); - ret = -1; - goto err; - } - - /* Register the main socket */ - priv->idx = event_register (this->xl->ctx->event_pool, priv->sock, - ib_verbs_server_event_handler, - transport_ref (this), 1, 0); - -err: - return ret; -} - -struct transport_ops tops = { - .receive = ib_verbs_receive, - .submit = ib_verbs_submit, - .connect = ib_verbs_connect, - .disconnect = ib_verbs_disconnect, - .listen = ib_verbs_listen, -}; - -int32_t -init (transport_t *this) -{ - ib_verbs_private_t *priv = GF_CALLOC (1, sizeof (*priv), - gf_ibv_mt_ib_verbs_private_t); - this->private = priv; - priv->sock = -1; - - if (ib_verbs_init (this)) { - gf_log (this->xl->name, GF_LOG_ERROR, - "Failed to initialize IB Device"); - return -1; - } - - return 0; -} - -void -fini (struct transport *this) -{ - /* TODO: verify this function does graceful finish */ - ib_verbs_private_t *priv = this->private; - this->private = NULL; - - pthread_mutex_destroy (&priv->recv_mutex); - pthread_mutex_destroy (&priv->write_mutex); - pthread_mutex_destroy (&priv->read_mutex); - /* pthread_cond_destroy (&priv->recv_cond); */ - - gf_log (this->xl->name, GF_LOG_TRACE, - "called fini on transport: %p", - this); - GF_FREE (priv); - return; -} - -int32_t -mem_acct_init (xlator_t *this) -{ - int ret = -1; - - if (!this) - return ret; - - ret = xlator_mem_acct_init (this, gf_common_mt_end + 1); - - if (ret != 0) { - gf_log (this->name, GF_LOG_ERROR, "Memory accounting init" - "failed"); - return ret; - } - - return ret; -} - -/* TODO: expand each option */ -struct volume_options options[] = { - { .key = {"transport.ib-verbs.port", - "ib-verbs-port"}, - .type = GF_OPTION_TYPE_INT, - .min = 1, - .max = 4, - .description = "check the option by 'ibv_devinfo'" - }, - { .key = {"transport.ib-verbs.mtu", - "ib-verbs-mtu"}, - .type = GF_OPTION_TYPE_INT, - }, - { .key = {"transport.ib-verbs.device-name", - "ib-verbs-device-name"}, - .type = GF_OPTION_TYPE_ANY, - .description = "check by 'ibv_devinfo'" - }, - { .key = {"transport.ib-verbs.work-request-send-count", - "ib-verbs-work-request-send-count"}, - .type = GF_OPTION_TYPE_INT, - }, - { .key = {"transport.ib-verbs.work-request-recv-count", - "ib-verbs-work-request-recv-count"}, - .type = GF_OPTION_TYPE_INT, - }, - { .key = {"remote-port", - "transport.remote-port", - "transport.ib-verbs.remote-port"}, - .type = GF_OPTION_TYPE_INT - }, - { .key = {"transport.ib-verbs.listen-port", "listen-port"}, - .type = GF_OPTION_TYPE_INT - }, - { .key = {"transport.ib-verbs.connect-path", "connect-path"}, - .type = GF_OPTION_TYPE_ANY - }, - { .key = {"transport.ib-verbs.bind-path", "bind-path"}, - .type = GF_OPTION_TYPE_ANY - }, - { .key = {"transport.ib-verbs.listen-path", "listen-path"}, - .type = GF_OPTION_TYPE_ANY - }, - { .key = {"transport.address-family", - "address-family"}, - .value = {"inet", "inet6", "inet/inet6", "inet6/inet", - "unix", "inet-sdp" }, - .type = GF_OPTION_TYPE_STR - }, - { .key = {"transport.socket.lowlat"}, - .type = GF_OPTION_TYPE_BOOL - }, - { .key = {NULL} } -}; diff --git a/xlators/protocol/legacy/transport/ib-verbs/src/ib-verbs.h b/xlators/protocol/legacy/transport/ib-verbs/src/ib-verbs.h deleted file mode 100644 index c385b62e5cb..00000000000 --- a/xlators/protocol/legacy/transport/ib-verbs/src/ib-verbs.h +++ /dev/null @@ -1,220 +0,0 @@ -/* - Copyright (c) 2006-2009 Gluster, Inc. <http://www.gluster.com> - This file is part of GlusterFS. - - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. -*/ - -#ifndef _XPORT_IB_VERBS_H -#define _XPORT_IB_VERBS_H - - -#ifndef _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif - -#ifndef MAX_IOVEC -#define MAX_IOVEC 16 -#endif /* MAX_IOVEC */ - -#include "xlator.h" -#include "event.h" -#include "ib-verbs-mem-types.h" - -#include <stdio.h> -#include <list.h> -#include <arpa/inet.h> -#include <infiniband/verbs.h> - -#define GF_DEFAULT_IBVERBS_LISTEN_PORT 6997 - -/* options per transport end point */ -struct _ib_verbs_options { - int32_t port; - char *device_name; - enum ibv_mtu mtu; - int32_t send_count; - int32_t recv_count; - uint64_t recv_size; - uint64_t send_size; -}; -typedef struct _ib_verbs_options ib_verbs_options_t; - - -struct _ib_verbs_header { - char colonO[3]; - uint32_t size1; - uint32_t size2; - char version; -} __attribute__((packed)); -typedef struct _ib_verbs_header ib_verbs_header_t; - -struct _ib_verbs_ioq { - union { - struct list_head list; - struct { - struct _ib_verbs_ioq *next; - struct _ib_verbs_ioq *prev; - }; - }; - ib_verbs_header_t header; - struct iovec vector[MAX_IOVEC]; - int count; - char *buf; - struct iobref *iobref; -}; -typedef struct _ib_verbs_ioq ib_verbs_ioq_t; - -/* represents one communication peer, two per transport_t */ -struct _ib_verbs_peer { - transport_t *trans; - struct ibv_qp *qp; - - int32_t recv_count; - int32_t send_count; - int32_t recv_size; - int32_t send_size; - - int32_t quota; - union { - struct list_head ioq; - struct { - ib_verbs_ioq_t *ioq_next; - ib_verbs_ioq_t *ioq_prev; - }; - }; - - /* QP attributes, needed to connect with remote QP */ - int32_t local_lid; - int32_t local_psn; - int32_t local_qpn; - int32_t remote_lid; - int32_t remote_psn; - int32_t remote_qpn; -}; -typedef struct _ib_verbs_peer ib_verbs_peer_t; - - -struct _ib_verbs_post { - struct _ib_verbs_post *next, *prev; - struct ibv_mr *mr; - char *buf; - int32_t buf_size; - char aux; - int32_t reused; - pthread_barrier_t wait; -}; -typedef struct _ib_verbs_post ib_verbs_post_t; - - -struct _ib_verbs_queue { - ib_verbs_post_t active_posts, passive_posts; - int32_t active_count, passive_count; - pthread_mutex_t lock; -}; -typedef struct _ib_verbs_queue ib_verbs_queue_t; - - -struct _ib_verbs_qpreg { - pthread_mutex_t lock; - int32_t count; - struct _qpent { - struct _qpent *next, *prev; - int32_t qp_num; - ib_verbs_peer_t *peer; - } ents[42]; -}; -typedef struct _ib_verbs_qpreg ib_verbs_qpreg_t; - -/* context per device, stored in global glusterfs_ctx_t->ib */ -struct _ib_verbs_device { - struct _ib_verbs_device *next; - const char *device_name; - struct ibv_context *context; - int32_t port; - struct ibv_pd *pd; - struct ibv_srq *srq; - ib_verbs_qpreg_t qpreg; - struct ibv_comp_channel *send_chan, *recv_chan; - struct ibv_cq *send_cq, *recv_cq; - ib_verbs_queue_t sendq, recvq; - pthread_t send_thread, recv_thread; -}; -typedef struct _ib_verbs_device ib_verbs_device_t; - -typedef enum { - IB_VERBS_HANDSHAKE_START = 0, - IB_VERBS_HANDSHAKE_SENDING_DATA, - IB_VERBS_HANDSHAKE_RECEIVING_DATA, - IB_VERBS_HANDSHAKE_SENT_DATA, - IB_VERBS_HANDSHAKE_RECEIVED_DATA, - IB_VERBS_HANDSHAKE_SENDING_ACK, - IB_VERBS_HANDSHAKE_RECEIVING_ACK, - IB_VERBS_HANDSHAKE_RECEIVED_ACK, - IB_VERBS_HANDSHAKE_COMPLETE, -} ib_verbs_handshake_state_t; - -struct ib_verbs_nbio { - int state; - char *buf; - int count; - struct iovec vector; - struct iovec *pending_vector; - int pending_count; -}; - - -struct _ib_verbs_private { - int32_t sock; - int32_t idx; - unsigned char connected; - unsigned char tcp_connected; - unsigned char ib_connected; - in_addr_t addr; - unsigned short port; - - /* IB Verbs Driver specific variables, pointers */ - ib_verbs_peer_t peer; - ib_verbs_device_t *device; - ib_verbs_options_t options; - - /* Used by trans->op->receive */ - char *data_ptr; - int32_t data_offset; - int32_t data_len; - - /* Mutex */ - pthread_mutex_t read_mutex; - pthread_mutex_t write_mutex; - pthread_barrier_t handshake_barrier; - char handshake_ret; - - pthread_mutex_t recv_mutex; - pthread_cond_t recv_cond; - - /* used during ib_verbs_handshake */ - struct { - struct ib_verbs_nbio incoming; - struct ib_verbs_nbio outgoing; - int state; - ib_verbs_header_t header; - char *buf; - size_t size; - } handshake; -}; -typedef struct _ib_verbs_private ib_verbs_private_t; - -#endif /* _XPORT_IB_VERBS_H */ diff --git a/xlators/protocol/legacy/transport/ib-verbs/src/name.c b/xlators/protocol/legacy/transport/ib-verbs/src/name.c deleted file mode 100644 index 1b8f83c293e..00000000000 --- a/xlators/protocol/legacy/transport/ib-verbs/src/name.c +++ /dev/null @@ -1,712 +0,0 @@ -/* - Copyright (c) 2008-2009 Gluster, Inc. <http://www.gluster.com> - This file is part of GlusterFS. - - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. -*/ - -#include <sys/types.h> -#include <sys/socket.h> -#include <errno.h> -#include <netdb.h> -#include <string.h> - -#ifdef CLIENT_PORT_CEILING -#undef CLIENT_PORT_CEILING -#endif - -#define CLIENT_PORT_CEILING 1024 - -#ifndef AF_INET_SDP -#define AF_INET_SDP 27 -#endif - -#include "transport.h" -#include "ib-verbs.h" - -int32_t -gf_resolve_ip6 (const char *hostname, - uint16_t port, - int family, - void **dnscache, - struct addrinfo **addr_info); - -static int32_t -af_inet_bind_to_port_lt_ceiling (int fd, struct sockaddr *sockaddr, - socklen_t sockaddr_len, int ceiling) -{ - int32_t ret = -1; - /* struct sockaddr_in sin = {0, }; */ - uint16_t port = ceiling - 1; - - while (port) - { - switch (sockaddr->sa_family) - { - case AF_INET6: - ((struct sockaddr_in6 *)sockaddr)->sin6_port = htons (port); - break; - - case AF_INET_SDP: - case AF_INET: - ((struct sockaddr_in *)sockaddr)->sin_port = htons (port); - break; - } - - ret = bind (fd, sockaddr, sockaddr_len); - - if (ret == 0) - break; - - if (ret == -1 && errno == EACCES) - break; - - port--; - } - - return ret; -} - -static int32_t -af_unix_client_bind (transport_t *this, - struct sockaddr *sockaddr, - socklen_t sockaddr_len, - int sock) -{ - data_t *path_data = NULL; - struct sockaddr_un *addr = NULL; - int32_t ret = -1; - - path_data = dict_get (this->xl->options, - "transport.ib-verbs.bind-path"); - if (path_data) { - char *path = data_to_str (path_data); - if (!path || strlen (path) > UNIX_PATH_MAX) { - gf_log (this->xl->name, GF_LOG_DEBUG, - "transport.ib-verbs.bind-path not specfied " - "for unix socket, letting connect to assign " - "default value"); - goto err; - } - - addr = (struct sockaddr_un *) sockaddr; - strcpy (addr->sun_path, path); - ret = bind (sock, (struct sockaddr *)addr, sockaddr_len); - if (ret == -1) { - gf_log (this->xl->name, GF_LOG_ERROR, - "cannot bind to unix-domain socket %d (%s)", - sock, strerror (errno)); - goto err; - } - } - -err: - return ret; -} - -static int32_t -client_fill_address_family (transport_t *this, struct sockaddr *sockaddr) -{ - data_t *address_family_data = NULL; - - address_family_data = dict_get (this->xl->options, - "transport.address-family"); - if (!address_family_data) { - data_t *remote_host_data = NULL, *connect_path_data = NULL; - remote_host_data = dict_get (this->xl->options, "remote-host"); - connect_path_data = dict_get (this->xl->options, - "transport.ib-verbs.connect-path"); - - if (!(remote_host_data || connect_path_data) || - (remote_host_data && connect_path_data)) { - gf_log (this->xl->name, GF_LOG_ERROR, - "address-family not specified and not able to " - "determine the same from other options " - "(remote-host:%s and connect-path:%s)", - data_to_str (remote_host_data), - data_to_str (connect_path_data)); - return -1; - } - - if (remote_host_data) { - gf_log (this->xl->name, GF_LOG_DEBUG, - "address-family not specified, guessing it " - "to be inet/inet6"); - sockaddr->sa_family = AF_UNSPEC; - } else { - gf_log (this->xl->name, GF_LOG_DEBUG, - "address-family not specified, guessing it " - "to be unix"); - sockaddr->sa_family = AF_UNIX; - } - - } else { - char *address_family = data_to_str (address_family_data); - if (!strcasecmp (address_family, "unix")) { - sockaddr->sa_family = AF_UNIX; - } else if (!strcasecmp (address_family, "inet")) { - sockaddr->sa_family = AF_INET; - } else if (!strcasecmp (address_family, "inet6")) { - sockaddr->sa_family = AF_INET6; - } else if (!strcasecmp (address_family, "inet-sdp")) { - sockaddr->sa_family = AF_INET_SDP; - } else if (!strcasecmp (address_family, "inet/inet6") - || !strcasecmp (address_family, "inet6/inet")) { - sockaddr->sa_family = AF_UNSPEC; - } else { - gf_log (this->xl->name, GF_LOG_ERROR, - "unknown address-family (%s) specified", - address_family); - return -1; - } - } - - return 0; -} - -static int32_t -af_inet_client_get_remote_sockaddr (transport_t *this, - struct sockaddr *sockaddr, - socklen_t *sockaddr_len) -{ - dict_t *options = this->xl->options; - data_t *remote_host_data = NULL; - data_t *remote_port_data = NULL; - char *remote_host = NULL; - uint16_t remote_port = 0; - struct addrinfo *addr_info = NULL; - int32_t ret = 0; - - remote_host_data = dict_get (options, "remote-host"); - if (remote_host_data == NULL) - { - gf_log (this->xl->name, GF_LOG_ERROR, - "option remote-host missing in volume %s", - this->xl->name); - ret = -1; - goto err; - } - - remote_host = data_to_str (remote_host_data); - if (remote_host == NULL) - { - gf_log (this->xl->name, GF_LOG_ERROR, - "option remote-host has data NULL in volume %s", - this->xl->name); - ret = -1; - goto err; - } - - remote_port_data = dict_get (options, "remote-port"); - if (remote_port_data == NULL) - { - gf_log (this->xl->name, GF_LOG_DEBUG, - "option remote-port missing in volume %s. " - "Defaulting to %d", - this->xl->name, GF_DEFAULT_IBVERBS_LISTEN_PORT); - - remote_port = GF_DEFAULT_IBVERBS_LISTEN_PORT; - } - else - { - remote_port = data_to_uint16 (remote_port_data); - } - - if (remote_port == (uint16_t)-1) - { - gf_log (this->xl->name, GF_LOG_ERROR, - "option remote-port has invalid port in volume %s", - this->xl->name); - ret = -1; - goto err; - } - - /* TODO: gf_resolve is a blocking call. kick in some - non blocking dns techniques */ - ret = gf_resolve_ip6 (remote_host, remote_port, - sockaddr->sa_family, - &this->dnscache, &addr_info); - if (ret == -1) { - gf_log (this->xl->name, GF_LOG_ERROR, - "DNS resolution failed on host %s", remote_host); - goto err; - } - - memcpy (sockaddr, addr_info->ai_addr, addr_info->ai_addrlen); - *sockaddr_len = addr_info->ai_addrlen; - -err: - return ret; -} - -static int32_t -af_unix_client_get_remote_sockaddr (transport_t *this, - struct sockaddr *sockaddr, - socklen_t *sockaddr_len) -{ - struct sockaddr_un *sockaddr_un = NULL; - char *connect_path = NULL; - data_t *connect_path_data = NULL; - int32_t ret = 0; - - connect_path_data = dict_get (this->xl->options, - "transport.ib-verbs.connect-path"); - if (!connect_path_data) { - gf_log (this->xl->name, GF_LOG_ERROR, - "option transport.ib-verbs.connect-path not " - "specified for address-family unix"); - ret = -1; - goto err; - } - - connect_path = data_to_str (connect_path_data); - if (!connect_path) { - gf_log (this->xl->name, GF_LOG_ERROR, - "connect-path is null-string"); - ret = -1; - goto err; - } - - if (strlen (connect_path) > UNIX_PATH_MAX) { - gf_log (this->xl->name, GF_LOG_ERROR, - "connect-path value length %"GF_PRI_SIZET" > " - "%d octets", strlen (connect_path), UNIX_PATH_MAX); - ret = -1; - goto err; - } - - gf_log (this->xl->name, - GF_LOG_DEBUG, - "using connect-path %s", connect_path); - sockaddr_un = (struct sockaddr_un *)sockaddr; - strcpy (sockaddr_un->sun_path, connect_path); - *sockaddr_len = sizeof (struct sockaddr_un); - -err: - return ret; -} - -static int32_t -af_unix_server_get_local_sockaddr (transport_t *this, - struct sockaddr *addr, - socklen_t *addr_len) -{ - data_t *listen_path_data = NULL; - char *listen_path = NULL; - int32_t ret = 0; - struct sockaddr_un *sunaddr = (struct sockaddr_un *)addr; - - - listen_path_data = dict_get (this->xl->options, - "transport.ib-verbs.listen-path"); - if (!listen_path_data) { - gf_log (this->xl->name, GF_LOG_ERROR, - "missing option listen-path"); - ret = -1; - goto err; - } - - listen_path = data_to_str (listen_path_data); - -#ifndef UNIX_PATH_MAX -#define UNIX_PATH_MAX 108 -#endif - - if (strlen (listen_path) > UNIX_PATH_MAX) { - gf_log (this->xl->name, GF_LOG_ERROR, - "option listen-path has value length %"GF_PRI_SIZET" > %d", - strlen (listen_path), UNIX_PATH_MAX); - ret = -1; - goto err; - } - - sunaddr->sun_family = AF_UNIX; - strcpy (sunaddr->sun_path, listen_path); - *addr_len = sizeof (struct sockaddr_un); - -err: - return ret; -} - -static int32_t -af_inet_server_get_local_sockaddr (transport_t *this, - struct sockaddr *addr, - socklen_t *addr_len) -{ - struct addrinfo hints, *res = 0; - data_t *listen_port_data = NULL, *listen_host_data = NULL; - uint16_t listen_port = -1; - char service[NI_MAXSERV], *listen_host = NULL; - dict_t *options = NULL; - int32_t ret = 0; - - options = this->xl->options; - - listen_port_data = dict_get (options, "transport.ib-verbs.listen-port"); - listen_host_data = dict_get (options, "transport.ib-verbs.bind-address"); - - if (listen_port_data) - { - listen_port = data_to_uint16 (listen_port_data); - } else { - if (addr->sa_family == AF_INET6) { - struct sockaddr_in6 *in = (struct sockaddr_in6 *) addr; - in->sin6_addr = in6addr_any; - in->sin6_port = htons(listen_port); - *addr_len = sizeof(struct sockaddr_in6); - goto out; - } else if (addr->sa_family == AF_INET) { - struct sockaddr_in *in = (struct sockaddr_in *) addr; - in->sin_addr.s_addr = htonl(INADDR_ANY); - in->sin_port = htons(listen_port); - *addr_len = sizeof(struct sockaddr_in); - goto out; - } - } - - if (listen_port == (uint16_t) -1) - listen_port = GF_DEFAULT_IBVERBS_LISTEN_PORT; - - - if (listen_host_data) - { - listen_host = data_to_str (listen_host_data); - } - - memset (service, 0, sizeof (service)); - sprintf (service, "%d", listen_port); - - memset (&hints, 0, sizeof (hints)); - hints.ai_family = addr->sa_family; - hints.ai_socktype = SOCK_STREAM; - hints.ai_flags = AI_ADDRCONFIG | AI_PASSIVE; - - ret = getaddrinfo(listen_host, service, &hints, &res); - if (ret != 0) { - gf_log (this->xl->name, - GF_LOG_ERROR, - "getaddrinfo failed for host %s, service %s (%s)", - listen_host, service, gai_strerror (ret)); - ret = -1; - goto out; - } - - memcpy (addr, res->ai_addr, res->ai_addrlen); - *addr_len = res->ai_addrlen; - - freeaddrinfo (res); - -out: - return ret; -} - -int32_t -gf_ibverbs_client_bind (transport_t *this, - struct sockaddr *sockaddr, - socklen_t *sockaddr_len, - int sock) -{ - int ret = 0; - - *sockaddr_len = sizeof (struct sockaddr_in6); - switch (sockaddr->sa_family) - { - case AF_INET_SDP: - case AF_INET: - *sockaddr_len = sizeof (struct sockaddr_in); - - case AF_INET6: - ret = af_inet_bind_to_port_lt_ceiling (sock, sockaddr, - *sockaddr_len, - CLIENT_PORT_CEILING); - if (ret == -1) { - gf_log (this->xl->name, GF_LOG_WARNING, - "cannot bind inet socket (%d) to port " - "less than %d (%s)", - sock, CLIENT_PORT_CEILING, strerror (errno)); - ret = 0; - } - break; - - case AF_UNIX: - *sockaddr_len = sizeof (struct sockaddr_un); - ret = af_unix_client_bind (this, (struct sockaddr *)sockaddr, - *sockaddr_len, sock); - break; - - default: - gf_log (this->xl->name, GF_LOG_ERROR, - "unknown address family %d", sockaddr->sa_family); - ret = -1; - break; - } - - return ret; -} - -int32_t -gf_ibverbs_client_get_remote_sockaddr (transport_t *this, - struct sockaddr *sockaddr, - socklen_t *sockaddr_len) -{ - int32_t ret = 0; - char is_inet_sdp = 0; - - ret = client_fill_address_family (this, sockaddr); - if (ret) { - ret = -1; - goto err; - } - - switch (sockaddr->sa_family) - { - case AF_INET_SDP: - sockaddr->sa_family = AF_INET; - is_inet_sdp = 1; - - case AF_INET: - case AF_INET6: - case AF_UNSPEC: - ret = af_inet_client_get_remote_sockaddr (this, - sockaddr, - sockaddr_len); - - if (is_inet_sdp) { - sockaddr->sa_family = AF_INET_SDP; - } - - break; - - case AF_UNIX: - ret = af_unix_client_get_remote_sockaddr (this, - sockaddr, - sockaddr_len); - break; - - default: - gf_log (this->xl->name, GF_LOG_ERROR, - "unknown address-family %d", sockaddr->sa_family); - ret = -1; - } - -err: - return ret; -} - -int32_t -gf_ibverbs_server_get_local_sockaddr (transport_t *this, - struct sockaddr *addr, - socklen_t *addr_len) -{ - data_t *address_family_data = NULL; - int32_t ret = 0; - char is_inet_sdp = 0; - - address_family_data = dict_get (this->xl->options, - "transport.address-family"); - if (address_family_data) { - char *address_family = NULL; - address_family = data_to_str (address_family_data); - - if (!strcasecmp (address_family, "inet")) { - addr->sa_family = AF_INET; - } else if (!strcasecmp (address_family, "inet6")) { - addr->sa_family = AF_INET6; - } else if (!strcasecmp (address_family, "inet-sdp")) { - addr->sa_family = AF_INET_SDP; - } else if (!strcasecmp (address_family, "unix")) { - addr->sa_family = AF_UNIX; - } else if (!strcasecmp (address_family, "inet/inet6") - || !strcasecmp (address_family, "inet6/inet")) { - addr->sa_family = AF_UNSPEC; - } else { - gf_log (this->xl->name, GF_LOG_ERROR, - "unknown address family (%s) specified", - address_family); - ret = -1; - goto err; - } - } else { - gf_log (this->xl->name, GF_LOG_DEBUG, - "option address-family not specified, defaulting " - "to inet/inet6"); - addr->sa_family = AF_UNSPEC; - } - - switch (addr->sa_family) - { - case AF_INET_SDP: - is_inet_sdp = 1; - addr->sa_family = AF_INET; - - case AF_INET: - case AF_INET6: - case AF_UNSPEC: - ret = af_inet_server_get_local_sockaddr (this, addr, addr_len); - if (is_inet_sdp && !ret) { - addr->sa_family = AF_INET_SDP; - } - break; - - case AF_UNIX: - ret = af_unix_server_get_local_sockaddr (this, addr, addr_len); - break; - } - -err: - return ret; -} - -int32_t -fill_inet6_inet_identifiers (transport_t *this, struct sockaddr_storage *addr, - int32_t addr_len, char *identifier) -{ - int32_t ret = 0, tmpaddr_len = 0; - char service[NI_MAXSERV], host[NI_MAXHOST]; - struct sockaddr_storage tmpaddr; - - memset (&tmpaddr, 0, sizeof (tmpaddr)); - tmpaddr = *addr; - tmpaddr_len = addr_len; - - if (((struct sockaddr *) &tmpaddr)->sa_family == AF_INET6) { - int32_t one_to_four, four_to_eight, twelve_to_sixteen; - int16_t eight_to_ten, ten_to_twelve; - - one_to_four = four_to_eight = twelve_to_sixteen = 0; - eight_to_ten = ten_to_twelve = 0; - - one_to_four = ((struct sockaddr_in6 *) - &tmpaddr)->sin6_addr.s6_addr32[0]; - four_to_eight = ((struct sockaddr_in6 *) - &tmpaddr)->sin6_addr.s6_addr32[1]; -#ifdef GF_SOLARIS_HOST_OS - eight_to_ten = S6_ADDR16(((struct sockaddr_in6 *) - &tmpaddr)->sin6_addr)[4]; -#else - eight_to_ten = ((struct sockaddr_in6 *) - &tmpaddr)->sin6_addr.s6_addr16[4]; -#endif - -#ifdef GF_SOLARIS_HOST_OS - ten_to_twelve = S6_ADDR16(((struct sockaddr_in6 *) - &tmpaddr)->sin6_addr)[5]; -#else - ten_to_twelve = ((struct sockaddr_in6 *) - &tmpaddr)->sin6_addr.s6_addr16[5]; -#endif - twelve_to_sixteen = ((struct sockaddr_in6 *) - &tmpaddr)->sin6_addr.s6_addr32[3]; - - /* ipv4 mapped ipv6 address has - bits 0-80: 0 - bits 80-96: 0xffff - bits 96-128: ipv4 address - */ - - if (one_to_four == 0 && - four_to_eight == 0 && - eight_to_ten == 0 && - ten_to_twelve == -1) { - struct sockaddr_in *in_ptr = (struct sockaddr_in *)&tmpaddr; - memset (&tmpaddr, 0, sizeof (tmpaddr)); - - in_ptr->sin_family = AF_INET; - in_ptr->sin_port = ((struct sockaddr_in6 *)addr)->sin6_port; - in_ptr->sin_addr.s_addr = twelve_to_sixteen; - tmpaddr_len = sizeof (*in_ptr); - } - } - - ret = getnameinfo ((struct sockaddr *) &tmpaddr, - tmpaddr_len, - host, sizeof (host), - service, sizeof (service), - NI_NUMERICHOST | NI_NUMERICSERV); - if (ret != 0) { - gf_log (this->xl->name, - GF_LOG_ERROR, - "getnameinfo failed (%s)", gai_strerror (ret)); - } - - sprintf (identifier, "%s:%s", host, service); - - return ret; -} - -int32_t -gf_ibverbs_get_transport_identifiers (transport_t *this) -{ - int32_t ret = 0; - char is_inet_sdp = 0; - - switch (((struct sockaddr *) &this->myinfo.sockaddr)->sa_family) - { - case AF_INET_SDP: - is_inet_sdp = 1; - ((struct sockaddr *) &this->peerinfo.sockaddr)->sa_family = ((struct sockaddr *) &this->myinfo.sockaddr)->sa_family = AF_INET; - - case AF_INET: - case AF_INET6: - { - ret = fill_inet6_inet_identifiers (this, - &this->myinfo.sockaddr, - this->myinfo.sockaddr_len, - this->myinfo.identifier); - if (ret == -1) { - gf_log (this->xl->name, GF_LOG_ERROR, - "can't fill inet/inet6 identifier for server"); - goto err; - } - - ret = fill_inet6_inet_identifiers (this, - &this->peerinfo.sockaddr, - this->peerinfo.sockaddr_len, - this->peerinfo.identifier); - if (ret == -1) { - gf_log (this->xl->name, GF_LOG_ERROR, - "can't fill inet/inet6 identifier for client"); - goto err; - } - - if (is_inet_sdp) { - ((struct sockaddr *) &this->peerinfo.sockaddr)->sa_family = ((struct sockaddr *) &this->myinfo.sockaddr)->sa_family = AF_INET_SDP; - } - } - break; - - case AF_UNIX: - { - struct sockaddr_un *sunaddr = NULL; - - sunaddr = (struct sockaddr_un *) &this->myinfo.sockaddr; - strcpy (this->myinfo.identifier, sunaddr->sun_path); - - sunaddr = (struct sockaddr_un *) &this->peerinfo.sockaddr; - strcpy (this->peerinfo.identifier, sunaddr->sun_path); - } - break; - - default: - gf_log (this->xl->name, GF_LOG_ERROR, - "unknown address family (%d)", - ((struct sockaddr *) &this->myinfo.sockaddr)->sa_family); - ret = -1; - break; - } - -err: - return ret; -} diff --git a/xlators/protocol/legacy/transport/ib-verbs/src/name.h b/xlators/protocol/legacy/transport/ib-verbs/src/name.h deleted file mode 100644 index e2575794bc7..00000000000 --- a/xlators/protocol/legacy/transport/ib-verbs/src/name.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - Copyright (c) 2008-2009 Gluster, Inc. <http://www.gluster.com> - This file is part of GlusterFS. - - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. -*/ - -#ifndef _IB_VERBS_NAME_H -#define _IB_VERBS_NAME_H - -#include <sys/socket.h> -#include <sys/un.h> - -#include "compat.h" - -int32_t -gf_ibverbs_client_bind (transport_t *this, - struct sockaddr *sockaddr, - socklen_t *sockaddr_len, - int sock); - -int32_t -gf_ibverbs_client_get_remote_sockaddr (transport_t *this, - struct sockaddr *sockaddr, - socklen_t *sockaddr_len); - -int32_t -gf_ibverbs_server_get_local_sockaddr (transport_t *this, - struct sockaddr *addr, - socklen_t *addr_len); - -int32_t -gf_ibverbs_get_transport_identifiers (transport_t *this); - -#endif /* _IB_VERBS_NAME_H */ diff --git a/xlators/protocol/legacy/transport/socket/Makefile.am b/xlators/protocol/legacy/transport/socket/Makefile.am deleted file mode 100644 index f963effea22..00000000000 --- a/xlators/protocol/legacy/transport/socket/Makefile.am +++ /dev/null @@ -1 +0,0 @@ -SUBDIRS = src
\ No newline at end of file diff --git a/xlators/protocol/legacy/transport/socket/src/Makefile.am b/xlators/protocol/legacy/transport/socket/src/Makefile.am deleted file mode 100644 index 5952e18e97b..00000000000 --- a/xlators/protocol/legacy/transport/socket/src/Makefile.am +++ /dev/null @@ -1,19 +0,0 @@ -# TODO : change to proper transport dir - -transport_LTLIBRARIES = socket.la -transportdir = $(libdir)/glusterfs/$(PACKAGE_VERSION)/transport - -socket_la_LDFLAGS = -module -avoidversion - -socket_la_SOURCES = socket.c name.c -socket_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la \ - $(top_builddir)/xlators/protocol/legacy/lib/src/libgfproto.la - -noinst_HEADERS = socket.h name.h socket-mem-types.h - -AM_CFLAGS = -fPIC -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -Wall -D$(GF_HOST_OS)\ - -I$(top_srcdir)/libglusterfs/src -shared -nostartfiles $(GF_CFLAGS) \ - -I$(top_srcdir)/xlators/protocol/legacy/transport/socket/src \ - -I$(top_srcdir)/xlators/protocol/legacy/lib/src - -CLEANFILES = *~ diff --git a/xlators/protocol/legacy/transport/socket/src/name.c b/xlators/protocol/legacy/transport/socket/src/name.c deleted file mode 100644 index b0fc7b4db3c..00000000000 --- a/xlators/protocol/legacy/transport/socket/src/name.c +++ /dev/null @@ -1,740 +0,0 @@ -/* - Copyright (c) 2008-2009 Gluster, Inc. <http://www.gluster.com> - This file is part of GlusterFS. - - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. -*/ - -#include <sys/types.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <errno.h> -#include <netdb.h> -#include <string.h> - -#ifdef CLIENT_PORT_CEILING -#undef CLIENT_PORT_CEILING -#endif - -#define CLIENT_PORT_CEILING 1024 - -#ifndef AF_INET_SDP -#define AF_INET_SDP 27 -#endif - -static int gf_name_addr_enotspec_log; - -#include "transport.h" -#include "socket.h" - -int32_t -gf_resolve_ip6 (const char *hostname, - uint16_t port, - int family, - void **dnscache, - struct addrinfo **addr_info); - -static int32_t -af_inet_bind_to_port_lt_ceiling (int fd, struct sockaddr *sockaddr, - socklen_t sockaddr_len, int ceiling) -{ - int32_t ret = -1; - /* struct sockaddr_in sin = {0, }; */ - uint16_t port = ceiling - 1; - - while (port) - { - switch (sockaddr->sa_family) - { - case AF_INET6: - ((struct sockaddr_in6 *)sockaddr)->sin6_port = htons (port); - break; - - case AF_INET_SDP: - case AF_INET: - ((struct sockaddr_in *)sockaddr)->sin_port = htons (port); - break; - } - - ret = bind (fd, sockaddr, sockaddr_len); - - if (ret == 0) - break; - - if (ret == -1 && errno == EACCES) - break; - - port--; - } - - return ret; -} - -static int32_t -af_unix_client_bind (transport_t *this, - struct sockaddr *sockaddr, - socklen_t sockaddr_len, - int sock) -{ - data_t *path_data = NULL; - struct sockaddr_un *addr = NULL; - int32_t ret = 0; - - path_data = dict_get (this->xl->options, "transport.socket.bind-path"); - if (path_data) { - char *path = data_to_str (path_data); - if (!path || strlen (path) > UNIX_PATH_MAX) { - gf_log (this->xl->name, GF_LOG_TRACE, - "bind-path not specfied for unix socket, " - "letting connect to assign default value"); - goto err; - } - - addr = (struct sockaddr_un *) sockaddr; - strcpy (addr->sun_path, path); - ret = bind (sock, (struct sockaddr *)addr, sockaddr_len); - if (ret == -1) { - gf_log (this->xl->name, GF_LOG_ERROR, - "cannot bind to unix-domain socket %d (%s)", - sock, strerror (errno)); - goto err; - } - } else { - gf_log (this->xl->name, GF_LOG_TRACE, - "bind-path not specfied for unix socket, " - "letting connect to assign default value"); - } - -err: - return ret; -} - -static int32_t -client_fill_address_family (transport_t *this, sa_family_t *sa_family) -{ - data_t *address_family_data = NULL; - int32_t ret = -1; - - if (sa_family == NULL) { - goto out; - } - - address_family_data = dict_get (this->xl->options, - "transport.address-family"); - if (!address_family_data) { - data_t *remote_host_data = NULL, *connect_path_data = NULL; - remote_host_data = dict_get (this->xl->options, "remote-host"); - connect_path_data = dict_get (this->xl->options, - "transport.socket.connect-path"); - - if (!(remote_host_data || connect_path_data) || - (remote_host_data && connect_path_data)) { - GF_LOG_OCCASIONALLY (gf_name_addr_enotspec_log, - this->xl->name, GF_LOG_ERROR, - "transport.address-family not specified and " - "not able to determine the " - "same from other options (remote-host:%s and " - "transport.unix.connect-path:%s)", - data_to_str (remote_host_data), - data_to_str (connect_path_data)); - goto out; - } - - if (remote_host_data) { - gf_log (this->xl->name, GF_LOG_DEBUG, - "address-family not specified, guessing it " - "to be inet/inet6"); - *sa_family = AF_UNSPEC; - } else { - gf_log (this->xl->name, GF_LOG_DEBUG, - "address-family not specified, guessing it " - "to be unix"); - *sa_family = AF_UNIX; - } - - } else { - char *address_family = data_to_str (address_family_data); - if (!strcasecmp (address_family, "unix")) { - *sa_family = AF_UNIX; - } else if (!strcasecmp (address_family, "inet")) { - *sa_family = AF_INET; - } else if (!strcasecmp (address_family, "inet6")) { - *sa_family = AF_INET6; - } else if (!strcasecmp (address_family, "inet-sdp")) { - *sa_family = AF_INET_SDP; - } else if (!strcasecmp (address_family, "inet/inet6") - || !strcasecmp (address_family, "inet6/inet")) { - *sa_family = AF_UNSPEC; - } else { - gf_log (this->xl->name, GF_LOG_ERROR, - "unknown address-family (%s) specified", - address_family); - goto out; - } - } - - ret = 0; - -out: - return ret; -} - -static int32_t -af_inet_client_get_remote_sockaddr (transport_t *this, - struct sockaddr *sockaddr, - socklen_t *sockaddr_len) -{ - dict_t *options = this->xl->options; - data_t *remote_host_data = NULL; - data_t *remote_port_data = NULL; - char *remote_host = NULL; - uint16_t remote_port = 0; - struct addrinfo *addr_info = NULL; - int32_t ret = 0; - - remote_host_data = dict_get (options, "remote-host"); - if (remote_host_data == NULL) - { - gf_log (this->xl->name, GF_LOG_ERROR, - "option remote-host missing in volume %s", this->xl->name); - ret = -1; - goto err; - } - - remote_host = data_to_str (remote_host_data); - if (remote_host == NULL) - { - gf_log (this->xl->name, GF_LOG_ERROR, - "option remote-host has data NULL in volume %s", this->xl->name); - ret = -1; - goto err; - } - - remote_port_data = dict_get (options, "remote-port"); - if (remote_port_data == NULL) - { - gf_log (this->xl->name, GF_LOG_TRACE, - "option remote-port missing in volume %s. Defaulting to %d", - this->xl->name, GF_DEFAULT_SOCKET_LISTEN_PORT); - - remote_port = GF_DEFAULT_SOCKET_LISTEN_PORT; - } - else - { - remote_port = data_to_uint16 (remote_port_data); - } - - if (remote_port == (uint16_t)-1) - { - gf_log (this->xl->name, GF_LOG_ERROR, - "option remote-port has invalid port in volume %s", - this->xl->name); - ret = -1; - goto err; - } - - /* TODO: gf_resolve is a blocking call. kick in some - non blocking dns techniques */ - ret = gf_resolve_ip6 (remote_host, remote_port, - sockaddr->sa_family, &this->dnscache, &addr_info); - if (ret == -1) { - gf_log (this->xl->name, GF_LOG_ERROR, - "DNS resolution failed on host %s", remote_host); - goto err; - } - - memcpy (sockaddr, addr_info->ai_addr, addr_info->ai_addrlen); - *sockaddr_len = addr_info->ai_addrlen; - -err: - return ret; -} - -static int32_t -af_unix_client_get_remote_sockaddr (transport_t *this, - struct sockaddr *sockaddr, - socklen_t *sockaddr_len) -{ - struct sockaddr_un *sockaddr_un = NULL; - char *connect_path = NULL; - data_t *connect_path_data = NULL; - int32_t ret = 0; - - connect_path_data = dict_get (this->xl->options, - "transport.socket.connect-path"); - if (!connect_path_data) { - gf_log (this->xl->name, GF_LOG_ERROR, - "option transport.unix.connect-path not specified for " - "address-family unix"); - ret = -1; - goto err; - } - - connect_path = data_to_str (connect_path_data); - if (!connect_path) { - gf_log (this->xl->name, GF_LOG_ERROR, - "transport.unix.connect-path is null-string"); - ret = -1; - goto err; - } - - if (strlen (connect_path) > UNIX_PATH_MAX) { - gf_log (this->xl->name, GF_LOG_ERROR, - "connect-path value length %"GF_PRI_SIZET" > %d octets", - strlen (connect_path), UNIX_PATH_MAX); - ret = -1; - goto err; - } - - gf_log (this->xl->name, GF_LOG_TRACE, - "using connect-path %s", connect_path); - sockaddr_un = (struct sockaddr_un *)sockaddr; - strcpy (sockaddr_un->sun_path, connect_path); - *sockaddr_len = sizeof (struct sockaddr_un); - -err: - return ret; -} - -static int32_t -af_unix_server_get_local_sockaddr (transport_t *this, - struct sockaddr *addr, - socklen_t *addr_len) -{ - data_t *listen_path_data = NULL; - char *listen_path = NULL; - int32_t ret = 0; - struct sockaddr_un *sunaddr = (struct sockaddr_un *)addr; - - - listen_path_data = dict_get (this->xl->options, - "transport.socket.listen-path"); - if (!listen_path_data) { - gf_log (this->xl->name, GF_LOG_ERROR, - "missing option transport.socket.listen-path"); - ret = -1; - goto err; - } - - listen_path = data_to_str (listen_path_data); - -#ifndef UNIX_PATH_MAX -#define UNIX_PATH_MAX 108 -#endif - - if (strlen (listen_path) > UNIX_PATH_MAX) { - gf_log (this->xl->name, GF_LOG_ERROR, - "option transport.unix.listen-path has value length " - "%"GF_PRI_SIZET" > %d", - strlen (listen_path), UNIX_PATH_MAX); - ret = -1; - goto err; - } - - sunaddr->sun_family = AF_UNIX; - strcpy (sunaddr->sun_path, listen_path); - *addr_len = sizeof (struct sockaddr_un); - -err: - return ret; -} - -static int32_t -af_inet_server_get_local_sockaddr (transport_t *this, - struct sockaddr *addr, - socklen_t *addr_len) -{ - struct addrinfo hints, *res = 0; - data_t *listen_port_data = NULL, *listen_host_data = NULL; - uint16_t listen_port = -1; - char service[NI_MAXSERV], *listen_host = NULL; - dict_t *options = NULL; - int32_t ret = 0; - - options = this->xl->options; - - listen_port_data = dict_get (options, "transport.socket.listen-port"); - listen_host_data = dict_get (options, "transport.socket.bind-address"); - - if (listen_port_data) - { - listen_port = data_to_uint16 (listen_port_data); - } - - if (listen_port == (uint16_t) -1) - listen_port = GF_DEFAULT_SOCKET_LISTEN_PORT; - - - if (listen_host_data) - { - listen_host = data_to_str (listen_host_data); - } else { - if (addr->sa_family == AF_INET6) { - struct sockaddr_in6 *in = (struct sockaddr_in6 *) addr; - in->sin6_addr = in6addr_any; - in->sin6_port = htons(listen_port); - *addr_len = sizeof(struct sockaddr_in6); - goto out; - } else if (addr->sa_family == AF_INET) { - struct sockaddr_in *in = (struct sockaddr_in *) addr; - in->sin_addr.s_addr = htonl(INADDR_ANY); - in->sin_port = htons(listen_port); - *addr_len = sizeof(struct sockaddr_in); - goto out; - } - } - - memset (service, 0, sizeof (service)); - sprintf (service, "%d", listen_port); - - memset (&hints, 0, sizeof (hints)); - hints.ai_family = addr->sa_family; - hints.ai_socktype = SOCK_STREAM; - hints.ai_flags = AI_ADDRCONFIG | AI_PASSIVE; - - ret = getaddrinfo(listen_host, service, &hints, &res); - if (ret != 0) { - gf_log (this->xl->name, GF_LOG_ERROR, - "getaddrinfo failed for host %s, service %s (%s)", - listen_host, service, gai_strerror (ret)); - ret = -1; - goto out; - } - - memcpy (addr, res->ai_addr, res->ai_addrlen); - *addr_len = res->ai_addrlen; - - freeaddrinfo (res); - -out: - return ret; -} - -int32_t -gf_client_bind (transport_t *this, - struct sockaddr *sockaddr, - socklen_t *sockaddr_len, - int sock) -{ - int ret = 0; - - *sockaddr_len = sizeof (struct sockaddr_in6); - switch (sockaddr->sa_family) - { - case AF_INET_SDP: - case AF_INET: - *sockaddr_len = sizeof (struct sockaddr_in); - - case AF_INET6: - ret = af_inet_bind_to_port_lt_ceiling (sock, sockaddr, - *sockaddr_len, CLIENT_PORT_CEILING); - if (ret == -1) { - gf_log (this->xl->name, GF_LOG_WARNING, - "cannot bind inet socket (%d) to port less than %d (%s)", - sock, CLIENT_PORT_CEILING, strerror (errno)); - ret = 0; - } - break; - - case AF_UNIX: - *sockaddr_len = sizeof (struct sockaddr_un); - ret = af_unix_client_bind (this, (struct sockaddr *)sockaddr, - *sockaddr_len, sock); - break; - - default: - gf_log (this->xl->name, GF_LOG_ERROR, - "unknown address family %d", sockaddr->sa_family); - ret = -1; - break; - } - - return ret; -} - -int32_t -gf_socket_client_get_remote_sockaddr (transport_t *this, - struct sockaddr *sockaddr, - socklen_t *sockaddr_len, - sa_family_t *sa_family) -{ - int32_t ret = 0; - - if ((sockaddr == NULL) || (sockaddr_len == NULL) - || (sa_family == NULL)) { - ret = -1; - goto err; - } - - - ret = client_fill_address_family (this, &sockaddr->sa_family); - if (ret) { - ret = -1; - goto err; - } - - *sa_family = sockaddr->sa_family; - - switch (sockaddr->sa_family) - { - case AF_INET_SDP: - sockaddr->sa_family = AF_INET; - - case AF_INET: - case AF_INET6: - case AF_UNSPEC: - ret = af_inet_client_get_remote_sockaddr (this, sockaddr, - sockaddr_len); - break; - - case AF_UNIX: - ret = af_unix_client_get_remote_sockaddr (this, sockaddr, - sockaddr_len); - break; - - default: - gf_log (this->xl->name, GF_LOG_ERROR, - "unknown address-family %d", sockaddr->sa_family); - ret = -1; - } - - if (*sa_family == AF_UNSPEC) { - *sa_family = sockaddr->sa_family; - } - -err: - return ret; -} - - -static int32_t -server_fill_address_family (transport_t *this, sa_family_t *sa_family) -{ - data_t *address_family_data = NULL; - int32_t ret = -1; - - if (sa_family == NULL) { - goto out; - } - - address_family_data = dict_get (this->xl->options, - "transport.address-family"); - if (address_family_data) { - char *address_family = NULL; - address_family = data_to_str (address_family_data); - - if (!strcasecmp (address_family, "inet")) { - *sa_family = AF_INET; - } else if (!strcasecmp (address_family, "inet6")) { - *sa_family = AF_INET6; - } else if (!strcasecmp (address_family, "inet-sdp")) { - *sa_family = AF_INET_SDP; - } else if (!strcasecmp (address_family, "unix")) { - *sa_family = AF_UNIX; - } else if (!strcasecmp (address_family, "inet/inet6") - || !strcasecmp (address_family, "inet6/inet")) { - *sa_family = AF_UNSPEC; - } else { - gf_log (this->xl->name, GF_LOG_ERROR, - "unknown address family (%s) specified", address_family); - goto out; - } - } else { - gf_log (this->xl->name, GF_LOG_DEBUG, - "option address-family not specified, defaulting to inet/inet6"); - *sa_family = AF_UNSPEC; - } - - ret = 0; -out: - return ret; -} - - -int32_t -gf_socket_server_get_local_sockaddr (transport_t *this, struct sockaddr *addr, - socklen_t *addr_len, sa_family_t *sa_family) -{ - int32_t ret = -1; - - if ((addr == NULL) || (addr_len == NULL) || (sa_family == NULL)) { - goto err; - } - - ret = server_fill_address_family (this, &addr->sa_family); - if (ret == -1) { - goto err; - } - - *sa_family = addr->sa_family; - - switch (addr->sa_family) - { - case AF_INET_SDP: - addr->sa_family = AF_INET; - - case AF_INET: - case AF_INET6: - case AF_UNSPEC: - ret = af_inet_server_get_local_sockaddr (this, addr, addr_len); - break; - - case AF_UNIX: - ret = af_unix_server_get_local_sockaddr (this, addr, addr_len); - break; - } - - if (*sa_family == AF_UNSPEC) { - *sa_family = addr->sa_family; - } - -err: - return ret; -} - -static int32_t -fill_inet6_inet_identifiers (transport_t *this, struct sockaddr_storage *addr, - int32_t addr_len, char *identifier) -{ - int32_t ret = 0, tmpaddr_len = 0; - char service[NI_MAXSERV], host[NI_MAXHOST]; - struct sockaddr_storage tmpaddr; - - memset (&tmpaddr, 0, sizeof (tmpaddr)); - tmpaddr = *addr; - tmpaddr_len = addr_len; - - if (((struct sockaddr *) &tmpaddr)->sa_family == AF_INET6) { - int32_t one_to_four, four_to_eight, twelve_to_sixteen; - int16_t eight_to_ten, ten_to_twelve; - - one_to_four = four_to_eight = twelve_to_sixteen = 0; - eight_to_ten = ten_to_twelve = 0; - - one_to_four = ((struct sockaddr_in6 *) &tmpaddr)->sin6_addr.s6_addr32[0]; - four_to_eight = ((struct sockaddr_in6 *) &tmpaddr)->sin6_addr.s6_addr32[1]; -#ifdef GF_SOLARIS_HOST_OS - eight_to_ten = S6_ADDR16(((struct sockaddr_in6 *) &tmpaddr)->sin6_addr)[4]; -#else - eight_to_ten = ((struct sockaddr_in6 *) &tmpaddr)->sin6_addr.s6_addr16[4]; -#endif - -#ifdef GF_SOLARIS_HOST_OS - ten_to_twelve = S6_ADDR16(((struct sockaddr_in6 *) &tmpaddr)->sin6_addr)[5]; -#else - ten_to_twelve = ((struct sockaddr_in6 *) &tmpaddr)->sin6_addr.s6_addr16[5]; -#endif - - twelve_to_sixteen = ((struct sockaddr_in6 *) &tmpaddr)->sin6_addr.s6_addr32[3]; - - /* ipv4 mapped ipv6 address has - bits 0-80: 0 - bits 80-96: 0xffff - bits 96-128: ipv4 address - */ - - if (one_to_four == 0 && - four_to_eight == 0 && - eight_to_ten == 0 && - ten_to_twelve == -1) { - struct sockaddr_in *in_ptr = (struct sockaddr_in *)&tmpaddr; - memset (&tmpaddr, 0, sizeof (tmpaddr)); - - in_ptr->sin_family = AF_INET; - in_ptr->sin_port = ((struct sockaddr_in6 *)addr)->sin6_port; - in_ptr->sin_addr.s_addr = twelve_to_sixteen; - tmpaddr_len = sizeof (*in_ptr); - } - } - - ret = getnameinfo ((struct sockaddr *) &tmpaddr, - tmpaddr_len, - host, sizeof (host), - service, sizeof (service), - NI_NUMERICHOST | NI_NUMERICSERV); - if (ret != 0) { - gf_log (this->xl->name, GF_LOG_ERROR, - "getnameinfo failed (%s)", gai_strerror (ret)); - } - - sprintf (identifier, "%s:%s", host, service); - - return ret; -} - -int32_t -gf_get_transport_identifiers (transport_t *this) -{ - int32_t ret = 0; - char is_inet_sdp = 0; - - switch (((struct sockaddr *) &this->myinfo.sockaddr)->sa_family) - { - case AF_INET_SDP: - is_inet_sdp = 1; - ((struct sockaddr *) &this->peerinfo.sockaddr)->sa_family = ((struct sockaddr *) &this->myinfo.sockaddr)->sa_family = AF_INET; - - case AF_INET: - case AF_INET6: - { - ret = fill_inet6_inet_identifiers (this, - &this->myinfo.sockaddr, - this->myinfo.sockaddr_len, - this->myinfo.identifier); - if (ret == -1) { - gf_log (this->xl->name, GF_LOG_ERROR, - "cannot fill inet/inet6 identifier for server"); - goto err; - } - - ret = fill_inet6_inet_identifiers (this, - &this->peerinfo.sockaddr, - this->peerinfo.sockaddr_len, - this->peerinfo.identifier); - if (ret == -1) { - gf_log (this->xl->name, GF_LOG_ERROR, - "cannot fill inet/inet6 identifier for client"); - goto err; - } - - if (is_inet_sdp) { - ((struct sockaddr *) &this->peerinfo.sockaddr)->sa_family = ((struct sockaddr *) &this->myinfo.sockaddr)->sa_family = AF_INET_SDP; - } - } - break; - - case AF_UNIX: - { - struct sockaddr_un *sunaddr = NULL; - - sunaddr = (struct sockaddr_un *) &this->myinfo.sockaddr; - strcpy (this->myinfo.identifier, sunaddr->sun_path); - - sunaddr = (struct sockaddr_un *) &this->peerinfo.sockaddr; - strcpy (this->peerinfo.identifier, sunaddr->sun_path); - } - break; - - default: - gf_log (this->xl->name, GF_LOG_ERROR, - "unknown address family (%d)", - ((struct sockaddr *) &this->myinfo.sockaddr)->sa_family); - ret = -1; - break; - } - -err: - return ret; -} diff --git a/xlators/protocol/legacy/transport/socket/src/name.h b/xlators/protocol/legacy/transport/socket/src/name.h deleted file mode 100644 index 1853781bd7c..00000000000 --- a/xlators/protocol/legacy/transport/socket/src/name.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - Copyright (c) 2008-2009 Gluster, Inc. <http://www.gluster.com> - This file is part of GlusterFS. - - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. -*/ - -#ifndef _SOCKET_NAME_H -#define _SOCKET_NAME_H - -#include "compat.h" - -int32_t -gf_client_bind (transport_t *this, - struct sockaddr *sockaddr, - socklen_t *sockaddr_len, - int sock); - -int32_t -gf_socket_client_get_remote_sockaddr (transport_t *this, - struct sockaddr *sockaddr, - socklen_t *sockaddr_len, - sa_family_t *sa_family); - -int32_t -gf_socket_server_get_local_sockaddr (transport_t *this, struct sockaddr *addr, - socklen_t *addr_len, sa_family_t *sa_family); - -int32_t -gf_get_transport_identifiers (transport_t *this); - -#endif /* _SOCKET_NAME_H */ diff --git a/xlators/protocol/legacy/transport/socket/src/socket-mem-types.h b/xlators/protocol/legacy/transport/socket/src/socket-mem-types.h deleted file mode 100644 index f50f4a75de8..00000000000 --- a/xlators/protocol/legacy/transport/socket/src/socket-mem-types.h +++ /dev/null @@ -1,36 +0,0 @@ - -/* - Copyright (c) 2008-2009 Gluster, Inc. <http://www.gluster.com> - This file is part of GlusterFS. - - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. -*/ - - -#ifndef __SOCKET_MEM_TYPES_H__ -#define __SOCKET_MEM_TYPES_H__ - -#include "mem-types.h" - -enum gf_socket_mem_types_ { - gf_socket_mt_socket_private_t = gf_common_mt_end + 1, - gf_socket_mt_ioq, - gf_socket_mt_transport_t, - gf_socket_mt_socket_local_t, - gf_socket_mt_char, - gf_socket_mt_end -}; -#endif - diff --git a/xlators/protocol/legacy/transport/socket/src/socket.c b/xlators/protocol/legacy/transport/socket/src/socket.c deleted file mode 100644 index 128b1ce6997..00000000000 --- a/xlators/protocol/legacy/transport/socket/src/socket.c +++ /dev/null @@ -1,1622 +0,0 @@ -/* - Copyright (c) 2008-2009 Gluster, Inc. <http://www.gluster.com> - This file is part of GlusterFS. - - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. -*/ - - -#ifndef _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif - -#include "socket.h" -#include "name.h" -#include "dict.h" -#include "transport.h" -#include "logging.h" -#include "xlator.h" -#include "byte-order.h" -#include "common-utils.h" -#include "compat-errno.h" - -#include <fcntl.h> -#include <errno.h> -#include <netinet/tcp.h> - - -#define GF_LOG_ERRNO(errno) ((errno == ENOTCONN) ? GF_LOG_DEBUG : GF_LOG_ERROR) -#define SA(ptr) ((struct sockaddr *)ptr) - -static int socket_init (transport_t *this); - -/* - * return value: - * 0 = success (completed) - * -1 = error - * > 0 = incomplete - */ - -static int -__socket_rwv (transport_t *this, struct iovec *vector, int count, - struct iovec **pending_vector, int *pending_count, - int write) -{ - socket_private_t *priv = NULL; - int sock = -1; - int ret = -1; - struct iovec *opvector = NULL; - int opcount = 0; - int moved = 0; - - priv = this->private; - sock = priv->sock; - - opvector = vector; - opcount = count; - - while (opcount) { - if (write) { - ret = writev (sock, opvector, opcount); - - if (ret == 0 || (ret == -1 && errno == EAGAIN)) { - /* done for now */ - break; - } - } else { - ret = readv (sock, opvector, opcount); - - if (ret == -1 && errno == EAGAIN) { - /* done for now */ - break; - } - } - - if (ret == 0) { - /* Mostly due to 'umount' in client */ - gf_log (this->xl->name, GF_LOG_TRACE, - "EOF from peer %s", this->peerinfo.identifier); - opcount = -1; - errno = ENOTCONN; - break; - } - - if (ret == -1) { - if (errno == EINTR) - continue; - - gf_log (this->xl->name, GF_LOG_TRACE, - "%s failed (%s)", write ? "writev" : "readv", - strerror (errno)); - opcount = -1; - break; - } - - moved = 0; - - while (moved < ret) { - if ((ret - moved) >= opvector[0].iov_len) { - moved += opvector[0].iov_len; - opvector++; - opcount--; - } else { - opvector[0].iov_len -= (ret - moved); - opvector[0].iov_base += (ret - moved); - moved += (ret - moved); - } - while (opcount && !opvector[0].iov_len) { - opvector++; - opcount--; - } - } - } - - if (pending_vector) - *pending_vector = opvector; - - if (pending_count) - *pending_count = opcount; - - return opcount; -} - - -static int -__socket_readv (transport_t *this, struct iovec *vector, int count, - struct iovec **pending_vector, int *pending_count) -{ - int ret = -1; - - ret = __socket_rwv (this, vector, count, - pending_vector, pending_count, 0); - - return ret; -} - - -static int -__socket_writev (transport_t *this, struct iovec *vector, int count, - struct iovec **pending_vector, int *pending_count) -{ - int ret = -1; - - ret = __socket_rwv (this, vector, count, - pending_vector, pending_count, 1); - - return ret; -} - - -static int -__socket_disconnect (transport_t *this) -{ - socket_private_t *priv = NULL; - int ret = -1; - - priv = this->private; - - if (priv->sock != -1) { - ret = shutdown (priv->sock, SHUT_RDWR); - priv->connected = -1; - gf_log (this->xl->name, GF_LOG_TRACE, - "shutdown() returned %d. set connection state to -1", - ret); - } - - return ret; -} - - -static int -__socket_server_bind (transport_t *this) -{ - socket_private_t *priv = NULL; - int ret = -1; - int opt = 1; - - priv = this->private; - - ret = setsockopt (priv->sock, SOL_SOCKET, SO_REUSEADDR, - &opt, sizeof (opt)); - - if (ret == -1) { - gf_log (this->xl->name, GF_LOG_ERROR, - "setsockopt() for SO_REUSEADDR failed (%s)", - strerror (errno)); - } - - ret = bind (priv->sock, (struct sockaddr *)&this->myinfo.sockaddr, - this->myinfo.sockaddr_len); - - if (ret == -1) { - gf_log (this->xl->name, GF_LOG_ERROR, - "binding to %s failed: %s", - this->myinfo.identifier, strerror (errno)); - if (errno == EADDRINUSE) { - gf_log (this->xl->name, GF_LOG_ERROR, - "Port is already in use"); - } - } - - return ret; -} - - -static int -__socket_nonblock (int fd) -{ - int flags = 0; - int ret = -1; - - flags = fcntl (fd, F_GETFL); - - if (flags != -1) - ret = fcntl (fd, F_SETFL, flags | O_NONBLOCK); - - return ret; -} - - -static int -__socket_nodelay (int fd) -{ - int on = 1; - int ret = -1; - - ret = setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, - &on, sizeof (on)); - if (!ret) - gf_log ("", GF_LOG_TRACE, - "NODELAY enabled for socket %d", fd); - - return ret; -} - - -static int -__socket_keepalive (int fd, int keepalive_intvl) -{ - int on = 1; - int ret = -1; - - ret = setsockopt (fd, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof (on)); - if (ret == -1) - goto err; - - if (keepalive_intvl == GF_USE_DEFAULT_KEEPALIVE) - goto done; - -#ifndef GF_LINUX_HOST_OS - ret = setsockopt (fd, IPPROTO_TCP, TCP_KEEPALIVE, &keepalive_intvl, - sizeof (keepalive_intvl)); - if (ret == -1) - goto err; -#else - ret = setsockopt (fd, IPPROTO_TCP, TCP_KEEPIDLE, &keepalive_intvl, - sizeof (keepalive_intvl)); - if (ret == -1) - goto err; - - ret = setsockopt (fd, IPPROTO_TCP, TCP_KEEPINTVL, &keepalive_intvl, - sizeof (keepalive_intvl)); - if (ret == -1) - goto err; -#endif - -done: - gf_log ("", GF_LOG_TRACE, "Keep-alive enabled for socket %d, interval " - "%d", fd, keepalive_intvl); - -err: - return ret; -} - - -static int -__socket_connect_finish (int fd) -{ - int ret = -1; - int optval = 0; - socklen_t optlen = sizeof (int); - - ret = getsockopt (fd, SOL_SOCKET, SO_ERROR, (void *)&optval, &optlen); - - if (ret == 0 && optval) { - errno = optval; - ret = -1; - } - - return ret; -} - - -static void -__socket_reset (transport_t *this) -{ - socket_private_t *priv = NULL; - - priv = this->private; - - /* TODO: use mem-pool on incoming data */ - - if (priv->incoming.hdr_p) - GF_FREE (priv->incoming.hdr_p); - - if (priv->incoming.iobuf) - iobuf_unref (priv->incoming.iobuf); - - memset (&priv->incoming, 0, sizeof (priv->incoming)); - - event_unregister (this->xl->ctx->event_pool, priv->sock, priv->idx); - close (priv->sock); - priv->sock = -1; - priv->idx = -1; - priv->connected = -1; -} - - -static struct ioq * -__socket_ioq_new (transport_t *this, char *buf, int len, - struct iovec *vector, int count, struct iobref *iobref) -{ - socket_private_t *priv = NULL; - struct ioq *entry = NULL; - - priv = this->private; - - /* TODO: use mem-pool */ - entry = GF_CALLOC (1, sizeof (*entry), - gf_common_mt_ioq); - if (!entry) - return NULL; - - assert (count <= (MAX_IOVEC-2)); - - entry->header.colonO[0] = ':'; - entry->header.colonO[1] = 'O'; - entry->header.colonO[2] = '\0'; - entry->header.version = 42; - entry->header.size1 = hton32 (len); - entry->header.size2 = hton32 (iov_length (vector, count)); - - entry->vector[0].iov_base = &entry->header; - entry->vector[0].iov_len = sizeof (entry->header); - entry->count++; - - entry->vector[1].iov_base = buf; - entry->vector[1].iov_len = len; - entry->count++; - - if (vector && count) { - memcpy (&entry->vector[2], vector, sizeof (*vector) * count); - entry->count += count; - } - - entry->pending_vector = entry->vector; - entry->pending_count = entry->count; - - if (iobref) - entry->iobref = iobref_ref (iobref); - - entry->buf = buf; - - INIT_LIST_HEAD (&entry->list); - - return entry; -} - - -static void -__socket_ioq_entry_free (struct ioq *entry) -{ - list_del_init (&entry->list); - if (entry->iobref) - iobref_unref (entry->iobref); - - /* TODO: use mem-pool */ - GF_FREE (entry->buf); - - /* TODO: use mem-pool */ - GF_FREE (entry); -} - - -static void -__socket_ioq_flush (transport_t *this) -{ - socket_private_t *priv = NULL; - struct ioq *entry = NULL; - - priv = this->private; - - while (!list_empty (&priv->ioq)) { - entry = priv->ioq_next; - __socket_ioq_entry_free (entry); - } - - return; -} - - -static int -__socket_ioq_churn_entry (transport_t *this, struct ioq *entry) -{ - int ret = -1; - - ret = __socket_writev (this, entry->pending_vector, - entry->pending_count, - &entry->pending_vector, - &entry->pending_count); - - if (ret == 0) { - /* current entry was completely written */ - assert (entry->pending_count == 0); - __socket_ioq_entry_free (entry); - } - - return ret; -} - - -static int -__socket_ioq_churn (transport_t *this) -{ - socket_private_t *priv = NULL; - int ret = 0; - struct ioq *entry = NULL; - - priv = this->private; - - while (!list_empty (&priv->ioq)) { - /* pick next entry */ - entry = priv->ioq_next; - - ret = __socket_ioq_churn_entry (this, entry); - - if (ret != 0) - break; - } - - if (list_empty (&priv->ioq)) { - /* all pending writes done, not interested in POLLOUT */ - priv->idx = event_select_on (this->xl->ctx->event_pool, - priv->sock, priv->idx, -1, 0); - } - - return ret; -} - - -static int -socket_event_poll_err (transport_t *this) -{ - socket_private_t *priv = NULL; - int ret = -1; - - priv = this->private; - - pthread_mutex_lock (&priv->lock); - { - __socket_ioq_flush (this); - __socket_reset (this); - } - pthread_mutex_unlock (&priv->lock); - - xlator_notify (this->xl, GF_EVENT_POLLERR, this); - - return ret; -} - - -static int -socket_event_poll_out (transport_t *this) -{ - socket_private_t *priv = NULL; - int ret = -1; - - priv = this->private; - - pthread_mutex_lock (&priv->lock); - { - if (priv->connected == 1) { - ret = __socket_ioq_churn (this); - - if (ret == -1) { - __socket_disconnect (this); - } - } - } - pthread_mutex_unlock (&priv->lock); - - xlator_notify (this->xl, GF_EVENT_POLLOUT, this); - - return ret; -} - - -static int -__socket_proto_validate_header (transport_t *this, - struct socket_header *header, - size_t *size1_p, size_t *size2_p) -{ - size_t size1 = 0; - size_t size2 = 0; - - if (strcmp (header->colonO, ":O")) { - gf_log (this->xl->name, GF_LOG_DEBUG, - "socket header signature does not match :O (%x.%x.%x)", - header->colonO[0], header->colonO[1], - header->colonO[2]); - return -1; - } - - if (header->version != 42) { - gf_log (this->xl->name, GF_LOG_DEBUG, - "socket header version does not match 42 != %d", - header->version); - return -1; - } - - size1 = ntoh32 (header->size1); - size2 = ntoh32 (header->size2); - - if (size1 <= 0 || size1 > 1048576) { - gf_log (this->xl->name, GF_LOG_DEBUG, - "socket header has incorrect size1=%"GF_PRI_SIZET, - size1); - return -1; - } - - if (size2 > (131072)) { - gf_log (this->xl->name, GF_LOG_DEBUG, - "socket header has incorrect size2=%"GF_PRI_SIZET, - size2); - return -1; - } - - if (size1_p) - *size1_p = size1; - - if (size2_p) - *size2_p = size2; - - return 0; -} - - - -/* socket protocol state machine */ - -static int -__socket_proto_state_machine (transport_t *this) -{ - int ret = -1; - socket_private_t *priv = NULL; - size_t size1 = 0; - size_t size2 = 0; - int previous_state = -1; - struct socket_header *hdr = NULL; - struct iobuf *iobuf = NULL; - - - priv = this->private; - - while (priv->incoming.state != SOCKET_PROTO_STATE_COMPLETE) { - /* debug check against infinite loops */ - if (previous_state == priv->incoming.state) { - gf_log (this->xl->name, GF_LOG_DEBUG, - "state did not change! (%d) breaking", - previous_state); - ret = -1; - goto unlock; - } - previous_state = priv->incoming.state; - - switch (priv->incoming.state) { - - case SOCKET_PROTO_STATE_NADA: - priv->incoming.pending_vector = - priv->incoming.vector; - - priv->incoming.pending_vector->iov_base = - &priv->incoming.header; - - priv->incoming.pending_vector->iov_len = - sizeof (struct socket_header); - - priv->incoming.state = - SOCKET_PROTO_STATE_HEADER_COMING; - break; - - case SOCKET_PROTO_STATE_HEADER_COMING: - - ret = __socket_readv (this, - priv->incoming.pending_vector, 1, - &priv->incoming.pending_vector, - NULL); - if (ret == 0) { - priv->incoming.state = - SOCKET_PROTO_STATE_HEADER_CAME; - break; - } - - if (ret == -1) { - gf_log (this->xl->name, GF_LOG_TRACE, - "read (%s) in state %d (%s)", - strerror (errno), - SOCKET_PROTO_STATE_HEADER_COMING, - this->peerinfo.identifier); - goto unlock; - } - - if (ret > 0) { - gf_log (this->xl->name, GF_LOG_TRACE, - "partial header read on NB socket."); - goto unlock; - } - break; - - case SOCKET_PROTO_STATE_HEADER_CAME: - hdr = &priv->incoming.header; - ret = __socket_proto_validate_header (this, hdr, - &size1, &size2); - - if (ret == -1) { - gf_log (this->xl->name, GF_LOG_ERROR, - "socket header validate failed (%s). " - "possible mismatch of transport-type " - "between server and client volumes, " - "or version mismatch", - this->peerinfo.identifier); - goto unlock; - } - - priv->incoming.hdrlen = size1; - priv->incoming.buflen = size2; - - /* TODO: use mem-pool */ - priv->incoming.hdr_p = GF_MALLOC (size1, - gf_common_mt_char); - if (size2) { - /* TODO: sanity check size2 < page size - */ - iobuf = iobuf_get (this->xl->ctx->iobuf_pool); - if (!iobuf) { - gf_log (this->xl->name, GF_LOG_ERROR, - "unable to allocate IO buffer " - "for peer %s", - this->peerinfo.identifier); - ret = -ENOMEM; - goto unlock; - } - priv->incoming.iobuf = iobuf; - priv->incoming.buf_p = iobuf->ptr; - } - - priv->incoming.vector[0].iov_base = - priv->incoming.hdr_p; - - priv->incoming.vector[0].iov_len = size1; - - priv->incoming.vector[1].iov_base = - priv->incoming.buf_p; - - priv->incoming.vector[1].iov_len = size2; - priv->incoming.count = size2 ? 2 : 1; - - priv->incoming.pending_vector = - priv->incoming.vector; - - priv->incoming.pending_count = - priv->incoming.count; - - priv->incoming.state = - SOCKET_PROTO_STATE_DATA_COMING; - break; - - case SOCKET_PROTO_STATE_DATA_COMING: - - ret = __socket_readv (this, - priv->incoming.pending_vector, - priv->incoming.pending_count, - &priv->incoming.pending_vector, - &priv->incoming.pending_count); - if (ret == 0) { - priv->incoming.state = - SOCKET_PROTO_STATE_DATA_CAME; - break; - } - - if (ret == -1) { - gf_log (this->xl->name, GF_LOG_DEBUG, - "read (%s) in state %d (%s)", - strerror (errno), - SOCKET_PROTO_STATE_DATA_COMING, - this->peerinfo.identifier); - goto unlock; - } - - if (ret > 0) { - gf_log (this->xl->name, GF_LOG_TRACE, - "partial data read on NB socket"); - goto unlock; - } - break; - - case SOCKET_PROTO_STATE_DATA_CAME: - memset (&priv->incoming.vector, 0, - sizeof (priv->incoming.vector)); - priv->incoming.pending_vector = NULL; - priv->incoming.pending_count = 0; - priv->incoming.state = SOCKET_PROTO_STATE_COMPLETE; - break; - - case SOCKET_PROTO_STATE_COMPLETE: - /* not reached */ - break; - - default: - gf_log (this->xl->name, GF_LOG_DEBUG, - "undefined state reached: %d", - priv->incoming.state); - goto unlock; - } - } -unlock: - - return ret; -} - - -static int -socket_proto_state_machine (transport_t *this) -{ - socket_private_t *priv = NULL; - int ret = 0; - - priv = this->private; - - pthread_mutex_lock (&priv->lock); - { - ret = __socket_proto_state_machine (this); - } - pthread_mutex_unlock (&priv->lock); - - return ret; -} - - -static int -socket_event_poll_in (transport_t *this) -{ - int ret = -1; - - ret = socket_proto_state_machine (this); - - /* call POLLIN on xlator even if complete block is not received, - just to keep the last_received timestamp ticking */ - - if (ret == 0) - ret = xlator_notify (this->xl, GF_EVENT_POLLIN, this); - - return ret; -} - - -static int -socket_connect_finish (transport_t *this) -{ - int ret = -1; - socket_private_t *priv = NULL; - int event = -1; - char notify_xlator = 0; - - priv = this->private; - - pthread_mutex_lock (&priv->lock); - { - if (priv->connected) - goto unlock; - - ret = __socket_connect_finish (priv->sock); - - if (ret == -1 && errno == EINPROGRESS) - ret = 1; - - if (ret == -1 && errno != EINPROGRESS) { - if (!priv->connect_finish_log) { - gf_log (this->xl->name, GF_LOG_ERROR, - "connection to %s failed (%s)", - this->peerinfo.identifier, - strerror (errno)); - priv->connect_finish_log = 1; - } - __socket_disconnect (this); - notify_xlator = 1; - event = GF_EVENT_POLLERR; - goto unlock; - } - - if (ret == 0) { - notify_xlator = 1; - - this->myinfo.sockaddr_len = - sizeof (this->myinfo.sockaddr); - - ret = getsockname (priv->sock, - SA (&this->myinfo.sockaddr), - &this->myinfo.sockaddr_len); - if (ret == -1) { - gf_log (this->xl->name, GF_LOG_DEBUG, - "getsockname on (%d) failed (%s)", - priv->sock, strerror (errno)); - __socket_disconnect (this); - event = GF_EVENT_POLLERR; - goto unlock; - } - - priv->connected = 1; - priv->connect_finish_log = 0; - event = GF_EVENT_CHILD_UP; - gf_get_transport_identifiers (this); - } - } -unlock: - pthread_mutex_unlock (&priv->lock); - - if (notify_xlator) - xlator_notify (this->xl, event, this); - - return 0; -} - - -static int -socket_event_handler (int fd, int idx, void *data, - int poll_in, int poll_out, int poll_err) -{ - transport_t *this = NULL; - socket_private_t *priv = NULL; - int ret = 0; - - this = data; - priv = this->private; - - pthread_mutex_lock (&priv->lock); - { - priv->idx = idx; - } - pthread_mutex_unlock (&priv->lock); - - if (!priv->connected) { - ret = socket_connect_finish (this); - } - - if (!ret && poll_out) { - ret = socket_event_poll_out (this); - } - - if (!ret && poll_in) { - ret = socket_event_poll_in (this); - } - - if (ret < 0 || poll_err) { - socket_event_poll_err (this); - transport_unref (this); - } - - return 0; -} - - -static int -socket_server_event_handler (int fd, int idx, void *data, - int poll_in, int poll_out, int poll_err) -{ - transport_t *this = NULL; - socket_private_t *priv = NULL; - int ret = 0; - int new_sock = -1; - transport_t *new_trans = NULL; - struct sockaddr_storage new_sockaddr = {0, }; - socklen_t addrlen = sizeof (new_sockaddr); - socket_private_t *new_priv = NULL; - glusterfs_ctx_t *ctx = NULL; - - this = data; - priv = this->private; - ctx = this->xl->ctx; - - pthread_mutex_lock (&priv->lock); - { - priv->idx = idx; - - if (poll_in) { - new_sock = accept (priv->sock, SA (&new_sockaddr), - &addrlen); - - if (new_sock == -1) - goto unlock; - - if (!priv->bio) { - ret = __socket_nonblock (new_sock); - - if (ret == -1) { - gf_log (this->xl->name, GF_LOG_DEBUG, - "NBIO on %d failed (%s)", - new_sock, strerror (errno)); - close (new_sock); - goto unlock; - } - } - - if (priv->nodelay) { - ret = __socket_nodelay (new_sock); - if (ret == -1) { - gf_log (this->xl->name, GF_LOG_ERROR, - "setsockopt() failed for " - "NODELAY (%s)", - strerror (errno)); - } - } - - if (priv->keepalive) { - ret = __socket_keepalive (new_sock, - priv->keepaliveintvl); - if (ret == -1) - gf_log (this->xl->name, GF_LOG_ERROR, - "Failed to set keep-alive: %s", - strerror (errno)); - } - - new_trans = GF_CALLOC (1, sizeof (*new_trans), - gf_common_mt_transport_t); - new_trans->xl = this->xl; - new_trans->fini = this->fini; - - memcpy (&new_trans->peerinfo.sockaddr, &new_sockaddr, - addrlen); - new_trans->peerinfo.sockaddr_len = addrlen; - - new_trans->myinfo.sockaddr_len = - sizeof (new_trans->myinfo.sockaddr); - - ret = getsockname (new_sock, - SA (&new_trans->myinfo.sockaddr), - &new_trans->myinfo.sockaddr_len); - if (ret == -1) { - gf_log (this->xl->name, GF_LOG_DEBUG, - "getsockname on %d failed (%s)", - new_sock, strerror (errno)); - close (new_sock); - goto unlock; - } - - gf_get_transport_identifiers (new_trans); - socket_init (new_trans); - new_trans->ops = this->ops; - new_trans->init = this->init; - new_trans->fini = this->fini; - - new_priv = new_trans->private; - - pthread_mutex_lock (&new_priv->lock); - { - new_priv->sock = new_sock; - new_priv->connected = 1; - - transport_ref (new_trans); - new_priv->idx = - event_register (ctx->event_pool, - new_sock, - socket_event_handler, - new_trans, 1, 0); - - if (new_priv->idx == -1) - ret = -1; - } - pthread_mutex_unlock (&new_priv->lock); - } - } -unlock: - pthread_mutex_unlock (&priv->lock); - - return ret; -} - - -static int -socket_disconnect (transport_t *this) -{ - socket_private_t *priv = NULL; - int ret = -1; - - priv = this->private; - - pthread_mutex_lock (&priv->lock); - { - ret = __socket_disconnect (this); - } - pthread_mutex_unlock (&priv->lock); - - return ret; -} - - -static int -socket_connect (transport_t *this) -{ - int ret = -1; - int sock = -1; - socket_private_t *priv = NULL; - struct sockaddr_storage sockaddr = {0, }; - socklen_t sockaddr_len = 0; - glusterfs_ctx_t *ctx = NULL; - sa_family_t sa_family = {0, }; - - priv = this->private; - ctx = this->xl->ctx; - - if (!priv) { - gf_log (this->xl->name, GF_LOG_DEBUG, - "connect() called on uninitialized transport"); - goto err; - } - - pthread_mutex_lock (&priv->lock); - { - sock = priv->sock; - } - pthread_mutex_unlock (&priv->lock); - - if (sock != -1) { - gf_log (this->xl->name, GF_LOG_TRACE, - "connect () called on transport already connected"); - ret = 0; - goto err; - } - - ret = gf_socket_client_get_remote_sockaddr (this, SA (&sockaddr), - &sockaddr_len, &sa_family); - if (ret == -1) { - /* logged inside client_get_remote_sockaddr */ - goto err; - } - - pthread_mutex_lock (&priv->lock); - { - if (priv->sock != -1) { - gf_log (this->xl->name, GF_LOG_TRACE, - "connect() -- already connected"); - goto unlock; - } - - memcpy (&this->peerinfo.sockaddr, &sockaddr, sockaddr_len); - this->peerinfo.sockaddr_len = sockaddr_len; - - priv->sock = socket (sa_family, SOCK_STREAM, 0); - if (priv->sock == -1) { - gf_log (this->xl->name, GF_LOG_ERROR, - "socket creation failed (%s)", - strerror (errno)); - goto unlock; - } - - /* Cant help if setting socket options fails. We can continue - * working nonetheless. - */ - if (setsockopt (priv->sock, SOL_SOCKET, SO_RCVBUF, - &priv->windowsize, - sizeof (priv->windowsize)) < 0) { - gf_log (this->xl->name, GF_LOG_ERROR, - "setting receive window size failed: %d: %d: " - "%s", priv->sock, priv->windowsize, - strerror (errno)); - } - - if (setsockopt (priv->sock, SOL_SOCKET, SO_SNDBUF, - &priv->windowsize, - sizeof (priv->windowsize)) < 0) { - gf_log (this->xl->name, GF_LOG_ERROR, - "setting send window size failed: %d: %d: " - "%s", priv->sock, priv->windowsize, - strerror (errno)); - } - - - if (priv->nodelay && priv->lowlat) { - ret = __socket_nodelay (priv->sock); - if (ret == -1) { - gf_log (this->xl->name, GF_LOG_ERROR, - "setsockopt() failed for NODELAY (%s)", - strerror (errno)); - } - } - - if (!priv->bio) { - ret = __socket_nonblock (priv->sock); - - if (ret == -1) { - gf_log (this->xl->name, GF_LOG_ERROR, - "NBIO on %d failed (%s)", - priv->sock, strerror (errno)); - close (priv->sock); - priv->sock = -1; - goto unlock; - } - } - - if (priv->keepalive) { - ret = __socket_keepalive (priv->sock, - priv->keepaliveintvl); - if (ret == -1) - gf_log (this->xl->name, GF_LOG_ERROR, - "Failed to set keep-alive: %s", - strerror (errno)); - } - - SA (&this->myinfo.sockaddr)->sa_family = - SA (&this->peerinfo.sockaddr)->sa_family; - - ret = gf_client_bind (this, SA (&this->myinfo.sockaddr), - &this->myinfo.sockaddr_len, priv->sock); - if (ret == -1) { - gf_log (this->xl->name, GF_LOG_WARNING, - "client bind failed: %s", strerror (errno)); - close (priv->sock); - priv->sock = -1; - goto unlock; - } - - ret = connect (priv->sock, SA (&this->peerinfo.sockaddr), - this->peerinfo.sockaddr_len); - - if (ret == -1 && errno != EINPROGRESS) { - gf_log (this->xl->name, GF_LOG_ERROR, - "connection attempt failed (%s)", - strerror (errno)); - close (priv->sock); - priv->sock = -1; - goto unlock; - } - - priv->connected = 0; - - transport_ref (this); - - priv->idx = event_register (ctx->event_pool, priv->sock, - socket_event_handler, this, 1, 1); - if (priv->idx == -1) - ret = -1; - } -unlock: - pthread_mutex_unlock (&priv->lock); - -err: - return ret; -} - - -static int -socket_listen (transport_t *this) -{ - socket_private_t * priv = NULL; - int ret = -1; - int sock = -1; - struct sockaddr_storage sockaddr; - socklen_t sockaddr_len; - peer_info_t *myinfo = NULL; - glusterfs_ctx_t *ctx = NULL; - sa_family_t sa_family = {0, }; - - priv = this->private; - myinfo = &this->myinfo; - ctx = this->xl->ctx; - - pthread_mutex_lock (&priv->lock); - { - sock = priv->sock; - } - pthread_mutex_unlock (&priv->lock); - - if (sock != -1) { - gf_log (this->xl->name, GF_LOG_DEBUG, - "alreading listening"); - return ret; - } - - ret = gf_socket_server_get_local_sockaddr (this, SA (&sockaddr), - &sockaddr_len, &sa_family); - if (ret == -1) { - return ret; - } - - pthread_mutex_lock (&priv->lock); - { - if (priv->sock != -1) { - gf_log (this->xl->name, GF_LOG_DEBUG, - "already listening"); - goto unlock; - } - - memcpy (&myinfo->sockaddr, &sockaddr, sockaddr_len); - myinfo->sockaddr_len = sockaddr_len; - - priv->sock = socket (sa_family, SOCK_STREAM, 0); - - if (priv->sock == -1) { - gf_log (this->xl->name, GF_LOG_ERROR, - "socket creation failed (%s)", - strerror (errno)); - goto unlock; - } - - /* Cant help if setting socket options fails. We can continue - * working nonetheless. - */ - if (setsockopt (priv->sock, SOL_SOCKET, SO_RCVBUF, - &priv->windowsize, - sizeof (priv->windowsize)) < 0) { - gf_log (this->xl->name, GF_LOG_ERROR, - "setting receive window size failed: %d: %d: " - "%s", priv->sock, priv->windowsize, - strerror (errno)); - } - - if (setsockopt (priv->sock, SOL_SOCKET, SO_SNDBUF, - &priv->windowsize, - sizeof (priv->windowsize)) < 0) { - gf_log (this->xl->name, GF_LOG_ERROR, - "setting send window size failed: %d: %d: " - "%s", priv->sock, priv->windowsize, - strerror (errno)); - } - - if (priv->nodelay) { - ret = __socket_nodelay (priv->sock); - if (ret == -1) { - gf_log (this->xl->name, GF_LOG_ERROR, - "setsockopt() failed for NODELAY (%s)", - strerror (errno)); - } - } - - if (!priv->bio) { - ret = __socket_nonblock (priv->sock); - - if (ret == -1) { - gf_log (this->xl->name, GF_LOG_ERROR, - "NBIO on %d failed (%s)", - priv->sock, strerror (errno)); - close (priv->sock); - priv->sock = -1; - goto unlock; - } - } - - ret = __socket_server_bind (this); - - if (ret == -1) { - /* logged inside __socket_server_bind() */ - close (priv->sock); - priv->sock = -1; - goto unlock; - } - - ret = listen (priv->sock, 10); - - if (ret == -1) { - gf_log (this->xl->name, GF_LOG_ERROR, - "could not set socket %d to listen mode (%s)", - priv->sock, strerror (errno)); - close (priv->sock); - priv->sock = -1; - goto unlock; - } - - transport_ref (this); - - priv->idx = event_register (ctx->event_pool, priv->sock, - socket_server_event_handler, - this, 1, 0); - - if (priv->idx == -1) { - gf_log (this->xl->name, GF_LOG_DEBUG, - "could not register socket %d with events", - priv->sock); - ret = -1; - close (priv->sock); - priv->sock = -1; - goto unlock; - } - } -unlock: - pthread_mutex_unlock (&priv->lock); - - return ret; -} - - -static int -socket_receive (transport_t *this, char **hdr_p, size_t *hdrlen_p, - struct iobuf **iobuf_p) -{ - socket_private_t *priv = NULL; - int ret = -1; - - priv = this->private; - - pthread_mutex_lock (&priv->lock); - { - if (priv->connected != 1) { - gf_log (this->xl->name, GF_LOG_DEBUG, - "socket not connected to receive"); - goto unlock; - } - - if (!hdr_p || !hdrlen_p || !iobuf_p) { - gf_log (this->xl->name, GF_LOG_DEBUG, - "bad parameters %p %p %p", - hdr_p, hdrlen_p, iobuf_p); - goto unlock; - } - - if (priv->incoming.state == SOCKET_PROTO_STATE_COMPLETE) { - *hdr_p = priv->incoming.hdr_p; - *hdrlen_p = priv->incoming.hdrlen; - *iobuf_p = priv->incoming.iobuf; - - memset (&priv->incoming, 0, sizeof (priv->incoming)); - priv->incoming.state = SOCKET_PROTO_STATE_NADA; - - ret = 0; - } - } -unlock: - pthread_mutex_unlock (&priv->lock); - - return ret; -} - - -/* TODO: implement per transfer limit */ -static int -socket_submit (transport_t *this, char *buf, int len, - struct iovec *vector, int count, - struct iobref *iobref) -{ - socket_private_t *priv = NULL; - int ret = -1; - char need_poll_out = 0; - char need_append = 1; - struct ioq *entry = NULL; - glusterfs_ctx_t *ctx = NULL; - - priv = this->private; - ctx = this->xl->ctx; - - pthread_mutex_lock (&priv->lock); - { - if (priv->connected != 1) { - if (!priv->submit_log && !priv->connect_finish_log) { - gf_log (this->xl->name, GF_LOG_DEBUG, - "not connected (priv->connected = %d)", - priv->connected); - priv->submit_log = 1; - } - goto unlock; - } - - priv->submit_log = 0; - entry = __socket_ioq_new (this, buf, len, vector, count, iobref); - if (!entry) - goto unlock; - - if (list_empty (&priv->ioq)) { - ret = __socket_ioq_churn_entry (this, entry); - - if (ret == 0) - need_append = 0; - - if (ret > 0) - need_poll_out = 1; - } - - if (need_append) { - list_add_tail (&entry->list, &priv->ioq); - ret = 0; - } - - if (need_poll_out) { - /* first entry to wait. continue writing on POLLOUT */ - priv->idx = event_select_on (ctx->event_pool, - priv->sock, - priv->idx, -1, 1); - } - } -unlock: - pthread_mutex_unlock (&priv->lock); - - return ret; -} - - -struct transport_ops tops = { - .listen = socket_listen, - .connect = socket_connect, - .disconnect = socket_disconnect, - .submit = socket_submit, - .receive = socket_receive -}; - - -static int -socket_init (transport_t *this) -{ - socket_private_t *priv = NULL; - gf_boolean_t tmp_bool = 0; - uint64_t windowsize = GF_DEFAULT_SOCKET_WINDOW_SIZE; - char *optstr = NULL; - uint32_t keepalive = 0; - - if (this->private) { - gf_log (this->xl->name, GF_LOG_DEBUG, - "double init attempted"); - return -1; - } - - priv = GF_CALLOC (1, sizeof (*priv), - gf_common_mt_socket_private_t); - if (!priv) { - gf_log (this->xl->name, GF_LOG_ERROR, - "calloc (1, %"GF_PRI_SIZET") returned NULL", - sizeof (*priv)); - return -1; - } - - pthread_mutex_init (&priv->lock, NULL); - - priv->sock = -1; - priv->idx = -1; - priv->connected = -1; - - INIT_LIST_HEAD (&priv->ioq); - - if (dict_get (this->xl->options, "non-blocking-io")) { - optstr = data_to_str (dict_get (this->xl->options, - "non-blocking-io")); - - if (gf_string2boolean (optstr, &tmp_bool) == -1) { - gf_log (this->xl->name, GF_LOG_ERROR, - "'non-blocking-io' takes only boolean options," - " not taking any action"); - tmp_bool = 1; - } - priv->bio = 0; - if (!tmp_bool) { - priv->bio = 1; - gf_log (this->xl->name, GF_LOG_WARNING, - "disabling non-blocking IO"); - } - } - - optstr = NULL; - - // By default, we enable NODELAY - priv->nodelay = 1; - if (dict_get (this->xl->options, "transport.socket.nodelay")) { - optstr = data_to_str (dict_get (this->xl->options, - "transport.socket.nodelay")); - - if (gf_string2boolean (optstr, &tmp_bool) == -1) { - gf_log (this->xl->name, GF_LOG_ERROR, - "'transport.socket.nodelay' takes only " - "boolean options, not taking any action"); - tmp_bool = 1; - } - if (!tmp_bool) { - priv->nodelay = 0; - gf_log (this->xl->name, GF_LOG_DEBUG, - "disabling nodelay"); - } - } - - - optstr = NULL; - if (dict_get_str (this->xl->options, "transport.window-size", - &optstr) == 0) { - if (gf_string2bytesize (optstr, &windowsize) != 0) { - gf_log (this->xl->name, GF_LOG_ERROR, - "invalid number format: %s", optstr); - return -1; - } - } - - optstr = NULL; - - if (dict_get_str (this->xl->options, "transport.socket.lowlat", - &optstr) == 0) { - priv->lowlat = 1; - } - - /* Enable Keep-alive by default. */ - priv->keepalive = 1; - priv->keepaliveintvl = GF_USE_DEFAULT_KEEPALIVE; - if (dict_get_str (this->xl->options, "transport.socket.keepalive", - &optstr) == 0) { - if (gf_string2boolean (optstr, &tmp_bool) == -1) { - gf_log (this->xl->name, GF_LOG_ERROR, - "'transport.socket.keepalive' takes only " - "boolean options, not taking any action"); - tmp_bool = 1; - } - - if (!tmp_bool) - priv->keepalive = 0; - - } - - if (dict_get_uint32 (this->xl->options, - "transport.socket.keepalive-interval", - &keepalive) == 0) { - priv->keepaliveintvl = keepalive; - } - - priv->windowsize = (int)windowsize; - this->private = priv; - - return 0; -} - - -void -fini (transport_t *this) -{ - socket_private_t *priv = this->private; - - gf_log (this->xl->name, GF_LOG_TRACE, - "transport %p destroyed", this); - - pthread_mutex_destroy (&priv->lock); - GF_FREE (priv); -} - - -int32_t -init (transport_t *this) -{ - int ret = -1; - - ret = socket_init (this); - - if (ret == -1) { - gf_log (this->xl->name, GF_LOG_DEBUG, "socket_init() failed"); - } - - return ret; -} - -struct volume_options options[] = { - { .key = {"remote-port", - "transport.remote-port", - "transport.socket.remote-port"}, - .type = GF_OPTION_TYPE_INT - }, - { .key = {"transport.socket.listen-port", "listen-port"}, - .type = GF_OPTION_TYPE_INT - }, - { .key = {"transport.socket.bind-address", "bind-address" }, - .type = GF_OPTION_TYPE_INTERNET_ADDRESS - }, - { .key = {"transport.socket.connect-path", "connect-path"}, - .type = GF_OPTION_TYPE_ANY - }, - { .key = {"transport.socket.bind-path", "bind-path"}, - .type = GF_OPTION_TYPE_ANY - }, - { .key = {"transport.socket.listen-path", "listen-path"}, - .type = GF_OPTION_TYPE_ANY - }, - { .key = { "transport.address-family", - "address-family" }, - .value = {"inet", "inet6", "inet/inet6", "inet6/inet", - "unix", "inet-sdp" }, - .type = GF_OPTION_TYPE_STR - }, - - { .key = {"non-blocking-io"}, - .type = GF_OPTION_TYPE_BOOL - }, - { .key = {"transport.window-size"}, - .type = GF_OPTION_TYPE_SIZET, - .min = GF_MIN_SOCKET_WINDOW_SIZE, - .max = GF_MAX_SOCKET_WINDOW_SIZE, - }, - { .key = {"transport.socket.nodelay"}, - .type = GF_OPTION_TYPE_BOOL - }, - { .key = {"transport.socket.lowlat"}, - .type = GF_OPTION_TYPE_BOOL - }, - { .key = {"transport.socket.keepalive"}, - .type = GF_OPTION_TYPE_BOOL - }, - { .key = {"transport.socket.keepalive-interval"}, - .type = GF_OPTION_TYPE_INT - }, - { .key = {NULL} } -}; - diff --git a/xlators/protocol/legacy/transport/socket/src/socket.h b/xlators/protocol/legacy/transport/socket/src/socket.h deleted file mode 100644 index e02801a5b1c..00000000000 --- a/xlators/protocol/legacy/transport/socket/src/socket.h +++ /dev/null @@ -1,129 +0,0 @@ -/* - Copyright (c) 2006-2009 Gluster, Inc. <http://www.gluster.com> - This file is part of GlusterFS. - - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. -*/ - -#ifndef _SOCKET_H -#define _SOCKET_H - - -#ifndef _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif - -#include "event.h" -#include "transport.h" -#include "logging.h" -#include "dict.h" -#include "mem-pool.h" -#include "socket-mem-types.h" - -#ifndef MAX_IOVEC -#define MAX_IOVEC 16 -#endif /* MAX_IOVEC */ - -#define GF_DEFAULT_SOCKET_LISTEN_PORT 6996 - -/* This is the size set through setsockopt for - * both the TCP receive window size and the - * send buffer size. - * Till the time iobuf size becomes configurable, this size is set to include - * two iobufs + the GlusterFS protocol headers. - * Linux allows us to over-ride the max values for the system. - * Should we over-ride them? Because if we set a value larger than the default - * setsockopt will fail. Having larger values might be beneficial for - * IB links. - */ -#define GF_DEFAULT_SOCKET_WINDOW_SIZE (512 * GF_UNIT_KB) -#define GF_MAX_SOCKET_WINDOW_SIZE (1 * GF_UNIT_MB) -#define GF_MIN_SOCKET_WINDOW_SIZE (128 * GF_UNIT_KB) - -#define GF_USE_DEFAULT_KEEPALIVE (-1) - -typedef enum { - SOCKET_PROTO_STATE_NADA = 0, - SOCKET_PROTO_STATE_HEADER_COMING, - SOCKET_PROTO_STATE_HEADER_CAME, - SOCKET_PROTO_STATE_DATA_COMING, - SOCKET_PROTO_STATE_DATA_CAME, - SOCKET_PROTO_STATE_COMPLETE, -} socket_proto_state_t; - -struct socket_header { - char colonO[3]; - uint32_t size1; - uint32_t size2; - char version; -} __attribute__((packed)); - - -struct ioq { - union { - struct list_head list; - struct { - struct ioq *next; - struct ioq *prev; - }; - }; - struct socket_header header; - struct iovec vector[MAX_IOVEC]; - int count; - struct iovec *pending_vector; - int pending_count; - char *buf; - struct iobref *iobref; -}; - - -typedef struct { - int32_t sock; - int32_t idx; - unsigned char connected; // -1 = not connected. 0 = in progress. 1 = connected - char bio; - char connect_finish_log; - char submit_log; - union { - struct list_head ioq; - struct { - struct ioq *ioq_next; - struct ioq *ioq_prev; - }; - }; - struct { - int state; - struct socket_header header; - char *hdr_p; - size_t hdrlen; - struct iobuf *iobuf; - char *buf_p; - size_t buflen; - struct iovec vector[2]; - int count; - struct iovec *pending_vector; - int pending_count; - } incoming; - pthread_mutex_t lock; - int windowsize; - char lowlat; - char nodelay; - int keepalive; - int keepaliveintvl; -} socket_private_t; - - -#endif diff --git a/xlators/protocol/server/src/Makefile.am b/xlators/protocol/server/src/Makefile.am index 72a581ddf10..5e875c8df0b 100644 --- a/xlators/protocol/server/src/Makefile.am +++ b/xlators/protocol/server/src/Makefile.am @@ -1,24 +1,33 @@ +if WITH_SERVER xlator_LTLIBRARIES = server.la +endif + xlatordir = $(libdir)/glusterfs/$(PACKAGE_VERSION)/xlator/protocol -server_la_LDFLAGS = -module -avoidversion +server_la_LDFLAGS = -module $(GF_XLATOR_DEFAULT_LDFLAGS) server_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la \ $(top_builddir)/rpc/rpc-lib/src/libgfrpc.la \ - $(top_builddir)/rpc/xdr/src/libgfxdr.la + $(top_builddir)/rpc/xdr/src/libgfxdr.la $(LIB_DL) server_la_SOURCES = server.c server-resolve.c server-helpers.c \ - server3_1-fops.c server-handshake.c authenticate.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 -noinst_HEADERS = server.h server-helpers.h server-mem-types.h authenticate.h +server_ladir = $(includedir)/glusterfs/server -AM_CFLAGS = -fPIC -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -Wall \ - -I$(top_srcdir)/libglusterfs/src -shared -nostartfiles \ - -DCONFDIR=\"$(sysconfdir)/glusterfs\" -D$(GF_HOST_OS) \ +AM_CPPFLAGS = $(GF_CPPFLAGS) -I$(top_srcdir)/libglusterfs/src \ + -DCONFDIR=\"$(sysconfdir)/glusterfs\" \ -DLIBDIR=\"$(libdir)/glusterfs/$(PACKAGE_VERSION)/auth\" \ - $(GF_CFLAGS) -I$(top_srcdir)/xlators/protocol/lib/src \ - -I$(top_srcdir)/rpc/rpc-lib/src/ \ - -I$(top_srcdir)/rpc/xdr/src/ \ - -I$(top_srcdir)/contrib/md5/ + -I$(top_srcdir)/xlators/protocol/lib/src \ + -I$(top_srcdir)/rpc/rpc-lib/src \ + -I$(top_srcdir)/rpc/xdr/src -I$(top_builddir)/rpc/xdr/src \ + -I$(top_srcdir)/glusterfsd/src + +AM_CFLAGS = -Wall $(GF_CFLAGS) \ + -DDATADIR=\"$(localstatedir)\" CLEANFILES = *~ diff --git a/xlators/protocol/server/src/authenticate.c b/xlators/protocol/server/src/authenticate.c index 5205b54df61..c1229f9ebf3 100644 --- a/xlators/protocol/server/src/authenticate.c +++ b/xlators/protocol/server/src/authenticate.c @@ -1,27 +1,13 @@ /* - Copyright (c) 2007-2010 Gluster, Inc. <http://www.gluster.com> + Copyright (c) 2007-2013 Red Hat, Inc. <http://www.redhat.com> This file is part of GlusterFS. - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. + 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. */ -#ifndef _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif - #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif @@ -30,220 +16,217 @@ #include <dlfcn.h> #include <errno.h> #include "authenticate.h" +#include "server-messages.h" -static void -init (dict_t *this, - char *key, - data_t *value, - void *data) +static int +init(dict_t *this, char *key, data_t *value, void *data) { - void *handle = NULL; - char *auth_file = NULL; - auth_handle_t *auth_handle = NULL; - auth_fn_t authenticate = NULL; - int *error = NULL; - int ret = 0; - - /* It gets over written */ - error = data; - - if (!strncasecmp (key, "ip", strlen ("ip"))) { - gf_log ("authenticate", GF_LOG_ERROR, - "AUTHENTICATION MODULE \"IP\" HAS BEEN REPLACED " - "BY \"ADDR\""); - dict_set (this, key, data_from_dynptr (NULL, 0)); - /* TODO: 1.3.x backword compatibility */ - // *error = -1; - // return; - key = "addr"; - } - - ret = gf_asprintf (&auth_file, "%s/%s.so", LIBDIR, key); - if (-1 == ret) { - gf_log ("authenticate", GF_LOG_ERROR, "asprintf failed"); - dict_set (this, key, data_from_dynptr (NULL, 0)); - *error = -1; - return; - } - - handle = dlopen (auth_file, RTLD_LAZY); - if (!handle) { - gf_log ("authenticate", GF_LOG_ERROR, "dlopen(%s): %s\n", - auth_file, dlerror ()); - dict_set (this, key, data_from_dynptr (NULL, 0)); - GF_FREE (auth_file); - *error = -1; - return; - } - GF_FREE (auth_file); - - authenticate = dlsym (handle, "gf_auth"); - if (!authenticate) { - gf_log ("authenticate", GF_LOG_ERROR, - "dlsym(gf_auth) on %s\n", dlerror ()); - dict_set (this, key, data_from_dynptr (NULL, 0)); - *error = -1; - return; - } - - auth_handle = GF_CALLOC (1, sizeof (*auth_handle), - gf_common_mt_auth_handle_t); - if (!auth_handle) { - gf_log ("authenticate", GF_LOG_ERROR, "Out of memory"); - dict_set (this, key, data_from_dynptr (NULL, 0)); - *error = -1; - return; - } - auth_handle->vol_opt = GF_CALLOC (1, sizeof (volume_opt_list_t), - gf_common_mt_volume_opt_list_t); - auth_handle->vol_opt->given_opt = dlsym (handle, "options"); - if (auth_handle->vol_opt->given_opt == NULL) { - gf_log ("authenticate", GF_LOG_DEBUG, - "volume option validation not specified"); - } - - auth_handle->authenticate = authenticate; - auth_handle->handle = handle; - - dict_set (this, key, - data_from_dynptr (auth_handle, sizeof (*auth_handle))); + void *handle = NULL; + char *auth_file = NULL; + auth_handle_t *auth_handle = NULL; + auth_fn_t authenticate = NULL; + int *error = NULL; + int ret = 0; + + /* It gets over written */ + error = data; + + if (!strncasecmp(key, "ip", SLEN("ip"))) { + gf_msg("authenticate", GF_LOG_ERROR, 0, PS_MSG_AUTHENTICATE_ERROR, + "AUTHENTICATION MODULE " + "\"IP\" HAS BEEN REPLACED BY \"ADDR\""); + dict_set(this, key, data_from_dynptr(NULL, 0)); + /* TODO: 1.3.x backward compatibility */ + // *error = -1; + // return; + key = "addr"; + } + + ret = gf_asprintf(&auth_file, "%s/%s.so", LIBDIR, key); + if (-1 == ret) { + dict_set(this, key, data_from_dynptr(NULL, 0)); + *error = -1; + return -1; + } + + handle = dlopen(auth_file, RTLD_LAZY); + if (!handle) { + gf_msg("authenticate", GF_LOG_ERROR, 0, PS_MSG_AUTHENTICATE_ERROR, + "dlopen(%s): %s\n", auth_file, dlerror()); + dict_set(this, key, data_from_dynptr(NULL, 0)); + GF_FREE(auth_file); + *error = -1; + return -1; + } + GF_FREE(auth_file); + + authenticate = dlsym(handle, "gf_auth"); + if (!authenticate) { + gf_msg("authenticate", GF_LOG_ERROR, 0, PS_MSG_AUTHENTICATE_ERROR, + "dlsym(gf_auth) on %s\n", dlerror()); + dict_set(this, key, data_from_dynptr(NULL, 0)); + dlclose(handle); + *error = -1; + return -1; + } + + auth_handle = GF_CALLOC(1, sizeof(*auth_handle), + gf_common_mt_auth_handle_t); + if (!auth_handle) { + dict_set(this, key, data_from_dynptr(NULL, 0)); + *error = -1; + dlclose(handle); + return -1; + } + auth_handle->vol_opt = GF_CALLOC(1, sizeof(volume_opt_list_t), + gf_common_mt_volume_opt_list_t); + if (!auth_handle->vol_opt) { + dict_set(this, key, data_from_dynptr(NULL, 0)); + *error = -1; + GF_FREE(auth_handle); + dlclose(handle); + return -1; + } + auth_handle->vol_opt->given_opt = dlsym(handle, "options"); + if (auth_handle->vol_opt->given_opt == NULL) { + gf_msg_debug("authenticate", 0, + "volume option validation " + "not specified"); + } + + auth_handle->authenticate = authenticate; + auth_handle->handle = handle; + + dict_set(this, key, data_from_dynptr(auth_handle, sizeof(*auth_handle))); + return 0; } -static void -fini (dict_t *this, - char *key, - data_t *value, - void *data) +static int +fini(dict_t *this, char *key, data_t *value, void *data) { - auth_handle_t *handle = data_to_ptr (value); - if (handle) { - dlclose (handle->handle); - } + auth_handle_t *handle = data_to_ptr(value); + if (handle) { + dlclose(handle->handle); + } + return 0; } -int32_t -gf_auth_init (xlator_t *xl, dict_t *auth_modules) +static int +_gf_auth_option_validate(dict_t *d, char *k, data_t *v, void *tmp) { - int ret = 0; - auth_handle_t *handle = NULL; - data_pair_t *pair = NULL; - dict_foreach (auth_modules, init, &ret); - if (!ret) { - pair = auth_modules->members_list; - while (pair) { - handle = data_to_ptr (pair->value); - if (handle) { - list_add_tail (&(handle->vol_opt->list), - &(xl->volume_options)); - if (-1 == - validate_xlator_volume_options (xl, - handle->vol_opt->given_opt)) { - gf_log ("authenticate", GF_LOG_ERROR, - "volume option validation " - "failed"); - ret = -1; - } - } - pair = pair->next; - } - } - if (ret) { - gf_log (xl->name, GF_LOG_ERROR, "authentication init failed"); - dict_foreach (auth_modules, fini, &ret); - ret = -1; - } - return ret; + auth_handle_t *handle = NULL; + xlator_t *xl = NULL; + int ret = 0; + + xl = tmp; + + handle = data_to_ptr(v); + if (!handle) + return 0; + + list_add_tail(&(handle->vol_opt->list), &(xl->volume_options)); + + ret = xlator_options_validate_list(xl, xl->options, handle->vol_opt, NULL); + if (ret) { + gf_msg("authenticate", GF_LOG_ERROR, 0, PS_MSG_VOL_VALIDATE_FAILED, + "volume option validation " + "failed"); + return -1; + } + return 0; } -static dict_t *__input_params; -static dict_t *__config_params; - -void -map (dict_t *this, - char *key, - data_t *value, - void *data) +int32_t +gf_auth_init(xlator_t *xl, dict_t *auth_modules) { - dict_t *res = data; - auth_fn_t authenticate; - auth_handle_t *handle = NULL; - - if (value && (handle = data_to_ptr (value)) && - (authenticate = handle->authenticate)) { - dict_set (res, key, - int_to_data (authenticate (__input_params, - __config_params))); - } else { - dict_set (res, key, int_to_data (AUTH_DONT_CARE)); - } + int ret = 0; + + dict_foreach(auth_modules, init, &ret); + if (ret) + goto out; + + ret = dict_foreach(auth_modules, _gf_auth_option_validate, xl); + +out: + if (ret) { + gf_msg(xl->name, GF_LOG_ERROR, 0, PS_MSG_AUTH_INIT_FAILED, + "authentication init failed"); + dict_foreach(auth_modules, fini, &ret); + ret = -1; + } + return ret; } -void -reduce (dict_t *this, - char *key, - data_t *value, - void *data) +typedef struct { + dict_t *iparams; + dict_t *cparams; + int64_t result; +} gf_auth_args_t; + +static int +gf_auth_one_method(dict_t *this, char *key, data_t *value, void *data) { - int64_t val = 0; - int64_t *res = data; - if (!data) - return; - - val = data_to_int64 (value); - switch (val) - { - case AUTH_ACCEPT: - if (AUTH_DONT_CARE == *res) - *res = AUTH_ACCEPT; - break; - - case AUTH_REJECT: - *res = AUTH_REJECT; - break; - - case AUTH_DONT_CARE: - break; - } + gf_auth_args_t *args = data; + auth_handle_t *handle = NULL; + + if (!value) { + return 0; + } + + handle = data_to_ptr(value); + if (!handle || !handle->authenticate) { + return 0; + } + + switch (handle->authenticate(args->iparams, args->cparams)) { + case AUTH_ACCEPT: + if (args->result != AUTH_REJECT) { + args->result = AUTH_ACCEPT; + } + /* FALLTHROUGH */ + default: + return 0; + case AUTH_REJECT: + args->result = AUTH_REJECT; + return -1; + } } - auth_result_t -gf_authenticate (dict_t *input_params, - dict_t *config_params, - dict_t *auth_modules) +gf_authenticate(dict_t *input_params, dict_t *config_params, + dict_t *auth_modules) { - dict_t *results = NULL; - int64_t result = AUTH_DONT_CARE; + char *name = NULL; + data_t *peerinfo_data = NULL; + gf_auth_args_t args; - results = get_new_dict (); - __input_params = input_params; - __config_params = config_params; + args.iparams = input_params; + args.cparams = config_params; + args.result = AUTH_DONT_CARE; - dict_foreach (auth_modules, map, results); + dict_foreach(auth_modules, gf_auth_one_method, &args); - dict_foreach (results, reduce, &result); - if (AUTH_DONT_CARE == result) { - data_t *peerinfo_data = dict_get (input_params, "peer-info-name"); - char *name = NULL; + if (AUTH_DONT_CARE == args.result) { + peerinfo_data = dict_get(input_params, "peer-info-name"); - if (peerinfo_data) { - name = peerinfo_data->data; - } + if (peerinfo_data) { + name = peerinfo_data->data; + } - gf_log ("auth", GF_LOG_ERROR, - "no authentication module is interested in " - "accepting remote-client %s", name); - result = AUTH_REJECT; - } + gf_msg("auth", GF_LOG_ERROR, 0, PS_MSG_REMOTE_CLIENT_REFUSED, + "no authentication module is interested in " + "accepting remote-client %s", + name); + args.result = AUTH_REJECT; + } - dict_destroy (results); - return result; + return args.result; } void -gf_auth_fini (dict_t *auth_modules) +gf_auth_fini(dict_t *auth_modules) { - int32_t dummy; + int32_t dummy; - dict_foreach (auth_modules, fini, &dummy); + dict_foreach(auth_modules, fini, &dummy); } diff --git a/xlators/protocol/server/src/authenticate.h b/xlators/protocol/server/src/authenticate.h index 93d73741b0a..6888cf696e6 100644 --- a/xlators/protocol/server/src/authenticate.h +++ b/xlators/protocol/server/src/authenticate.h @@ -1,60 +1,42 @@ /* - Copyright (c) 2007-2009 Gluster, Inc. <http://www.gluster.com> + Copyright (c) 2007-2013 Red Hat, Inc. <http://www.redhat.com> This file is part of GlusterFS. - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. + 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. */ #ifndef _AUTHENTICATE_H #define _AUTHENTICATE_H -#ifndef _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif - #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif #include <stdio.h> #include <fnmatch.h> -#include "dict.h" -#include "compat.h" -#include "list.h" -#include "xlator.h" +#include <glusterfs/dict.h> +#include <glusterfs/compat.h> +#include <glusterfs/list.h> +#include <glusterfs/xlator.h> -typedef enum { - AUTH_ACCEPT, - AUTH_REJECT, - AUTH_DONT_CARE -} auth_result_t; +typedef enum { AUTH_ACCEPT, AUTH_REJECT, AUTH_DONT_CARE } auth_result_t; -typedef auth_result_t (*auth_fn_t) (dict_t *input_params, - dict_t *config_params); +typedef auth_result_t (*auth_fn_t)(dict_t *input_params, dict_t *config_params); typedef struct { - void *handle; - auth_fn_t authenticate; - volume_opt_list_t *vol_opt; + void *handle; + auth_fn_t authenticate; + volume_opt_list_t *vol_opt; } auth_handle_t; -auth_result_t gf_authenticate (dict_t *input_params, - dict_t *config_params, - dict_t *auth_modules); -int32_t gf_auth_init (xlator_t *xl, dict_t *auth_modules); -void gf_auth_fini (dict_t *auth_modules); +int32_t +gf_auth_init(xlator_t *xl, dict_t *auth_modules); +void +gf_auth_fini(dict_t *auth_modules); +auth_result_t +gf_authenticate(dict_t *, dict_t *, dict_t *); #endif /* _AUTHENTICATE_H */ diff --git a/xlators/protocol/server/src/server-common.c b/xlators/protocol/server/src/server-common.c new file mode 100644 index 00000000000..cd79cf4d930 --- /dev/null +++ b/xlators/protocol/server/src/server-common.c @@ -0,0 +1,842 @@ +#include "server.h" +#include <glusterfs/defaults.h> +#include "rpc-common-xdr.h" +#include "glusterfs3-xdr.h" +#include "glusterfs3.h" +#include <glusterfs/compat-errno.h> +#include "server-messages.h" +#include "server-helpers.h" +#include <glusterfs/defaults.h> +#include <glusterfs/fd.h> +#include "xdr-nfs3.h" + +void +server_post_stat(server_state_t *state, gfs3_stat_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 */ + static uuid_t gfid = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; + + stbuf->ia_ino = 1; + gf_uuid_copy(stbuf->ia_gfid, gfid); + } + + gf_stat_from_iatt(&rsp->stat, stbuf); +} + +void +server_post_readlink(gfs3_readlink_rsp *rsp, struct iatt *stbuf, + const char *buf) +{ + gf_stat_from_iatt(&rsp->buf, stbuf); + rsp->path = (char *)buf; +} + +void +server_post_mknod(server_state_t *state, gfs3_mknod_rsp *rsp, + struct iatt *stbuf, struct iatt *preparent, + struct iatt *postparent, inode_t *inode) +{ + inode_t *link_inode = NULL; + + gf_stat_from_iatt(&rsp->stat, stbuf); + gf_stat_from_iatt(&rsp->preparent, preparent); + gf_stat_from_iatt(&rsp->postparent, postparent); + + link_inode = inode_link(inode, state->loc.parent, state->loc.name, stbuf); + inode_lookup(link_inode); + inode_unref(link_inode); +} + +void +server_post_mkdir(server_state_t *state, gfs3_mkdir_rsp *rsp, inode_t *inode, + struct iatt *stbuf, struct iatt *preparent, + struct iatt *postparent, dict_t *xdata) +{ + inode_t *link_inode = NULL; + + gf_stat_from_iatt(&rsp->stat, stbuf); + gf_stat_from_iatt(&rsp->preparent, preparent); + gf_stat_from_iatt(&rsp->postparent, postparent); + + link_inode = inode_link(inode, state->loc.parent, state->loc.name, stbuf); + inode_lookup(link_inode); + inode_unref(link_inode); +} + +void +server_post_unlink(server_state_t *state, gfs3_unlink_rsp *rsp, + struct iatt *preparent, struct iatt *postparent) +{ + inode_unlink(state->loc.inode, state->loc.parent, state->loc.name); + + forget_inode_if_no_dentry(state->loc.inode); + + gf_stat_from_iatt(&rsp->preparent, preparent); + gf_stat_from_iatt(&rsp->postparent, postparent); +} + +void +server_post_rmdir(server_state_t *state, gfs3_rmdir_rsp *rsp, + struct iatt *preparent, struct iatt *postparent) +{ + 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); + + gf_stat_from_iatt(&rsp->preparent, preparent); + gf_stat_from_iatt(&rsp->postparent, postparent); +} + +void +server_post_symlink(server_state_t *state, gfs3_symlink_rsp *rsp, + inode_t *inode, struct iatt *stbuf, struct iatt *preparent, + struct iatt *postparent, dict_t *xdata) +{ + inode_t *link_inode = NULL; + + gf_stat_from_iatt(&rsp->stat, stbuf); + gf_stat_from_iatt(&rsp->preparent, preparent); + gf_stat_from_iatt(&rsp->postparent, postparent); + + link_inode = inode_link(inode, state->loc.parent, state->loc.name, stbuf); + inode_lookup(link_inode); + inode_unref(link_inode); +} + +void +server_post_link(server_state_t *state, gfs3_link_rsp *rsp, inode_t *inode, + struct iatt *stbuf, struct iatt *preparent, + struct iatt *postparent, dict_t *xdata) +{ + inode_t *link_inode = NULL; + + gf_stat_from_iatt(&rsp->stat, stbuf); + gf_stat_from_iatt(&rsp->preparent, preparent); + gf_stat_from_iatt(&rsp->postparent, postparent); + + link_inode = inode_link(inode, state->loc2.parent, state->loc2.name, stbuf); + inode_lookup(link_inode); + inode_unref(link_inode); +} + +void +server_post_truncate(gfs3_truncate_rsp *rsp, struct iatt *prebuf, + struct iatt *postbuf) +{ + gf_stat_from_iatt(&rsp->prestat, prebuf); + gf_stat_from_iatt(&rsp->poststat, postbuf); +} + +void +server_post_writev(gfs3_write_rsp *rsp, struct iatt *prebuf, + struct iatt *postbuf) +{ + gf_stat_from_iatt(&rsp->prestat, prebuf); + gf_stat_from_iatt(&rsp->poststat, postbuf); +} + +void +server_post_statfs(gfs3_statfs_rsp *rsp, struct statvfs *stbuf) +{ + gf_statfs_from_statfs(&rsp->statfs, stbuf); +} + +void +server_post_fsync(gfs3_fsync_rsp *rsp, struct iatt *prebuf, + struct iatt *postbuf) +{ + gf_stat_from_iatt(&rsp->prestat, prebuf); + gf_stat_from_iatt(&rsp->poststat, postbuf); +} + +void +server_post_ftruncate(gfs3_ftruncate_rsp *rsp, struct iatt *prebuf, + struct iatt *postbuf) +{ + gf_stat_from_iatt(&rsp->prestat, prebuf); + gf_stat_from_iatt(&rsp->poststat, postbuf); +} + +void +server_post_fstat(server_state_t *state, gfs3_fstat_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 */ + static uuid_t gfid = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; + + stbuf->ia_ino = 1; + gf_uuid_copy(stbuf->ia_gfid, gfid); + } + + gf_stat_from_iatt(&rsp->stat, stbuf); +} + +void +server_post_lk(xlator_t *this, gfs3_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 +server_post_readdir(gfs3_readdir_rsp *rsp, gf_dirent_t *entries) +{ + int ret = 0; + + ret = serialize_rsp_dirent(entries, rsp); + + return ret; +} +void +server_post_zerofill(gfs3_zerofill_rsp *rsp, struct iatt *statpre, + struct iatt *statpost) +{ + gf_stat_from_iatt(&rsp->statpre, statpre); + gf_stat_from_iatt(&rsp->statpost, statpost); +} + +void +server_post_discard(gfs3_discard_rsp *rsp, struct iatt *statpre, + struct iatt *statpost) +{ + gf_stat_from_iatt(&rsp->statpre, statpre); + gf_stat_from_iatt(&rsp->statpost, statpost); +} + +void +server_post_fallocate(gfs3_fallocate_rsp *rsp, struct iatt *statpre, + struct iatt *statpost) +{ + gf_stat_from_iatt(&rsp->statpre, statpre); + gf_stat_from_iatt(&rsp->statpost, statpost); +} + +void +server_post_seek(gfs3_seek_rsp *rsp, off_t offset) +{ + rsp->offset = offset; +} + +int +server_post_readdirp(gfs3_readdirp_rsp *rsp, gf_dirent_t *entries) +{ + int ret = 0; + + ret = serialize_rsp_direntp(entries, rsp); + + return ret; +} + +void +server_post_fsetattr(gfs3_fsetattr_rsp *rsp, struct iatt *statpre, + struct iatt *statpost) +{ + gf_stat_from_iatt(&rsp->statpre, statpre); + gf_stat_from_iatt(&rsp->statpost, statpost); +} + +void +server_post_setattr(gfs3_setattr_rsp *rsp, struct iatt *statpre, + struct iatt *statpost) +{ + gf_stat_from_iatt(&rsp->statpre, statpre); + gf_stat_from_iatt(&rsp->statpost, statpost); +} + +void +server_post_rchecksum(gfs3_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 = MD5_DIGEST_LENGTH; +} + +void +server_post_rename(call_frame_t *frame, server_state_t *state, + gfs3_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); + gf_stat_from_iatt(&rsp->stat, stbuf); + + gf_stat_from_iatt(&rsp->preoldparent, preoldparent); + gf_stat_from_iatt(&rsp->postoldparent, postoldparent); + + gf_stat_from_iatt(&rsp->prenewparent, prenewparent); + gf_stat_from_iatt(&rsp->postnewparent, postnewparent); +} + +int +server_post_open(call_frame_t *frame, xlator_t *this, gfs3_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 +server_post_readv(gfs3_read_rsp *rsp, struct iatt *stbuf, int op_ret) +{ + gf_stat_from_iatt(&rsp->stat, stbuf); + rsp->size = op_ret; +} + +int +server_post_opendir(call_frame_t *frame, xlator_t *this, gfs3_opendir_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; +} + +int +server_post_create(call_frame_t *frame, gfs3_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; + gf_stat_from_iatt(&rsp->stat, stbuf); + gf_stat_from_iatt(&rsp->preparent, preparent); + gf_stat_from_iatt(&rsp->postparent, postparent); + + return 0; +out: + return -op_errno; +} + +/*TODO: Handle revalidate path */ +void +server_post_lookup(gfs3_lookup_rsp *rsp, call_frame_t *frame, + server_state_t *state, inode_t *inode, struct iatt *stbuf, + struct iatt *postparent) +{ + inode_t *root_inode = NULL; + inode_t *link_inode = NULL; + static uuid_t rootgfid = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; + + 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; + gf_uuid_copy(stbuf->ia_gfid, rootgfid); + if (inode->ia_type == 0) + inode->ia_type = stbuf->ia_type; + } + + gf_stat_from_iatt(&rsp->stat, stbuf); +} + +void +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 */ + static uuid_t gfid = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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_3iatt_noinode(gfx_common_3iatt_rsp *rsp, struct iatt *stbuf, + struct iatt *prebuf_dst, + struct iatt *postbuf_dst) +{ + gfx_stat_from_iattx(&rsp->stat, stbuf); + gfx_stat_from_iattx(&rsp->preparent, prebuf_dst); + gfx_stat_from_iattx(&rsp->postparent, postbuf_dst); +} + +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 */ + static uuid_t gfid = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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; + /* When the length encoding changes, update the change + in posix code also. */ + rsp->strong_checksum.strong_checksum_val = (char *)strong_checksum; + rsp->strong_checksum.strong_checksum_len = SHA256_DIGEST_LENGTH; + rsp->flags = 1; /* Indicates SHA256 TYPE */ +} + +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; + static uuid_t rootgfid = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; + + 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; + 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) +{ + 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 new file mode 100644 index 00000000000..6200415e304 --- /dev/null +++ b/xlators/protocol/server/src/server-common.h @@ -0,0 +1,199 @@ +#include "server.h" +#include <glusterfs/defaults.h> +#include "rpc-common-xdr.h" +#include "glusterfs3-xdr.h" +#include "glusterfs3.h" +#include <glusterfs/compat-errno.h> +#include "server-messages.h" +#include <glusterfs/defaults.h> + +#include "xdr-nfs3.h" +void +server_post_stat(server_state_t *state, gfs3_stat_rsp *rsp, struct iatt *stbuf); + +void +server_post_readlink(gfs3_readlink_rsp *rsp, struct iatt *stbuf, + const char *buf); + +void +server_post_mknod(server_state_t *state, gfs3_mknod_rsp *rsp, + struct iatt *stbuf, struct iatt *preparent, + struct iatt *postparent, inode_t *inode); +void +server_post_mkdir(server_state_t *state, gfs3_mkdir_rsp *rsp, inode_t *inode, + struct iatt *stbuf, struct iatt *preparent, + struct iatt *postparent, dict_t *xdata); + +void +server_post_unlink(server_state_t *state, gfs3_unlink_rsp *rsp, + struct iatt *preparent, struct iatt *postparent); +void +server_post_rmdir(server_state_t *state, gfs3_rmdir_rsp *rsp, + struct iatt *preparent, struct iatt *postparent); + +void +server_post_symlink(server_state_t *state, gfs3_symlink_rsp *rsp, + inode_t *inode, struct iatt *stbuf, struct iatt *preparent, + struct iatt *postparent, dict_t *xdata); +void +server_post_link(server_state_t *state, gfs3_link_rsp *rsp, inode_t *inode, + struct iatt *stbuf, struct iatt *preparent, + struct iatt *postparent, dict_t *xdata); +void +server_post_truncate(gfs3_truncate_rsp *rsp, struct iatt *prebuf, + struct iatt *postbuf); + +void +server_post_writev(gfs3_write_rsp *rsp, struct iatt *prebuf, + struct iatt *postbuf); +void +server_post_statfs(gfs3_statfs_rsp *rsp, struct statvfs *stbuf); + +void +server_post_fsync(gfs3_fsync_rsp *rsp, struct iatt *prebuf, + struct iatt *postbuf); + +void +server_post_ftruncate(gfs3_ftruncate_rsp *rsp, struct iatt *prebuf, + struct iatt *postbuf); + +void +server_post_fstat(server_state_t *state, gfs3_fstat_rsp *rsp, + struct iatt *stbuf); + +void +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); + +void +server_post_zerofill(gfs3_zerofill_rsp *rsp, struct iatt *statpre, + struct iatt *statpost); + +void +server_post_discard(gfs3_discard_rsp *rsp, struct iatt *statpre, + struct iatt *statpost); + +void +server_post_fallocate(gfs3_fallocate_rsp *rsp, struct iatt *statpre, + struct iatt *statpost); + +void +server_post_seek(gfs3_seek_rsp *rsp, off_t offset); + +int +server_post_readdirp(gfs3_readdirp_rsp *rsp, gf_dirent_t *entries); + +void +server_post_fsetattr(gfs3_fsetattr_rsp *rsp, struct iatt *statpre, + struct iatt *statpost); + +void +server_post_setattr(gfs3_setattr_rsp *rsp, struct iatt *statpre, + struct iatt *statpost); + +void +server_post_rchecksum(gfs3_rchecksum_rsp *rsp, uint32_t weak_checksum, + uint8_t *strong_checksum); + +void +server_post_rename(call_frame_t *frame, server_state_t *state, + gfs3_rename_rsp *rsp, struct iatt *stbuf, + struct iatt *preoldparent, struct iatt *postoldparent, + struct iatt *prenewparent, struct iatt *postnewparent); + +int +server_post_open(call_frame_t *frame, xlator_t *this, gfs3_open_rsp *rsp, + fd_t *fd); +void +server_post_readv(gfs3_read_rsp *rsp, struct iatt *stbuf, int op_ret); + +int +server_post_opendir(call_frame_t *frame, xlator_t *this, gfs3_opendir_rsp *rsp, + fd_t *fd); + +int +server_post_create(call_frame_t *frame, gfs3_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 +server_post_lookup(gfs3_lookup_rsp *rsp, call_frame_t *frame, + server_state_t *state, inode_t *inode, struct iatt *stbuf, + struct iatt *postparent); + +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); + +void +server4_post_common_3iatt_noinode(gfx_common_3iatt_rsp *rsp, struct iatt *stbuf, + struct iatt *prebuf_dst, + struct iatt *postbuf_dst); diff --git a/xlators/protocol/server/src/server-handshake.c b/xlators/protocol/server/src/server-handshake.c index b148f06690d..85c87c1ab8b 100644 --- a/xlators/protocol/server/src/server-handshake.c +++ b/xlators/protocol/server/src/server-handshake.c @@ -1,675 +1,796 @@ /* - Copyright (c) 2010 Gluster, Inc. <http://www.gluster.com> + Copyright (c) 2010-2013 Red Hat, Inc. <http://www.redhat.com> This file is part of GlusterFS. - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. + 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. */ - -#ifndef _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif - #include "server.h" #include "server-helpers.h" +#include "rpc-common-xdr.h" #include "glusterfs3-xdr.h" -#include "compat-errno.h" +#include <glusterfs/compat-errno.h> #include "glusterfs3.h" #include "authenticate.h" +#include "server-messages.h" +#include <glusterfs/syscall.h> +#include <glusterfs/events.h> +#include <glusterfs/syncop.h> struct __get_xl_struct { - const char *name; - xlator_t *reply; + const char *name; + xlator_t *reply; }; int -gf_compare_client_version (rpcsvc_request_t *req, int fop_prognum, - int mgmt_prognum) -{ - int ret = -1; - /* TODO: think.. */ - if (glusterfs3_1_fop_prog.prognum == fop_prognum) - ret = 0; - - return ret; -} - -void __check_and_set (xlator_t *each, void *data) -{ - if (!strcmp (each->name, - ((struct __get_xl_struct *) data)->name)) - ((struct __get_xl_struct *) data)->reply = each; -} - -static xlator_t * -get_xlator_by_name (xlator_t *some_xl, const char *name) +gf_compare_client_version(rpcsvc_request_t *req, int fop_prognum, + int mgmt_prognum) { - struct __get_xl_struct get = { - .name = name, - .reply = NULL - }; + int ret = -1; + /* TODO: think.. */ + if (glusterfs3_3_fop_prog.prognum == fop_prognum) + ret = 0; - xlator_foreach (some_xl, __check_and_set, &get); - - return get.reply; + return ret; } - int -_volfile_update_checksum (xlator_t *this, char *key, uint32_t checksum) +server_getspec(rpcsvc_request_t *req) { - server_conf_t *conf = NULL; - struct _volfile_ctx *temp_volfile = NULL; - - conf = this->private; - temp_volfile = conf->volfile; - - while (temp_volfile) { - if ((NULL == key) && (NULL == temp_volfile->key)) - break; - if ((NULL == key) || (NULL == temp_volfile->key)) { - temp_volfile = temp_volfile->next; - continue; - } - if (strcmp (temp_volfile->key, key) == 0) - break; - temp_volfile = temp_volfile->next; - } - - if (!temp_volfile) { - temp_volfile = GF_CALLOC (1, sizeof (struct _volfile_ctx), - gf_server_mt_volfile_ctx_t); - if (!temp_volfile) - goto out; - temp_volfile->next = conf->volfile; - temp_volfile->key = (key)? gf_strdup (key): NULL; - temp_volfile->checksum = checksum; - - conf->volfile = temp_volfile; - goto out; - } + int32_t ret = 0; + int32_t op_errno = ENOENT; + gf_getspec_req args = { + 0, + }; + gf_getspec_rsp rsp = { + 0, + }; + + ret = xdr_to_generic(req->msg[0], &args, (xdrproc_t)xdr_gf_getspec_req); + if (ret < 0) { + // failed to decode msg; + req->rpc_err = GARBAGE_ARGS; + op_errno = EINVAL; + goto fail; + } + + op_errno = ENOSYS; +fail: + rsp.spec = "<this method is not in use, use glusterd for getspec>"; + rsp.op_errno = gf_errno_to_error(op_errno); + rsp.op_ret = -1; - if (temp_volfile->checksum != checksum) { - gf_log (this->name, GF_LOG_CRITICAL, - "the volume file got modified between earlier access " - "and now, this may lead to inconsistency between " - "clients, advised to remount client"); - temp_volfile->checksum = checksum; - } + server_submit_reply(NULL, req, &rsp, NULL, 0, NULL, + (xdrproc_t)xdr_gf_getspec_rsp); - out: - return 0; + return 0; } - -static size_t -getspec_build_volfile_path (xlator_t *this, const char *key, char *path, - size_t path_len) +static void +server_first_lookup_done(rpcsvc_request_t *req, gf_setvolume_rsp *rsp) { - int ret = -1; - int free_filename = 0; - char *filename = NULL; - server_conf_t *conf = NULL; - char data_key[256] = {0,}; - - conf = this->private; - - /* Inform users that this option is changed now */ - ret = dict_get_str (this->options, "client-volume-filename", - &filename); - if (ret == 0) { - gf_log (this->name, GF_LOG_WARNING, - "option 'client-volume-filename' is changed to " - "'volume-filename.<key>' which now takes 'key' as an " - "option to choose/fetch different files from server. " - "Refer documentation or contact developers for more " - "info. Currently defaulting to given file '%s'", - filename); - } - - if (key && !filename) { - sprintf (data_key, "volume-filename.%s", key); - ret = dict_get_str (this->options, data_key, &filename); - if (ret < 0) { - /* Make sure that key doesn't contain "../" in path */ - if ((gf_strstr (key, "/", "..")) == -1) { - gf_log (this->name, GF_LOG_ERROR, - "%s: invalid key", key); - goto out; - } - } - } - - if (!filename) { - ret = dict_get_str (this->options, - "volume-filename.default", &filename); - if (ret < 0) { - gf_log (this->name, GF_LOG_DEBUG, - "no default volume filename given, " - "defaulting to %s", DEFAULT_VOLUME_FILE_PATH); - } - } - - if (!filename && key) { - ret = gf_asprintf (&filename, "%s/%s.vol", conf->conf_dir, key); - if (-1 == ret) - goto out; + server_submit_reply(NULL, req, rsp, NULL, 0, NULL, + (xdrproc_t)xdr_gf_setvolume_rsp); - free_filename = 1; - } - if (!filename) - filename = DEFAULT_VOLUME_FILE_PATH; - - ret = -1; - - if ((filename) && (path_len > strlen (filename))) { - strcpy (path, filename); - ret = strlen (filename); - } - -out: - if (free_filename) - GF_FREE (filename); - - return ret; + GF_FREE(rsp->dict.dict_val); + GF_FREE(rsp); } -int -_validate_volfile_checksum (xlator_t *this, char *key, - uint32_t checksum) +static inode_t * +do_path_lookup(xlator_t *xl, dict_t *dict, inode_t *parinode, char *basename) { - char filename[ZR_PATH_MAX] = {0,}; - server_conf_t *conf = NULL; - struct _volfile_ctx *temp_volfile = NULL; - int ret = 0; - int fd = 0; - uint32_t local_checksum = 0; - - conf = this->private; - temp_volfile = conf->volfile; - - if (!checksum) - goto out; - - if (!temp_volfile) { - ret = getspec_build_volfile_path (this, key, filename, - sizeof (filename)); - if (ret <= 0) - goto out; - fd = open (filename, O_RDONLY); - if (-1 == fd) { - ret = 0; - gf_log (this->name, GF_LOG_DEBUG, - "failed to open volume file (%s) : %s", - filename, strerror (errno)); - goto out; - } - get_checksum_for_file (fd, &local_checksum); - _volfile_update_checksum (this, key, local_checksum); - close (fd); - } - - temp_volfile = conf->volfile; - while (temp_volfile) { - if ((NULL == key) && (NULL == temp_volfile->key)) - break; - if ((NULL == key) || (NULL == temp_volfile->key)) { - temp_volfile = temp_volfile->next; - continue; - } - if (strcmp (temp_volfile->key, key) == 0) - break; - temp_volfile = temp_volfile->next; - } - - if (!temp_volfile) - goto out; - - if ((temp_volfile->checksum) && - (checksum != temp_volfile->checksum)) - ret = -1; + int ret = 0; + loc_t loc = { + 0, + }; + uuid_t gfid = { + 0, + }; + struct iatt iatt = { + 0, + }; + inode_t *inode = NULL; + + loc.parent = parinode; + loc_touchup(&loc, basename); + loc.inode = inode_new(xl->itable); + + gf_uuid_generate(gfid); + ret = dict_set_gfuuid(dict, "gfid-req", gfid, true); + if (ret) { + gf_log(xl->name, GF_LOG_ERROR, "failed to set 'gfid-req' for subdir"); + goto out; + } + + ret = syncop_lookup(xl, &loc, &iatt, NULL, dict, NULL); + if (ret < 0) { + gf_log(xl->name, GF_LOG_ERROR, "first lookup on subdir (%s) failed: %s", + basename, strerror(errno)); + } + + /* Inode linking is required so that the + resolution happens all fine for future fops */ + inode = inode_link(loc.inode, loc.parent, loc.name, &iatt); + + /* Extra ref so the pointer is valid till client is valid */ + /* FIXME: not a priority, but this can lead to some inode + leaks if subdir is more than 1 level depth. Leak is only + per subdir entry, and not dependent on number of + connections, so it should be fine for now */ + inode_ref(inode); out: - return ret; + return inode; } - int -server_getspec (rpcsvc_request_t *req) +server_first_lookup(xlator_t *this, client_t *client, dict_t *reply) { - int32_t ret = -1; - int32_t op_errno = ENOENT; - int32_t spec_fd = -1; - size_t file_len = 0; - char filename[ZR_PATH_MAX] = {0,}; - struct stat stbuf = {0,}; - uint32_t checksum = 0; - char *key = NULL; - server_conf_t *conf = NULL; - xlator_t *this = NULL; - gf_getspec_req args = {0,}; - gf_getspec_rsp rsp = {0,}; - server_connection_t *conn = NULL; - - conn = req->trans->private; - this = req->svc->mydata; - conf = this->private; - if (xdr_to_glusterfs_req (req, &args, xdr_to_getspec_req)) { - //failed to decode msg; - req->rpc_err = GARBAGE_ARGS; - op_errno = EINVAL; + loc_t loc = { + 0, + }; + struct iatt iatt = { + 0, + }; + dict_t *dict = NULL; + int ret = 0; + xlator_t *xl = client->bound_xl; + char *msg = NULL; + inode_t *inode = NULL; + char *bname = NULL; + char *str = NULL; + char *tmp = NULL; + char *saveptr = NULL; + + loc.path = "/"; + loc.name = ""; + loc.inode = xl->itable->root; + loc.parent = NULL; + gf_uuid_copy(loc.gfid, loc.inode->gfid); + + ret = syncop_lookup(xl, &loc, &iatt, NULL, NULL, NULL); + if (ret < 0) + gf_log(xl->name, GF_LOG_ERROR, "lookup on root failed: %s", + strerror(errno)); + /* Ignore error from lookup, don't set + * failure in rsp->op_ret. lookup on a snapview-server + * can fail with ESTALE + */ + /* TODO-SUBDIR-MOUNT: validate above comment with respect to subdir lookup + */ + + if (client->subdir_mount) { + str = tmp = gf_strdup(client->subdir_mount); + dict = dict_new(); + inode = xl->itable->root; + bname = strtok_r(str, "/", &saveptr); + while (bname != NULL) { + inode = do_path_lookup(xl, dict, inode, bname); + if (inode == NULL) { + gf_log(this->name, GF_LOG_ERROR, + "first lookup on subdir (%s) failed: %s", + client->subdir_mount, strerror(errno)); + ret = -1; goto fail; + } + bname = strtok_r(NULL, "/", &saveptr); } - ret = getspec_build_volfile_path (this, args.key, - filename, sizeof (filename)); - if (ret > 0) { - /* to allocate the proper buffer to hold the file data */ - ret = stat (filename, &stbuf); - if (ret < 0){ - gf_log (this->name, GF_LOG_ERROR, - "Unable to stat %s (%s)", - filename, strerror (errno)); - op_errno = errno; - goto fail; - } - - spec_fd = open (filename, O_RDONLY); - if (spec_fd < 0) { - gf_log (this->name, GF_LOG_ERROR, - "Unable to open %s (%s)", - filename, strerror (errno)); - op_errno = errno; - goto fail; - } - ret = file_len = stbuf.st_size; - - if (conf->verify_volfile) { - get_checksum_for_file (spec_fd, &checksum); - _volfile_update_checksum (this, key, checksum); - } - } else { - op_errno = ENOENT; - } + /* Can be used in server_resolve() */ + gf_uuid_copy(client->subdir_gfid, inode->gfid); + client->subdir_inode = inode; + } - if (file_len) { - rsp.spec = GF_CALLOC (file_len, sizeof (char), - gf_server_mt_rsp_buf_t); - if (!rsp.spec) { - ret = -1; - op_errno = ENOMEM; - goto fail; - } - ret = read (spec_fd, rsp.spec, file_len); - - close (spec_fd); - } + ret = 0; + goto out; - /* convert to XDR */ - op_errno = errno; fail: - if (!rsp.spec) - rsp.spec = ""; - rsp.op_errno = gf_errno_to_error (op_errno); - rsp.op_ret = ret; + /* we should say to client, it is not possible + to connect */ + ret = gf_asprintf(&msg, "subdirectory for mount \"%s\" is not found", + client->subdir_mount); + if (-1 == ret) { + gf_msg(this->name, GF_LOG_ERROR, 0, PS_MSG_ASPRINTF_FAILED, + "asprintf failed while setting error msg"); + } + ret = dict_set_dynstr(reply, "ERROR", msg); + if (ret < 0) + gf_msg_debug(this->name, 0, + "failed to set error " + "msg"); + + ret = -1; +out: + if (dict) + dict_unref(dict); - server_submit_reply (NULL, req, &rsp, NULL, 0, NULL, - (gfs_serialize_t)xdr_serialize_getspec_rsp); + inode_unref(loc.inode); - return 0; -} + if (tmp) + GF_FREE(tmp); + return ret; +} int -server_setvolume (rpcsvc_request_t *req) +server_setvolume(rpcsvc_request_t *req) { - gf_setvolume_req args = {0,}; - gf_setvolume_rsp rsp = {0,}; - server_connection_t *conn = NULL; - server_conf_t *conf = NULL; - peer_info_t *peerinfo = NULL; - dict_t *reply = NULL; - dict_t *config_params = NULL; - dict_t *params = NULL; - char *name = NULL; - char *process_uuid = NULL; - xlator_t *xl = NULL; - char *msg = NULL; - char *volfile_key = NULL; - xlator_t *this = NULL; - uint32_t checksum = 0; - int32_t ret = -1; - int32_t op_ret = -1; - int32_t op_errno = EINVAL; - int32_t fop_version = 0; - int32_t mgmt_version = 0; - char *buf = NULL; - - params = dict_new (); - reply = dict_new (); - if (xdr_to_glusterfs_req (req, &args, xdr_to_setvolume_req)) { - //failed to decode msg; - req->rpc_err = GARBAGE_ARGS; - goto fail; + gf_setvolume_req args = { + { + 0, + }, + }; + gf_setvolume_rsp *rsp = NULL; + client_t *client = NULL; + server_ctx_t *serv_ctx = NULL; + server_conf_t *conf = NULL; + peer_info_t *peerinfo = NULL; + dict_t *reply = NULL; + dict_t *config_params = NULL; + dict_t *params = NULL; + char *name = NULL; + char *volume_id = NULL; + char *client_uid = NULL; + char *clnt_version = NULL; + xlator_t *xl = NULL; + char *msg = NULL; + xlator_t *this = NULL; + int32_t ret = -1; + int32_t op_ret = -1; + int32_t op_errno = EINVAL; + uint32_t opversion = 0; + rpc_transport_t *xprt = NULL; + int32_t fop_version = 0; + int32_t mgmt_version = 0; + glusterfs_ctx_t *ctx = NULL; + struct _child_status *tmp = NULL; + char *subdir_mount = NULL; + char *client_name = NULL; + gf_boolean_t cleanup_starting = _gf_false; + gf_boolean_t xlator_in_graph = _gf_true; + + params = dict_new(); + reply = dict_new(); + ret = xdr_to_generic(req->msg[0], &args, (xdrproc_t)xdr_gf_setvolume_req); + if (ret < 0) { + // failed to decode msg; + req->rpc_err = GARBAGE_ARGS; + goto fail; + } + ctx = THIS->ctx; + + this = req->svc->xl; + /* this is to ensure config_params is populated with the first brick + * details at first place if brick multiplexing is enabled + */ + config_params = dict_copy_with_ref(this->options, NULL); + + ret = dict_unserialize(args.dict.dict_val, args.dict.dict_len, ¶ms); + if (ret < 0) { + ret = dict_set_sizen_str_sizen(reply, "ERROR", + "Internal error: failed to unserialize " + "request dictionary"); + if (ret < 0) + gf_msg_debug(this->name, 0, + "failed to set error " + "msg \"%s\"", + "Internal error: failed " + "to unserialize request dictionary"); + + op_ret = -1; + op_errno = EINVAL; + goto fail; + } + + ret = dict_get_str(params, "remote-subvolume", &name); + if (ret < 0) { + ret = dict_set_str(reply, "ERROR", + "No remote-subvolume option specified"); + if (ret < 0) + gf_msg_debug(this->name, 0, + "failed to set error " + "msg"); + + op_ret = -1; + op_errno = EINVAL; + goto fail; + } + + LOCK(&ctx->volfile_lock); + { + xl = get_xlator_by_name(this, name); + if (!xl) { + xlator_in_graph = _gf_false; + xl = this; } - - this = req->svc->mydata; - - config_params = dict_copy_with_ref (this->options, NULL); - conf = this->private; - - buf = memdup (args.dict.dict_val, args.dict.dict_len); - if (buf == NULL) { - gf_log (this->name, GF_LOG_ERROR, "out of memory"); - op_ret = -1; - op_errno = ENOMEM; - goto fail; + } + UNLOCK(&ctx->volfile_lock); + if (xl == NULL) { + ret = gf_asprintf(&msg, "remote-subvolume \"%s\" is not found", name); + if (-1 == ret) { + gf_msg(this->name, GF_LOG_ERROR, 0, PS_MSG_ASPRINTF_FAILED, + "asprintf failed while setting error msg"); + goto fail; } - - ret = dict_unserialize (buf, args.dict.dict_len, ¶ms); - if (ret < 0) { - ret = dict_set_str (reply, "ERROR", - "Internal error: failed to unserialize " - "request dictionary"); - if (ret < 0) - gf_log (this->name, GF_LOG_DEBUG, - "failed to set error msg \"%s\"", - "Internal error: failed to unserialize " - "request dictionary"); - - op_ret = -1; - op_errno = EINVAL; - goto fail; + ret = dict_set_dynstr(reply, "ERROR", msg); + if (ret < 0) + gf_msg_debug(this->name, 0, + "failed to set error " + "msg"); + + op_ret = -1; + op_errno = ENOENT; + goto fail; + } + + config_params = dict_copy_with_ref(xl->options, config_params); + conf = this->private; + + if (conf->parent_up == _gf_false) { + /* PARENT_UP indicates that all xlators in graph are inited + * successfully + */ + op_ret = -1; + op_errno = EAGAIN; + + ret = dict_set_str(reply, "ERROR", + "xlator graph in server is not initialised " + "yet. Try again later"); + if (ret < 0) + gf_msg_debug(this->name, 0, + "failed to set error: " + "xlator graph in server is not " + "initialised yet. Try again later"); + goto fail; + } + + pthread_mutex_lock(&conf->mutex); + list_for_each_entry(tmp, &conf->child_status->status_list, status_list) + { + if (strcmp(tmp->name, name) == 0) + break; + } + + if (!tmp->name) { + gf_msg(this->name, GF_LOG_INFO, 0, PS_MSG_CHILD_STATUS_FAILED, + "No xlator %s is found in child status list", name); + } else { + ret = dict_set_int32(reply, "child_up", tmp->child_up); + if (ret < 0) + gf_msg(this->name, GF_LOG_ERROR, 0, PS_MSG_DICT_GET_FAILED, + "Failed to set 'child_up' for xlator %s " + "in the reply dict", + tmp->name); + if (!tmp->child_up) { + ret = dict_set_str(reply, "ERROR", + "Not received child_up for this xlator"); + if (ret < 0) + gf_msg_debug(this->name, 0, "failed to set error msg"); + + gf_msg(this->name, GF_LOG_ERROR, 0, PS_MSG_CHILD_STATUS_FAILED, + "Not received child_up for this xlator %s", name); + op_ret = -1; + op_errno = EAGAIN; + pthread_mutex_unlock(&conf->mutex); + goto fail; } - - params->extra_free = buf; - buf = NULL; - - ret = dict_get_str (params, "process-uuid", &process_uuid); - if (ret < 0) { - ret = dict_set_str (reply, "ERROR", - "UUID not specified"); - if (ret < 0) - gf_log (this->name, GF_LOG_DEBUG, - "failed to set error msg"); - - op_ret = -1; - op_errno = EINVAL; - goto fail; - } - - - conn = server_connection_get (this, process_uuid); - if (req->trans->xl_private != conn) - req->trans->xl_private = conn; - - ret = dict_get_int32 (params, "fops-version", &fop_version); - if (ret < 0) { - ret = dict_set_str (reply, "ERROR", - "No FOP version number specified"); - if (ret < 0) - gf_log (this->name, GF_LOG_DEBUG, - "failed to set error msg"); - } - - ret = dict_get_int32 (params, "mgmt-version", &mgmt_version); - if (ret < 0) { - ret = dict_set_str (reply, "ERROR", - "No MGMT version number specified"); - if (ret < 0) - gf_log (this->name, GF_LOG_DEBUG, - "failed to set error msg"); + } + pthread_mutex_unlock(&conf->mutex); + + ret = dict_get_str(params, "process-uuid", &client_uid); + if (ret < 0) { + ret = dict_set_str(reply, "ERROR", "UUID not specified"); + if (ret < 0) + gf_msg_debug(this->name, 0, + "failed to set error " + "msg"); + + op_ret = -1; + op_errno = EINVAL; + goto fail; + } + + ret = dict_get_str(params, "subdir-mount", &subdir_mount); + if (ret < 0) { + /* Not a problem at all as the key is optional */ + } + ret = dict_get_str(params, "process-name", &client_name); + if (ret < 0) { + client_name = "unknown"; + } + + /* If any value is set, the first element will be non-0. + It would be '0', but not '\0' :-) */ + if (xl->graph->volume_id[0]) { + ret = dict_get_str_sizen(params, "volume-id", &volume_id); + if (!ret && strcmp(xl->graph->volume_id, volume_id)) { + ret = dict_set_str(reply, "ERROR", + "Volume-ID different, possible case " + "of same brick re-used in another volume"); + if (ret < 0) + gf_msg_debug(this->name, 0, "failed to set error msg"); + + op_ret = -1; + op_errno = EINVAL; + goto fail; } - - ret = gf_compare_client_version (req, fop_version, mgmt_version); - if (ret != 0) { - ret = gf_asprintf (&msg, "version mismatch: client(%d)" - " - client-mgmt(%d)", - fop_version, mgmt_version); - /* get_supported_version (req)); */ - if (-1 == ret) { - gf_log (this->name, GF_LOG_ERROR, - "asprintf failed while setting up error msg"); - goto fail; - } - ret = dict_set_dynstr (reply, "ERROR", msg); - if (ret < 0) - gf_log (this->name, GF_LOG_DEBUG, - "failed to set error msg"); - - op_ret = -1; - op_errno = EINVAL; - goto fail; - } - - ret = dict_get_str (params, "remote-subvolume", &name); - if (ret < 0) { - ret = dict_set_str (reply, "ERROR", - "No remote-subvolume option specified"); - if (ret < 0) - gf_log (this->name, GF_LOG_DEBUG, - "failed to set error msg"); - - op_ret = -1; - op_errno = EINVAL; - goto fail; - } - - xl = get_xlator_by_name (this, name); - if (xl == NULL) { - ret = gf_asprintf (&msg, "remote-subvolume \"%s\" is not found", - name); - if (-1 == ret) { - gf_log (this->name, GF_LOG_ERROR, - "asprintf failed while setting error msg"); - goto fail; - } - ret = dict_set_dynstr (reply, "ERROR", msg); - if (ret < 0) - gf_log (this->name, GF_LOG_DEBUG, - "failed to set error msg"); - - op_ret = -1; - op_errno = ENOENT; - goto fail; - } - - if (conf->verify_volfile) { - ret = dict_get_uint32 (params, "volfile-checksum", &checksum); - if (ret == 0) { - ret = dict_get_str (params, "volfile-key", - &volfile_key); - if (ret) - gf_log (this->name, GF_LOG_DEBUG, - "failed to set 'volfile-key'"); - - ret = _validate_volfile_checksum (this, volfile_key, - checksum); - if (-1 == ret) { - ret = dict_set_str (reply, "ERROR", - "volume-file checksum " - "varies from earlier " - "access"); - if (ret < 0) - gf_log (this->name, GF_LOG_DEBUG, - "failed to set error msg"); - - op_ret = -1; - op_errno = ESTALE; - goto fail; - } - } - } - - - peerinfo = &req->trans->peerinfo; - if (peerinfo) { - ret = dict_set_static_ptr (params, "peer-info", peerinfo); - if (ret < 0) - gf_log (this->name, GF_LOG_DEBUG, - "failed to set peer-info"); + ret = dict_set_str(reply, "volume-id", tmp->volume_id); + if (ret) + gf_msg_debug(this->name, 0, "failed to set 'volume-id'"); + } + client = gf_client_get(this, &req->cred, client_uid, subdir_mount); + if (client == NULL) { + op_ret = -1; + op_errno = ENOMEM; + goto fail; + } + + client->client_name = gf_strdup(client_name); + + gf_msg_debug(this->name, 0, "Connected to %s", client->client_uid); + + serv_ctx = server_ctx_get(client, 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 fail; + } + + pthread_mutex_lock(&conf->mutex); + if (xl->cleanup_starting) { + cleanup_starting = _gf_true; + } else if (req->trans->xl_private != client) { + req->trans->xl_private = client; + } + pthread_mutex_unlock(&conf->mutex); + + if (cleanup_starting) { + op_ret = -1; + op_errno = EAGAIN; + + ret = dict_set_str(reply, "ERROR", + "cleanup flag is set for xlator. " + " Try again later"); + if (ret < 0) + gf_msg_debug(this->name, 0, + "failed to set error: " + "cleanup flag is set for xlator. " + "Try again later"); + goto fail; + } + + auth_set_username_passwd(params, config_params, client); + if (req->trans->ssl_name) { + if (dict_set_str(params, "ssl-name", req->trans->ssl_name) != 0) { + gf_msg(this->name, GF_LOG_WARNING, 0, PS_MSG_SSL_NAME_SET_FAILED, + "failed to set " + "ssl_name %s", + req->trans->ssl_name); + /* Not fatal, auth will just fail. */ } - if (conf->auth_modules == NULL) { - gf_log (this->name, GF_LOG_ERROR, - "Authentication module not initialized"); + } + + ret = dict_get_int32(params, "fops-version", &fop_version); + if (ret < 0) { + ret = dict_set_str(reply, "ERROR", "No FOP version number specified"); + if (ret < 0) + gf_msg_debug(this->name, 0, + "failed to set error " + "msg"); + } + + ret = dict_get_int32(params, "mgmt-version", &mgmt_version); + if (ret < 0) { + ret = dict_set_str(reply, "ERROR", "No MGMT version number specified"); + if (ret < 0) + gf_msg_debug(this->name, 0, + "failed to set error " + "msg"); + } + + ret = gf_compare_client_version(req, fop_version, mgmt_version); + if (ret != 0) { + ret = gf_asprintf(&msg, + "version mismatch: client(%d)" + " - client-mgmt(%d)", + fop_version, mgmt_version); + /* get_supported_version (req)); */ + if (-1 == ret) { + gf_msg(this->name, GF_LOG_ERROR, 0, PS_MSG_ASPRINTF_FAILED, + "asprintf failed while" + "setting up error msg"); + goto fail; } - - ret = gf_authenticate (params, config_params, - conf->auth_modules); - - if (ret == AUTH_ACCEPT) { - gf_log (this->name, GF_LOG_INFO, - "accepted client from %s", - (peerinfo)?peerinfo->identifier:""); - op_ret = 0; - conn->bound_xl = xl; - ret = dict_set_str (reply, "ERROR", "Success"); - if (ret < 0) - gf_log (this->name, GF_LOG_DEBUG, - "failed to set error msg"); + ret = dict_set_dynstr(reply, "ERROR", msg); + if (ret < 0) + gf_msg_debug(this->name, 0, + "failed to set error " + "msg"); + + op_ret = -1; + op_errno = EINVAL; + goto fail; + } + + peerinfo = &req->trans->peerinfo; + if (peerinfo) { + ret = dict_set_static_ptr(params, "peer-info", peerinfo); + if (ret < 0) + gf_msg_debug(this->name, 0, + "failed to set " + "peer-info"); + } + + ret = dict_get_uint32(params, "opversion", &opversion); + if (ret) { + gf_msg(this->name, GF_LOG_INFO, 0, PS_MSG_CLIENT_OPVERSION_GET_FAILED, + "Failed to get client opversion"); + } + client->opversion = opversion; + /* Assign op-version value to the client */ + pthread_mutex_lock(&conf->mutex); + list_for_each_entry(xprt, &conf->xprt_list, list) + { + if (strcmp(peerinfo->identifier, xprt->peerinfo.identifier)) + continue; + xprt->peerinfo.max_op_version = opversion; + } + pthread_mutex_unlock(&conf->mutex); + + if (conf->auth_modules == NULL) { + gf_msg(this->name, GF_LOG_ERROR, 0, PS_MSG_AUTH_INIT_FAILED, + "Authentication module not initialized"); + } + + ret = dict_get_str(params, "client-version", &clnt_version); + if (ret) + gf_msg(this->name, GF_LOG_INFO, 0, PS_MSG_CLIENT_VERSION_NOT_SET, + "client-version not set, may be of older version"); + + ret = gf_authenticate(params, config_params, conf->auth_modules); + + if (ret == AUTH_ACCEPT) { + /* Store options received from client side */ + req->trans->clnt_options = dict_ref(params); + + gf_msg(this->name, GF_LOG_INFO, 0, PS_MSG_CLIENT_ACCEPTED, + "accepted client from %s (version: %s) with subvol %s", + client->client_uid, (clnt_version) ? clnt_version : "old", name); + + gf_event(EVENT_CLIENT_CONNECT, + "client_uid=%s;" + "client_identifier=%s;server_identifier=%s;" + "brick_path=%s;subdir_mount=%s", + client->client_uid, req->trans->peerinfo.identifier, + req->trans->myinfo.identifier, name, subdir_mount); + + op_ret = 0; + client->bound_xl = xl; + + /* Don't be confused by the below line (like how ERROR can + be Success), key checked on client is 'ERROR' and hence + we send 'Success' in this key */ + ret = dict_set_str(reply, "ERROR", "Success"); + if (ret < 0) + gf_msg_debug(this->name, 0, + "failed to set error " + "msg"); + } else { + op_ret = -1; + if (!xlator_in_graph) { + gf_msg(this->name, GF_LOG_ERROR, ENOENT, PS_MSG_AUTHENTICATE_ERROR, + "Cannot authenticate client" + " from %s %s because brick is not attached in graph", + client->client_uid, (clnt_version) ? clnt_version : "old"); + + op_errno = ENOENT; + ret = dict_set_str(reply, "ERROR", "Brick not found"); } else { - gf_log (this->name, GF_LOG_ERROR, - "Cannot authenticate client from %s", - (peerinfo)? peerinfo->identifier:"<>"); - op_ret = -1; - op_errno = EACCES; - ret = dict_set_str (reply, "ERROR", "Authentication failed"); - if (ret < 0) - gf_log (this->name, GF_LOG_DEBUG, - "failed to set error msg"); - - goto fail; + gf_event(EVENT_CLIENT_AUTH_REJECT, + "client_uid=%s;" + "client_identifier=%s;server_identifier=%s;" + "brick_path=%s", + client->client_uid, req->trans->peerinfo.identifier, + req->trans->myinfo.identifier, name); + gf_msg(this->name, GF_LOG_ERROR, EACCES, PS_MSG_AUTHENTICATE_ERROR, + "Cannot authenticate client" + " from %s %s", + client->client_uid, (clnt_version) ? clnt_version : "old"); + + op_errno = EACCES; + ret = dict_set_str(reply, "ERROR", "Authentication failed"); } - - if (conn->bound_xl == NULL) { - ret = dict_set_str (reply, "ERROR", - "Check volfile and handshake " - "options in protocol/client"); - if (ret < 0) - gf_log (this->name, GF_LOG_DEBUG, - "failed to set error msg"); - - op_ret = -1; - op_errno = EACCES; - goto fail; - } - - if ((conn->bound_xl != NULL) && - (ret >= 0) && - (conn->bound_xl->itable == NULL)) { - /* create inode table for this bound_xl, if one doesn't - already exist */ - - gf_log (this->name, GF_LOG_TRACE, - "creating inode table with lru_limit=%"PRId32", " - "xlator=%s", conf->inode_lru_limit, - conn->bound_xl->name); - - /* TODO: what is this ? */ - conn->bound_xl->itable = inode_table_new (conf->inode_lru_limit, - conn->bound_xl); + if (ret < 0) + gf_msg_debug(this->name, 0, + "failed to set error " + "msg"); + goto fail; + } + + if (client->bound_xl == NULL) { + ret = dict_set_str(reply, "ERROR", + "Check volfile and handshake " + "options in protocol/client"); + if (ret < 0) + gf_msg_debug(this->name, 0, + "failed to set error " + "msg"); + + op_ret = -1; + op_errno = EACCES; + goto fail; + } + + LOCK(&conf->itable_lock); + { + if (client->bound_xl->itable == NULL) { + /* create inode table for this bound_xl, if one doesn't + already exist */ + + gf_msg_trace(this->name, 0, + "creating inode table with" + " lru_limit=%" PRId32 ", xlator=%s", + conf->inode_lru_limit, client->bound_xl->name); + + /* TODO: what is this ? */ + client->bound_xl->itable = inode_table_new(conf->inode_lru_limit, + client->bound_xl); } - - ret = dict_set_str (reply, "process-uuid", - this->ctx->process_uuid); - if (ret) - gf_log (this->name, GF_LOG_DEBUG, - "failed to set 'process-uuid'"); - - ret = dict_set_uint64 (reply, "transport-ptr", - ((uint64_t) (long) req->trans)); - if (ret) - gf_log (this->name, GF_LOG_DEBUG, - "failed to set 'transport-ptr'"); + } + UNLOCK(&conf->itable_lock); + + ret = dict_set_str(reply, "process-uuid", this->ctx->process_uuid); + if (ret) + gf_msg_debug(this->name, 0, "failed to set 'process-uuid'"); + + /* Insert a dummy key value pair to avoid failure at client side for + * clnt-lk-version with older clients. + */ + ret = dict_set_uint32(reply, "clnt-lk-version", 0); + if (ret) { + gf_msg(this->name, GF_LOG_WARNING, 0, PS_MSG_CLIENT_LK_VERSION_ERROR, + "failed to set " + "'clnt-lk-version'"); + } + + ret = dict_set_uint64(reply, "transport-ptr", ((uint64_t)(long)req->trans)); + if (ret) + gf_msg_debug(this->name, 0, "failed to set 'transport-ptr'"); fail: - rsp.dict.dict_len = dict_serialized_length (reply); - if (rsp.dict.dict_len < 0) { - gf_log ("server-handshake", GF_LOG_DEBUG, - "failed to get serialized length of reply dict"); - op_ret = -1; - op_errno = EINVAL; - rsp.dict.dict_len = 0; - } - - if (rsp.dict.dict_len) { - rsp.dict.dict_val = GF_CALLOC (1, rsp.dict.dict_len, - gf_server_mt_rsp_buf_t); - if (rsp.dict.dict_val) { - ret = dict_serialize (reply, rsp.dict.dict_val); - if (ret < 0) { - gf_log ("server-handshake", GF_LOG_DEBUG, - "failed to serialize reply dict"); - op_ret = -1; - op_errno = -ret; - } - } + /* It is important to validate the lookup on '/' as part of handshake, + because if lookup itself can't succeed, we should communicate this + to client. Very important in case of subdirectory mounts, where if + client is trying to mount a non-existing directory */ + if (op_ret >= 0 && client->bound_xl->itable) { + if (client->bound_xl->cleanup_starting) { + op_ret = -1; + op_errno = EAGAIN; + ret = dict_set_str(reply, "ERROR", + "cleanup flag is set for xlator " + "before call first_lookup Try again later"); + /* quisce coverity about UNUSED_VALUE ret */ + (void)(ret); + } else { + op_ret = server_first_lookup(this, client, reply); + if (op_ret == -1) + op_errno = ENOENT; } - rsp.op_ret = op_ret; - rsp.op_errno = gf_errno_to_error (op_errno); + } - server_submit_reply (NULL, req, &rsp, NULL, 0, NULL, - (gfs_serialize_t)xdr_serialize_setvolume_rsp); + rsp = GF_CALLOC(1, sizeof(gf_setvolume_rsp), gf_server_mt_setvolume_rsp_t); + GF_ASSERT(rsp); + rsp->op_ret = 0; - if (args.dict.dict_val) - free (args.dict.dict_val); + ret = dict_allocate_and_serialize(reply, (char **)&rsp->dict.dict_val, + &rsp->dict.dict_len); + if (ret != 0) { + ret = -1; + gf_msg_debug("server-handshake", 0, "failed to serialize reply dict"); + op_ret = -1; + op_errno = -ret; + } + + rsp->op_ret = op_ret; + rsp->op_errno = gf_errno_to_error(op_errno); + + /* if bound_xl is NULL or something fails, then put the connection + * back. Otherwise the connection would have been added to the + * list of connections the server is maintaining and might segfault + * during statedump when bound_xl of the connection is accessed. + */ + if (op_ret && !xl && (client != NULL)) { + /* We would have set the xl_private of the transport to the + * @conn. But if we have put the connection i.e shutting down + * the connection, then we should set xl_private to NULL as it + * would be pointing to a freed memory and would segfault when + * accessed upon getting DISCONNECT. + */ + gf_client_put(client, NULL); + req->trans->xl_private = NULL; + } + + /* Send the response properly */ + server_first_lookup_done(req, rsp); + + free(args.dict.dict_val); + + dict_unref(params); + dict_unref(reply); + if (config_params) { + /* + * This might be null if we couldn't even find the translator + * (brick) to copy it from. + */ + dict_unref(config_params); + } + + return 0; +} - if (rsp.dict.dict_val) - GF_FREE (rsp.dict.dict_val); +int +server_ping(rpcsvc_request_t *req) +{ + gf_common_rsp rsp = { + 0, + }; - dict_unref (params); - dict_unref (reply); - dict_unref (config_params); + /* Accepted */ + rsp.op_ret = 0; - if (buf) { - GF_FREE (buf); - } + server_submit_reply(NULL, req, &rsp, NULL, 0, NULL, + (xdrproc_t)xdr_gf_common_rsp); - return 0; + return 0; } - int -server_ping (rpcsvc_request_t *req) +server_set_lk_version(rpcsvc_request_t *req) { - gf_common_rsp rsp = {0,}; - - rsp.gfs_id = req->gfs_id; - /* Accepted */ - rsp.op_ret = 0; + int ret = -1; + gf_set_lk_ver_req args = { + 0, + }; + gf_set_lk_ver_rsp rsp = { + 0, + }; + + ret = xdr_to_generic(req->msg[0], &args, (xdrproc_t)xdr_gf_set_lk_ver_req); + if (ret < 0) { + /* failed to decode msg */ + req->rpc_err = GARBAGE_ARGS; + goto fail; + } + + rsp.lk_ver = args.lk_ver; +fail: + server_submit_reply(NULL, req, &rsp, NULL, 0, NULL, + (xdrproc_t)xdr_gf_set_lk_ver_rsp); - server_submit_reply (NULL, req, &rsp, NULL, 0, NULL, - xdr_serialize_common_rsp); + free(args.uid); - return 0; + return 0; } - -rpcsvc_actor_t gluster_handshake_actors[] = { - [GF_HNDSK_NULL] = {"NULL", GF_HNDSK_NULL, server_null, NULL, NULL }, - [GF_HNDSK_SETVOLUME] = {"SETVOLUME", GF_HNDSK_SETVOLUME, server_setvolume, NULL, NULL }, - [GF_HNDSK_GETSPEC] = {"GETSPEC", GF_HNDSK_GETSPEC, server_getspec, NULL, NULL }, - [GF_HNDSK_PING] = {"PING", GF_HNDSK_PING, server_ping, NULL, NULL }, +static rpcsvc_actor_t gluster_handshake_actors[GF_HNDSK_MAXVALUE] = { + [GF_HNDSK_NULL] = {"NULL", server_null, NULL, GF_HNDSK_NULL, DRC_NA, 0}, + [GF_HNDSK_SETVOLUME] = {"SETVOLUME", server_setvolume, NULL, + GF_HNDSK_SETVOLUME, DRC_NA, 0}, + [GF_HNDSK_GETSPEC] = {"GETSPEC", server_getspec, NULL, GF_HNDSK_GETSPEC, + DRC_NA, 0}, + [GF_HNDSK_PING] = {"PING", server_ping, NULL, GF_HNDSK_PING, DRC_NA, 0}, + [GF_HNDSK_SET_LK_VER] = {"SET_LK_VER", server_set_lk_version, NULL, + GF_HNDSK_SET_LK_VER, DRC_NA, 0}, }; - struct rpcsvc_program gluster_handshake_prog = { - .progname = "GlusterFS Handshake", - .prognum = GLUSTER_HNDSK_PROGRAM, - .progver = GLUSTER_HNDSK_VERSION, - .actors = gluster_handshake_actors, - .numactors = GF_HNDSK_MAXVALUE, + .progname = "GlusterFS Handshake", + .prognum = GLUSTER_HNDSK_PROGRAM, + .progver = GLUSTER_HNDSK_VERSION, + .actors = gluster_handshake_actors, + .numactors = GF_HNDSK_MAXVALUE, }; diff --git a/xlators/protocol/server/src/server-helpers.c b/xlators/protocol/server/src/server-helpers.c index 3415eb35cc3..6e644912a46 100644 --- a/xlators/protocol/server/src/server-helpers.c +++ b/xlators/protocol/server/src/server-helpers.c @@ -1,1297 +1,1507 @@ /* - Copyright (c) 2010 Gluster, Inc. <http://www.gluster.com> + Copyright (c) 2010-2013 Red Hat, Inc. <http://www.redhat.com> This file is part of GlusterFS. - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. + 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. */ -#ifndef _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif - #include "server.h" #include "server-helpers.h" +#include <glusterfs/gidcache.h> +#include "server-messages.h" +#include <glusterfs/syscall.h> +#include <glusterfs/defaults.h> +#include <glusterfs/default-args.h> +#include "server-common.h" +#include <fnmatch.h> +#include <pwd.h> + +/* based on nfs_fix_aux_groups() */ int -server_decode_groups (call_frame_t *frame, rpcsvc_request_t *req) +gid_resolve(server_conf_t *conf, call_stack_t *root) { - int i = 0; + int ret = 0; + struct passwd mypw; + char mystrs[1024]; + struct passwd *result; + gid_t *mygroups = NULL; + gid_list_t gl; + int ngroups; + const gid_list_t *agl; + + agl = gid_cache_lookup(&conf->gid_cache, root->uid, 0, 0); + if (agl) { + root->ngrps = agl->gl_count; + + if (root->ngrps > 0) { + ret = call_stack_alloc_groups(root, agl->gl_count); + if (ret == 0) { + memcpy(root->groups, agl->gl_list, + sizeof(gid_t) * agl->gl_count); + } + } - if ((!frame) || (!req)) - return 0; + gid_cache_release(&conf->gid_cache, agl); - frame->root->ngrps = req->auxgidcount; - if (frame->root->ngrps == 0) - return 0; + return ret; + } + + ret = getpwuid_r(root->uid, &mypw, mystrs, sizeof(mystrs), &result); + if (ret != 0) { + gf_smsg("gid-cache", GF_LOG_ERROR, errno, PS_MSG_GET_UID_FAILED, + "uid=%u", root->uid, NULL); + return -1; + } + + if (!result) { + gf_smsg("gid-cache", GF_LOG_ERROR, 0, PS_MSG_UID_NOT_FOUND, "uid=%u", + root->uid, NULL); + return -1; + } + + gf_msg_trace("gid-cache", 0, "mapped %u => %s", root->uid, result->pw_name); + + ngroups = gf_getgrouplist(result->pw_name, root->gid, &mygroups); + if (ngroups == -1) { + gf_smsg("gid-cache", GF_LOG_ERROR, 0, PS_MSG_MAPPING_ERROR, + "pw_name=%s", result->pw_name, "root->ngtps=%d", root->ngrps, + NULL); + return -1; + } + root->ngrps = (uint16_t)ngroups; + + /* setup a full gid_list_t to add it to the gid_cache */ + gl.gl_id = root->uid; + gl.gl_uid = root->uid; + gl.gl_gid = root->gid; + gl.gl_count = root->ngrps; + + gl.gl_list = GF_MALLOC(root->ngrps * sizeof(gid_t), gf_common_mt_groups_t); + if (gl.gl_list) + memcpy(gl.gl_list, mygroups, sizeof(gid_t) * root->ngrps); + else { + GF_FREE(mygroups); + return -1; + } + + if (root->ngrps > 0) { + call_stack_set_groups(root, root->ngrps, &mygroups); + } + + if (gid_cache_add(&conf->gid_cache, &gl) != 1) + GF_FREE(gl.gl_list); + + return ret; +} - if (frame->root->ngrps > GF_REQUEST_MAXGROUPS) - return -1; +int +server_resolve_groups(call_frame_t *frame, rpcsvc_request_t *req) +{ + xlator_t *this = NULL; + server_conf_t *conf = NULL; - for (; i < frame->root->ngrps; ++i) - frame->root->groups[i] = req->auxgids[i]; + GF_VALIDATE_OR_GOTO("server", frame, out); + GF_VALIDATE_OR_GOTO("server", req, out); - return 0; + this = req->trans->xl; + conf = this->private; + + return gid_resolve(conf, frame->root); +out: + return -1; } -void -server_loc_wipe (loc_t *loc) +int +server_decode_groups(call_frame_t *frame, rpcsvc_request_t *req) { - if (loc->parent) { - inode_unref (loc->parent); - loc->parent = NULL; - } + int i = 0; - if (loc->inode) { - inode_unref (loc->inode); - loc->inode = NULL; - } + GF_VALIDATE_OR_GOTO("server", frame, out); + GF_VALIDATE_OR_GOTO("server", req, out); - if (loc->path) - GF_FREE ((void *)loc->path); -} + if (call_stack_alloc_groups(frame->root, req->auxgidcount) != 0) + return -1; + + frame->root->ngrps = req->auxgidcount; + if (frame->root->ngrps == 0) + return 0; + /* ngrps cannot be bigger than USHRT_MAX(65535) */ + if (frame->root->ngrps > GF_MAX_AUX_GROUPS) + return -1; + + for (; i < frame->root->ngrps; ++i) + frame->root->groups[i] = req->auxgids[i]; +out: + return 0; +} void -server_resolve_wipe (server_resolve_t *resolve) +server_loc_wipe(loc_t *loc) { - struct resolve_comp *comp = NULL; - int i = 0; + if (loc->parent) { + inode_unref(loc->parent); + loc->parent = NULL; + } - if (resolve->path) - GF_FREE ((void *)resolve->path); + if (loc->inode) { + inode_unref(loc->inode); + loc->inode = NULL; + } - if (resolve->bname) - GF_FREE ((void *)resolve->bname); + GF_FREE((void *)loc->path); +} - if (resolve->resolved) - GF_FREE ((void *)resolve->resolved); +void +server_resolve_wipe(server_resolve_t *resolve) +{ + GF_FREE((void *)resolve->path); - loc_wipe (&resolve->deep_loc); + GF_FREE((void *)resolve->bname); - comp = resolve->components; - if (comp) { - for (i = 0; comp[i].basename; i++) { - if (comp[i].inode) - inode_unref (comp[i].inode); - } - GF_FREE ((void *)resolve->components); - } + loc_wipe(&resolve->resolve_loc); } - void -free_state (server_state_t *state) +free_state(server_state_t *state) { - if (state->conn) { - //xprt_svc_unref (state->conn); - state->conn = NULL; - } + if (state->fd) { + fd_unref(state->fd); + state->fd = NULL; + } + + if (state->params) { + dict_unref(state->params); + state->params = NULL; + } + + if (state->iobref) { + iobref_unref(state->iobref); + state->iobref = NULL; + } + + if (state->iobuf) { + iobuf_unref(state->iobuf); + state->iobuf = NULL; + } + + if (state->dict) { + dict_unref(state->dict); + state->dict = NULL; + } + + if (state->xdata) { + dict_unref(state->xdata); + state->xdata = NULL; + } + + GF_FREE((void *)state->volume); + + GF_FREE((void *)state->name); + + server_loc_wipe(&state->loc); + server_loc_wipe(&state->loc2); + + server_resolve_wipe(&state->resolve); + server_resolve_wipe(&state->resolve2); + + /* Call rpc_trnasport_unref to avoid crashes at last after free + all resources because of server_rpc_notify (for transport destroy) + call's xlator_mem_cleanup if all xprt are destroyed that internally + call's inode_table_destroy. + */ + if (state->xprt) { + rpc_transport_unref(state->xprt); + state->xprt = NULL; + } + + GF_FREE(state); +} - if (state->fd) { - fd_unref (state->fd); - state->fd = NULL; +static int +server_connection_cleanup_flush_cbk(call_frame_t *frame, void *cookie, + xlator_t *this, int32_t op_ret, + int32_t op_errno, dict_t *xdata) +{ + int32_t ret = -1; + fd_t *fd = NULL; + client_t *client = NULL; + uint64_t fd_cnt = 0; + xlator_t *victim = NULL; + server_conf_t *conf = NULL; + xlator_t *serv_xl = NULL; + rpc_transport_t *xprt = NULL; + rpc_transport_t *xp_next = NULL; + int32_t detach = (long)cookie; + gf_boolean_t xprt_found = _gf_false; + + GF_VALIDATE_OR_GOTO("server", this, out); + GF_VALIDATE_OR_GOTO("server", frame, out); + + fd = frame->local; + client = frame->root->client; + serv_xl = frame->this; + conf = serv_xl->private; + + fd_unref(fd); + frame->local = NULL; + + if (client) + victim = client->bound_xl; + + if (victim) { + fd_cnt = GF_ATOMIC_DEC(client->fd_cnt); + if (!fd_cnt && conf && detach) { + pthread_mutex_lock(&conf->mutex); + { + list_for_each_entry_safe(xprt, xp_next, &conf->xprt_list, list) + { + if (!xprt->xl_private) + continue; + if (xprt->xl_private == client) { + xprt_found = _gf_true; + break; + } + } + } + pthread_mutex_unlock(&conf->mutex); + if (xprt_found) { + rpc_transport_unref(xprt); + } } + } - if (state->params) { - dict_unref (state->params); - state->params = NULL; - } + gf_client_unref(client); + STACK_DESTROY(frame->root); - if (state->iobref) { - iobref_unref (state->iobref); - state->iobref = NULL; - } + ret = 0; +out: + return ret; +} - if (state->iobuf) { - iobuf_unref (state->iobuf); - state->iobuf = NULL; - } +static int +do_fd_cleanup(xlator_t *this, client_t *client, fdentry_t *fdentries, + int fd_count, int32_t detach) +{ + fd_t *fd = NULL; + int i = 0, ret = -1; + call_frame_t *tmp_frame = NULL; + xlator_t *bound_xl = NULL; + char *path = NULL; - if (state->dict) { - dict_unref (state->dict); - state->dict = NULL; - } + GF_VALIDATE_OR_GOTO("server", this, out); + GF_VALIDATE_OR_GOTO("server", fdentries, out); - if (state->volume) - GF_FREE ((void *)state->volume); + bound_xl = client->bound_xl; - if (state->name) - GF_FREE ((void *)state->name); + for (i = 0; i < fd_count; i++) { + fd = fdentries[i].fd; - server_loc_wipe (&state->loc); - server_loc_wipe (&state->loc2); + if (fd != NULL) { + tmp_frame = create_frame(this, this->ctx->pool); + if (tmp_frame == NULL) { + goto out; + } + + tmp_frame->root->type = GF_OP_TYPE_FOP; + GF_ASSERT(fd->inode); + + ret = inode_path(fd->inode, NULL, &path); + + if (ret > 0) { + gf_smsg(this->name, GF_LOG_INFO, 0, PS_MSG_FD_CLEANUP, + "path=%s", path, NULL); + GF_FREE(path); + } else { + gf_smsg(this->name, GF_LOG_INFO, 0, PS_MSG_FD_CLEANUP, + "inode-gfid=%s", uuid_utoa(fd->inode->gfid), NULL); + } + + tmp_frame->local = fd; + tmp_frame->root->pid = 0; + gf_client_ref(client); + tmp_frame->root->client = client; + memset(&tmp_frame->root->lk_owner, 0, sizeof(gf_lkowner_t)); + + STACK_WIND_COOKIE(tmp_frame, server_connection_cleanup_flush_cbk, + (void *)(long)detach, bound_xl, + bound_xl->fops->flush, fd, NULL); + } + } - server_resolve_wipe (&state->resolve); - server_resolve_wipe (&state->resolve2); + GF_FREE(fdentries); + ret = 0; - GF_FREE (state); +out: + return ret; } - int -gf_add_locker (struct _lock_table *table, const char *volume, - loc_t *loc, fd_t *fd, pid_t pid, uint64_t owner) +server_connection_cleanup(xlator_t *this, client_t *client, int32_t flags, + gf_boolean_t *fd_exist) { - int32_t ret = -1; - struct _locker *new = NULL; - uint8_t dir = 0; - - new = GF_CALLOC (1, sizeof (struct _locker), gf_server_mt_locker_t); - if (new == NULL) { - gf_log ("server", GF_LOG_ERROR, - "failed to allocate memory for \'struct _locker\'"); - goto out; + server_ctx_t *serv_ctx = NULL; + fdentry_t *fdentries = NULL; + uint32_t fd_count = 0; + int cd_ret = 0; + int ret = 0; + xlator_t *bound_xl = NULL; + int i = 0; + fd_t *fd = NULL; + uint64_t fd_cnt = 0; + int32_t detach = 0; + + GF_VALIDATE_OR_GOTO("server", this, out); + GF_VALIDATE_OR_GOTO(this->name, client, out); + GF_VALIDATE_OR_GOTO(this->name, flags, out); + + serv_ctx = server_ctx_get(client, client->this); + + if (serv_ctx == NULL) { + gf_smsg(this->name, GF_LOG_INFO, 0, PS_MSG_SERVER_CTX_GET_FAILED, NULL); + goto out; + } + + LOCK(&serv_ctx->fdtable_lock); + { + if (serv_ctx->fdtable && (flags & POSIX_LOCKS)) + fdentries = gf_fd_fdtable_get_all_fds(serv_ctx->fdtable, &fd_count); + } + UNLOCK(&serv_ctx->fdtable_lock); + + if (client->bound_xl == NULL) + goto out; + + if (flags & INTERNAL_LOCKS) { + cd_ret = gf_client_disconnect(client); + } + + if (fdentries != NULL) { + /* Loop to configure fd_count on victim brick */ + bound_xl = client->bound_xl; + if (bound_xl) { + for (i = 0; i < fd_count; i++) { + fd = fdentries[i].fd; + if (!fd) + continue; + fd_cnt++; + } + if (fd_cnt) { + if (fd_exist) + (*fd_exist) = _gf_true; + GF_ATOMIC_ADD(client->fd_cnt, fd_cnt); + } } - INIT_LIST_HEAD (&new->lockers); - new->volume = gf_strdup (volume); + /* If fd_exist is not NULL it means function is invoke + by server_rpc_notify at the time of getting DISCONNECT + notification + */ + if (fd_exist) + detach = 1; - if (fd == NULL) { - loc_copy (&new->loc, loc); - dir = IA_ISDIR (new->loc.inode->ia_type); - } else { - new->fd = fd_ref (fd); - dir = IA_ISDIR (fd->inode->ia_type); - } + gf_msg_debug(this->name, 0, + "Performing cleanup on %d " + "fdentries", + fd_count); + ret = do_fd_cleanup(this, client, fdentries, fd_count, detach); + } else + gf_smsg(this->name, GF_LOG_INFO, 0, PS_MSG_FDENTRY_NULL, NULL); - new->pid = pid; - new->owner = owner; + if (cd_ret || ret) + ret = -1; - LOCK (&table->lock); - { - if (dir) - list_add_tail (&new->lockers, &table->dir_lockers); - else - list_add_tail (&new->lockers, &table->file_lockers); - } - UNLOCK (&table->lock); out: - return ret; + return ret; } - -int -gf_del_locker (struct _lock_table *table, const char *volume, - loc_t *loc, fd_t *fd, uint64_t owner) +static call_frame_t * +server_alloc_frame(rpcsvc_request_t *req) { - struct _locker *locker = NULL; - struct _locker *tmp = NULL; - int32_t ret = 0; - uint8_t dir = 0; - struct list_head *head = NULL; - struct list_head del; - - INIT_LIST_HEAD (&del); - - if (fd) { - dir = IA_ISDIR (fd->inode->ia_type); - } else { - dir = IA_ISDIR (loc->inode->ia_type); - } + call_frame_t *frame = NULL; + server_state_t *state = NULL; + client_t *client = NULL; - LOCK (&table->lock); - { - if (dir) { - head = &table->dir_lockers; - } else { - head = &table->file_lockers; - } + GF_VALIDATE_OR_GOTO("server", req, out); + GF_VALIDATE_OR_GOTO("server", req->trans, out); + GF_VALIDATE_OR_GOTO("server", req->svc, out); + GF_VALIDATE_OR_GOTO("server", req->svc->ctx, out); - list_for_each_entry_safe (locker, tmp, head, lockers) { - if (locker->fd && fd && - (locker->fd == fd) && (locker->owner == owner) - && !strcmp (locker->volume, volume)) { - list_move_tail (&locker->lockers, &del); - } else if (locker->loc.inode && - loc && - (locker->loc.inode == loc->inode) && - (locker->owner == owner) - && !strcmp (locker->volume, volume)) { - list_move_tail (&locker->lockers, &del); - } - } - } - UNLOCK (&table->lock); + client = req->trans->xl_private; + GF_VALIDATE_OR_GOTO("server", client, out); - tmp = NULL; - locker = NULL; + frame = create_frame(client->this, req->svc->ctx->pool); + if (!frame) + goto out; - list_for_each_entry_safe (locker, tmp, &del, lockers) { - list_del_init (&locker->lockers); - if (locker->fd) - fd_unref (locker->fd); - else - loc_wipe (&locker->loc); + frame->root->type = GF_OP_TYPE_FOP; + state = GF_CALLOC(1, sizeof(*state), gf_server_mt_state_t); + if (!state) + goto out; - GF_FREE (locker->volume); - GF_FREE (locker); - } + if (client->bound_xl) + state->itable = client->bound_xl->itable; - return ret; -} + state->xprt = rpc_transport_ref(req->trans); + state->resolve.fd_no = -1; + state->resolve2.fd_no = -1; -static struct _lock_table * -gf_lock_table_new (void) -{ - struct _lock_table *new = NULL; + frame->root->client = client; + frame->root->state = state; /* which socket */ - new = GF_CALLOC (1, sizeof (struct _lock_table), gf_server_mt_lock_table_t); - if (new == NULL) { - gf_log ("server-protocol", GF_LOG_CRITICAL, - "failed to allocate memory for new lock table"); - goto out; - } - INIT_LIST_HEAD (&new->dir_lockers); - INIT_LIST_HEAD (&new->file_lockers); - LOCK_INIT (&new->lock); + frame->this = client->this; out: - return new; + return frame; } -static int -server_nop_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno) +call_frame_t * +get_frame_from_request(rpcsvc_request_t *req) { - server_state_t *state = NULL; - - state = CALL_STATE(frame); - - if (state) - free_state (state); - STACK_DESTROY (frame->root); - return 0; + call_frame_t *frame = NULL; + client_t *client = NULL; + client_t *tmp_client = NULL; + xlator_t *this = NULL; + server_conf_t *priv = NULL; + clienttable_t *clienttable = NULL; + unsigned int i = 0; + rpc_transport_t *trans = NULL; + server_state_t *state = NULL; + + GF_VALIDATE_OR_GOTO("server", req, out); + + frame = server_alloc_frame(req); + if (!frame) + goto out; + + frame->root->op = req->procnum; + + client = req->trans->xl_private; + this = req->trans->xl; + priv = this->private; + clienttable = this->ctx->clienttable; + + for (i = 0; i < clienttable->max_clients; i++) { + tmp_client = clienttable->cliententries[i].client; + if (client == tmp_client) { + /* for non trusted clients username and password + would not have been set. So for non trusted clients + (i.e clients not from the same machine as the brick, + and clients from outside the storage pool) + do the root-squashing and all-squashing. + TODO: If any client within the storage pool (i.e + mounting within a machine from the pool but using + other machine's ip/hostname from the same pool) + is present treat it as a trusted client + */ + if (!client->auth.username && req->pid != NFS_PID) { + RPC_AUTH_ROOT_SQUASH(req); + RPC_AUTH_ALL_SQUASH(req); + } + + /* Problem: If we just check whether the client is + trusted client and do not do root squashing and + all squashing for them, then for smb clients and + UFO clients root squashing and all squashing will + never happen as they use the fuse mounts done within + the trusted pool (i.e they are trusted clients). + Solution: To fix it, do root squashing and all squashing + for trusted clients also. If one wants to have a client + within the storage pool for which root-squashing does + not happen, then the client has to be mounted with + --no-root-squash option. But for defrag client and + gsyncd client do not do root-squashing and all-squashing. + */ + if (client->auth.username && + req->pid != GF_CLIENT_PID_NO_ROOT_SQUASH && + req->pid != GF_CLIENT_PID_GSYNCD && + req->pid != GF_CLIENT_PID_DEFRAG && + req->pid != GF_CLIENT_PID_SELF_HEALD && + req->pid != GF_CLIENT_PID_QUOTA_MOUNT) { + RPC_AUTH_ROOT_SQUASH(req); + RPC_AUTH_ALL_SQUASH(req); + } + + /* For nfs clients the server processes will be running + within the trusted storage pool machines. So if we + do not do root-squashing and all-squashing for nfs + servers, thinking that its a trusted client, then + root-squashing and all-squashing won't work for nfs + clients. + */ + if (req->pid == NFS_PID) { + RPC_AUTH_ROOT_SQUASH(req); + RPC_AUTH_ALL_SQUASH(req); + } + } + } + + /* Add a ref for this fop */ + if (client) + gf_client_ref(client); + + frame->root->uid = req->uid; + frame->root->gid = req->gid; + frame->root->pid = req->pid; + frame->root->client = client; + frame->root->lk_owner = req->lk_owner; + + if (priv->server_manage_gids) + server_resolve_groups(frame, req); + else + server_decode_groups(frame, req); + trans = req->trans; + if (trans) { + memcpy(&frame->root->identifier, trans->peerinfo.identifier, + sizeof(trans->peerinfo.identifier)); + } + + /* more fields, for the clients which are 3.x series this will be 0 */ + frame->root->flags = req->flags; + frame->root->ctime = req->ctime; + + frame->local = req; + + state = CALL_STATE(frame); + state->client = client; +out: + return frame; } int -do_lock_table_cleanup (xlator_t *this, server_connection_t *conn, - call_frame_t *frame, struct _lock_table *ltable) +server_build_config(xlator_t *this, server_conf_t *conf) { - struct list_head file_lockers, dir_lockers; - call_frame_t *tmp_frame = NULL; - struct flock flock = {0, }; - xlator_t *bound_xl = NULL; - struct _locker *locker = NULL, *tmp = NULL; - int ret = -1; - - bound_xl = conn->bound_xl; - INIT_LIST_HEAD (&file_lockers); - INIT_LIST_HEAD (&dir_lockers); - - LOCK (<able->lock); - { - list_splice_init (<able->file_lockers, - &file_lockers); - - list_splice_init (<able->dir_lockers, &dir_lockers); + data_t *data = NULL; + int ret = -1; + struct stat buf = { + 0, + }; + + GF_VALIDATE_OR_GOTO("server", this, out); + GF_VALIDATE_OR_GOTO("server", conf, out); + + ret = dict_get_int32(this->options, "inode-lru-limit", + &conf->inode_lru_limit); + if (ret < 0) { + conf->inode_lru_limit = 16384; + } + + conf->verify_volfile = 1; + data = dict_get(this->options, "verify-volfile-checksum"); + if (data) { + ret = gf_string2boolean(data->data, &conf->verify_volfile); + if (ret != 0) { + gf_smsg(this->name, GF_LOG_WARNING, EINVAL, PS_MSG_WRONG_VALUE, + NULL); } - UNLOCK (<able->lock); - - GF_FREE (ltable); - - flock.l_type = F_UNLCK; - flock.l_start = 0; - flock.l_len = 0; - list_for_each_entry_safe (locker, - tmp, &file_lockers, lockers) { - tmp_frame = copy_frame (frame); - if (tmp_frame == NULL) { - gf_log (this->name, GF_LOG_ERROR, - "out of memory"); - goto out; - } - /* - lock owner = 0 is a special case that tells posix-locks - to release all locks from this transport - */ - tmp_frame->root->pid = 0; - tmp_frame->root->lk_owner = 0; - tmp_frame->root->trans = conn; - - if (locker->fd) { - STACK_WIND (tmp_frame, server_nop_cbk, bound_xl, - bound_xl->fops->finodelk, - locker->volume, - locker->fd, F_SETLK, &flock); - fd_unref (locker->fd); - } else { - STACK_WIND (tmp_frame, server_nop_cbk, bound_xl, - bound_xl->fops->inodelk, - locker->volume, - &(locker->loc), F_SETLK, &flock); - loc_wipe (&locker->loc); - } - - GF_FREE (locker->volume); - - list_del_init (&locker->lockers); - GF_FREE (locker); + } + + data = dict_get(this->options, "trace"); + if (data) { + ret = gf_string2boolean(data->data, &conf->trace); + if (ret != 0) { + gf_smsg(this->name, GF_LOG_WARNING, EINVAL, PS_MSG_INVALID_ENTRY, + NULL); } - - tmp = NULL; - locker = NULL; - list_for_each_entry_safe (locker, tmp, &dir_lockers, lockers) { - tmp_frame = copy_frame (frame); - - tmp_frame->root->lk_owner = 0; - tmp_frame->root->pid = 0; - tmp_frame->root->trans = conn; - - if (locker->fd) { - STACK_WIND (tmp_frame, server_nop_cbk, bound_xl, - bound_xl->fops->fentrylk, - locker->volume, - locker->fd, NULL, - ENTRYLK_UNLOCK, ENTRYLK_WRLCK); - fd_unref (locker->fd); - } else { - STACK_WIND (tmp_frame, server_nop_cbk, bound_xl, - bound_xl->fops->entrylk, - locker->volume, - &(locker->loc), NULL, - ENTRYLK_UNLOCK, ENTRYLK_WRLCK); - loc_wipe (&locker->loc); - } - - GF_FREE (locker->volume); - - list_del_init (&locker->lockers); - GF_FREE (locker); + } + + /* TODO: build_rpc_config (); */ + ret = dict_get_int32(this->options, "limits.transaction-size", + &conf->rpc_conf.max_block_size); + if (ret < 0) { + gf_msg_trace(this->name, 0, + "defaulting limits.transaction-" + "size to %d", + DEFAULT_BLOCK_SIZE); + conf->rpc_conf.max_block_size = DEFAULT_BLOCK_SIZE; + } + + data = dict_get(this->options, "config-directory"); + if (data) { + /* Check whether the specified directory exists, + or directory specified is non standard */ + ret = sys_stat(data->data, &buf); + if ((ret != 0) || !S_ISDIR(buf.st_mode)) { + gf_smsg(this->name, GF_LOG_ERROR, 0, PS_MSG_DIR_NOT_FOUND, + "data=%s", data->data, NULL); + ret = -1; + goto out; + } + /* Make sure that conf-dir doesn't contain ".." in path */ + if ((gf_strstr(data->data, "/", "..")) == -1) { + ret = -1; + gf_smsg(this->name, GF_LOG_ERROR, 0, PS_MSG_CONF_DIR_INVALID, + "data=%s", data->data, NULL); + goto out; } - ret = 0; + conf->conf_dir = gf_strdup(data->data); + } + ret = 0; out: - return ret; + return ret; } - -static int -server_connection_cleanup_flush_cbk (call_frame_t *frame, void *cookie, - xlator_t *this, int32_t op_ret, - int32_t op_errno) +void +print_caller(char *str, int size, call_frame_t *frame) { - fd_t *fd = NULL; + server_state_t *state = NULL; - fd = frame->local; + GF_VALIDATE_OR_GOTO("server", str, out); + GF_VALIDATE_OR_GOTO("server", frame, out); - fd_unref (fd); - frame->local = NULL; + state = CALL_STATE(frame); - STACK_DESTROY (frame->root); - return 0; -} + snprintf(str, size, " Callid=%" PRId64 ", Client=%s", frame->root->unique, + state->xprt->peerinfo.identifier); +out: + return; +} -int -do_fd_cleanup (xlator_t *this, server_connection_t *conn, call_frame_t *frame, - fdentry_t *fdentries, int fd_count) +void +server_print_resolve(char *str, int size, server_resolve_t *resolve) { - fd_t *fd = NULL; - int i = 0, ret = -1; - call_frame_t *tmp_frame = NULL; - xlator_t *bound_xl = NULL; + int filled = 0; - bound_xl = conn->bound_xl; - for (i = 0;i < fd_count; i++) { - fd = fdentries[i].fd; - - if (fd != NULL) { - tmp_frame = copy_frame (frame); - if (tmp_frame == NULL) { - gf_log (this->name, GF_LOG_ERROR, - "out of memory"); - goto out; - } - tmp_frame->local = fd; - - tmp_frame->root->pid = 0; - tmp_frame->root->trans = conn; - tmp_frame->root->lk_owner = 0; - STACK_WIND (tmp_frame, - server_connection_cleanup_flush_cbk, - bound_xl, bound_xl->fops->flush, fd); - } - } - - GF_FREE (fdentries); - ret = 0; + GF_VALIDATE_OR_GOTO("server", str, out); + if (!resolve) { + snprintf(str, size, "<nul>"); + return; + } + + filled += snprintf(str + filled, size - filled, " Resolve={"); + if (resolve->fd_no != -1) + filled += snprintf(str + filled, size - filled, "fd=%" PRId64 ",", + (uint64_t)resolve->fd_no); + if (resolve->bname) + filled += snprintf(str + filled, size - filled, "bname=%s,", + resolve->bname); + if (resolve->path) + filled += snprintf(str + filled, size - filled, "path=%s", + resolve->path); + + snprintf(str + filled, size - filled, "}"); out: - return ret; + return; } -int -do_connection_cleanup (xlator_t *this, server_connection_t *conn, - struct _lock_table *ltable, fdentry_t *fdentries, int fd_count) +void +server_print_loc(char *str, int size, loc_t *loc) { - int ret = 0; - int saved_ret = 0; - call_frame_t *frame = NULL; - server_state_t *state = NULL; - - frame = create_frame (this, this->ctx->pool); - if (frame == NULL) { - gf_log (this->name, GF_LOG_ERROR, "out of memory"); - goto out; - } + int filled = 0; - saved_ret = do_lock_table_cleanup (this, conn, frame, ltable); + GF_VALIDATE_OR_GOTO("server", str, out); - if (fdentries != NULL) { - ret = do_fd_cleanup (this, conn, frame, fdentries, fd_count); - } - - state = CALL_STATE (frame); - if (state) - GF_FREE (state); + if (!loc) { + snprintf(str, size, "<nul>"); + return; + } - STACK_DESTROY (frame->root); + filled += snprintf(str + filled, size - filled, " Loc={"); - if (saved_ret || ret) { - ret = -1; - } + if (loc->path) + filled += snprintf(str + filled, size - filled, "path=%s,", loc->path); + if (loc->inode) + filled += snprintf(str + filled, size - filled, "inode=%p,", + loc->inode); + if (loc->parent) + filled += snprintf(str + filled, size - filled, "parent=%p", + loc->parent); + snprintf(str + filled, size - filled, "}"); out: - return ret; + return; } - -int -server_connection_cleanup (xlator_t *this, server_connection_t *conn) +void +server_print_params(char *str, int size, server_state_t *state) { - char do_cleanup = 0; - struct _lock_table *ltable = NULL; - fdentry_t *fdentries = NULL; - uint32_t fd_count = 0; - int ret = 0; - - if (conn == NULL) { - goto out; - } - - pthread_mutex_lock (&conn->lock); - { - conn->active_transports--; - if (conn->active_transports == 0) { - if (conn->ltable) { - ltable = conn->ltable; - conn->ltable = gf_lock_table_new (); - } - - if (conn->fdtable) { - fdentries = gf_fd_fdtable_get_all_fds (conn->fdtable, - &fd_count); - } - do_cleanup = 1; - } - } - pthread_mutex_unlock (&conn->lock); - - if (do_cleanup && conn->bound_xl) - ret = do_connection_cleanup (this, conn, ltable, fdentries, fd_count); - + int filled = 0; + + GF_VALIDATE_OR_GOTO("server", str, out); + + filled += snprintf(str + filled, size - filled, " Params={"); + + if (state->fd) + filled += snprintf(str + filled, size - filled, "fd=%p,", state->fd); + if (state->valid) + filled += snprintf(str + filled, size - filled, "valid=%d,", + state->valid); + if (state->flags) + filled += snprintf(str + filled, size - filled, "flags=%d,", + state->flags); + if (state->wbflags) + filled += snprintf(str + filled, size - filled, "wbflags=%d,", + state->wbflags); + if (state->size) + filled += snprintf(str + filled, size - filled, "size=%zu,", + state->size); + if (state->offset) + filled += snprintf(str + filled, size - filled, "offset=%" PRId64 ",", + state->offset); + if (state->cmd) + filled += snprintf(str + filled, size - filled, "cmd=%d,", state->cmd); + if (state->type) + filled += snprintf(str + filled, size - filled, "type=%d,", + state->type); + if (state->name) + filled += snprintf(str + filled, size - filled, "name=%s,", + state->name); + if (state->mask) + filled += snprintf(str + filled, size - filled, "mask=%d,", + state->mask); + if (state->volume) + filled += snprintf(str + filled, size - filled, "volume=%s,", + state->volume); + +/* FIXME + snprintf (str + filled, size - filled, + "bound_xl=%s}", state->client->bound_xl->name); +*/ out: - return ret; + return; } - int -server_connection_destroy (xlator_t *this, server_connection_t *conn) +server_resolve_is_empty(server_resolve_t *resolve) { - call_frame_t *frame = NULL, *tmp_frame = NULL; - xlator_t *bound_xl = NULL; - int32_t ret = -1; - server_state_t *state = NULL; - struct list_head file_lockers; - struct list_head dir_lockers; - struct _lock_table *ltable = NULL; - struct _locker *locker = NULL, *tmp = NULL; - struct flock flock = {0,}; - fd_t *fd = NULL; - int32_t i = 0; - fdentry_t *fdentries = NULL; - uint32_t fd_count = 0; - - if (conn == NULL) { - ret = 0; - goto out; - } + if (resolve->fd_no != -1) + return 0; - bound_xl = (xlator_t *) (conn->bound_xl); + if (resolve->path != 0) + return 0; - if (bound_xl) { - /* trans will have ref_count = 1 after this call, but its - ok since this function is called in - GF_EVENT_TRANSPORT_CLEANUP */ - frame = create_frame (this, this->ctx->pool); + if (resolve->bname != 0) + return 0; - pthread_mutex_lock (&(conn->lock)); - { - if (conn->ltable) { - ltable = conn->ltable; - conn->ltable = NULL; - } - } - pthread_mutex_unlock (&conn->lock); + return 1; +} - INIT_LIST_HEAD (&file_lockers); - INIT_LIST_HEAD (&dir_lockers); +void +server_print_reply(call_frame_t *frame, int op_ret, int op_errno) +{ + server_conf_t *conf = NULL; + server_state_t *state = NULL; + xlator_t *this = NULL; + char caller[512]; + char fdstr[32]; + char *op = "UNKNOWN"; - if (ltable) { - LOCK (<able->lock); - { - list_splice_init (<able->file_lockers, - &file_lockers); + GF_VALIDATE_OR_GOTO("server", frame, out); - list_splice_init (<able->dir_lockers, &dir_lockers); - } - UNLOCK (<able->lock); - GF_FREE (ltable); - } + this = frame->this; + conf = this->private; - flock.l_type = F_UNLCK; - flock.l_start = 0; - flock.l_len = 0; - list_for_each_entry_safe (locker, - tmp, &file_lockers, lockers) { - tmp_frame = copy_frame (frame); - /* - lock_owner = 0 is a special case that tells posix-locks - to release all locks from this transport - */ - tmp_frame->root->lk_owner = 0; - tmp_frame->root->trans = conn; - - if (locker->fd) { - STACK_WIND (tmp_frame, server_nop_cbk, bound_xl, - bound_xl->fops->finodelk, - locker->volume, - locker->fd, F_SETLK, &flock); - fd_unref (locker->fd); - } else { - STACK_WIND (tmp_frame, server_nop_cbk, bound_xl, - bound_xl->fops->inodelk, - locker->volume, - &(locker->loc), F_SETLK, &flock); - loc_wipe (&locker->loc); - } - - GF_FREE (locker->volume); - - list_del_init (&locker->lockers); - GF_FREE (locker); - } + GF_VALIDATE_OR_GOTO("server", conf, out); + GF_VALIDATE_OR_GOTO("server", conf->trace, out); - tmp = NULL; - locker = NULL; - list_for_each_entry_safe (locker, tmp, &dir_lockers, lockers) { - tmp_frame = copy_frame (frame); - - tmp_frame->root->lk_owner = 0; - tmp_frame->root->trans = conn; - - if (locker->fd) { - STACK_WIND (tmp_frame, server_nop_cbk, bound_xl, - bound_xl->fops->fentrylk, - locker->volume, - locker->fd, NULL, - ENTRYLK_UNLOCK, ENTRYLK_WRLCK); - fd_unref (locker->fd); - } else { - STACK_WIND (tmp_frame, server_nop_cbk, bound_xl, - bound_xl->fops->entrylk, - locker->volume, - &(locker->loc), NULL, - ENTRYLK_UNLOCK, ENTRYLK_WRLCK); - loc_wipe (&locker->loc); - } - - GF_FREE (locker->volume); - - list_del_init (&locker->lockers); - GF_FREE (locker); - } - - pthread_mutex_lock (&(conn->lock)); - { - if (conn->fdtable) { - fdentries = gf_fd_fdtable_get_all_fds (conn->fdtable, - &fd_count); - gf_fd_fdtable_destroy (conn->fdtable); - conn->fdtable = NULL; - } - } - pthread_mutex_unlock (&conn->lock); - - if (fdentries != NULL) { - for (i = 0; i < fd_count; i++) { - fd = fdentries[i].fd; - if (fd != NULL) { - tmp_frame = copy_frame (frame); - tmp_frame->local = fd; - - STACK_WIND (tmp_frame, - server_connection_cleanup_flush_cbk, - bound_xl, - bound_xl->fops->flush, - fd); - } - } - GF_FREE (fdentries); - } - } + state = CALL_STATE(frame); - if (frame) { - state = CALL_STATE (frame); - if (state) - GF_FREE (state); - STACK_DESTROY (frame->root); - } + print_caller(caller, 256, frame); - gf_log (this->name, GF_LOG_INFO, "destroyed connection of %s", - conn->id); + switch (frame->root->type) { + case GF_OP_TYPE_FOP: + op = (char *)gf_fop_list[frame->root->op]; + break; + default: + op = ""; + } - GF_FREE (conn->id); - GF_FREE (conn); + fdstr[0] = '\0'; + if (state->fd) + snprintf(fdstr, 32, " fd=%p", state->fd); + gf_smsg(this->name, GF_LOG_INFO, op_errno, PS_MSG_SERVER_MSG, "op=%s", op, + "caller=%s", caller, "op_ret=%d", op_ret, "op_errno=%d", op_errno, + "fdstr=%s", fdstr, NULL); out: - return ret; + return; } - -server_connection_t * -server_connection_get (xlator_t *this, const char *id) +void +server_print_request(call_frame_t *frame) { - server_connection_t *conn = NULL; - server_connection_t *trav = NULL; - server_conf_t *conf = NULL; - - conf = this->private; + server_conf_t *conf = NULL; + xlator_t *this = NULL; + server_state_t *state = NULL; + char *op = "UNKNOWN"; + char resolve_vars[256]; + char resolve2_vars[256]; + char loc_vars[256]; + char loc2_vars[256]; + char other_vars[512]; + char caller[512]; - pthread_mutex_lock (&conf->mutex); - { - list_for_each_entry (trav, &conf->conns, list) { - if (!strcmp (id, trav->id)) { - conn = trav; - break; - } - } + GF_VALIDATE_OR_GOTO("server", frame, out); - if (!conn) { - conn = (void *) GF_CALLOC (1, sizeof (*conn), - gf_server_mt_conn_t); - if (!conn) - goto unlock; + this = frame->this; + conf = this->private; - conn->id = gf_strdup (id); - conn->fdtable = gf_fd_fdtable_alloc (); - conn->ltable = gf_lock_table_new (); - conn->this = this; - pthread_mutex_init (&conn->lock, NULL); + GF_VALIDATE_OR_GOTO("server", conf, out); - list_add (&conn->list, &conf->conns); - } + if (!conf->trace) + goto out; - conn->ref++; - conn->active_transports++; - } -unlock: - pthread_mutex_unlock (&conf->mutex); + state = CALL_STATE(frame); - return conn; -} + memset(resolve_vars, '\0', 256); + memset(resolve2_vars, '\0', 256); + memset(loc_vars, '\0', 256); + memset(loc2_vars, '\0', 256); + memset(other_vars, '\0', 256); + print_caller(caller, 256, frame); -void -server_connection_put (xlator_t *this, server_connection_t *conn) -{ - server_conf_t *conf = NULL; - server_connection_t *todel = NULL; + if (!server_resolve_is_empty(&state->resolve)) { + server_print_resolve(resolve_vars, 256, &state->resolve); + server_print_loc(loc_vars, 256, &state->loc); + } - if (conn == NULL) { - goto out; - } + if (!server_resolve_is_empty(&state->resolve2)) { + server_print_resolve(resolve2_vars, 256, &state->resolve2); + server_print_loc(loc2_vars, 256, &state->loc2); + } - conf = this->private; - - pthread_mutex_lock (&conf->mutex); - { - conn->ref--; - - if (!conn->ref) { - list_del_init (&conn->list); - todel = conn; - } - } - pthread_mutex_unlock (&conf->mutex); - - if (todel) { - server_connection_destroy (this, todel); - } + server_print_params(other_vars, 512, state); + switch (frame->root->type) { + case GF_OP_TYPE_FOP: + op = (char *)gf_fop_list[frame->root->op]; + break; + default: + op = ""; + break; + } + + gf_smsg(this->name, GF_LOG_INFO, 0, PS_MSG_SERVER_MSG, "op=%s", op, + "caller=%s", caller, "resolve_vars=%s", resolve_vars, "loc_vars=%s", + loc_vars, "resolve2_vars=%s", resolve2_vars, "loc2_vars=%s", + loc2_vars, "other_vars=%s", other_vars, NULL); out: - return; + return; } -static call_frame_t * -server_alloc_frame (rpcsvc_request_t *req) +int +serialize_rsp_direntp(gf_dirent_t *entries, gfs3_readdirp_rsp *rsp) { - call_frame_t *frame = NULL; - server_state_t *state = NULL; - server_connection_t *conn = NULL; - - GF_VALIDATE_OR_GOTO("server", req, out); - GF_VALIDATE_OR_GOTO("server", req->trans, out); - GF_VALIDATE_OR_GOTO("server", req->svc, out); - GF_VALIDATE_OR_GOTO("server", req->svc->ctx, out); - - conn = (server_connection_t *)req->trans->xl_private; - if (!conn) + gf_dirent_t *entry = NULL; + gfs3_dirplist *trav = NULL; + gfs3_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; + + gf_stat_from_iatt(&trav->stat, &entry->d_stat); + + /* if 'dict' is present, pack it */ + if (entry->dict) { + ret = dict_allocate_and_serialize(entry->dict, + (char **)&trav->dict.dict_val, + &trav->dict.dict_len); + if (ret != 0) { + gf_smsg(THIS->name, GF_LOG_ERROR, 0, PS_MSG_DICT_SERIALIZE_FAIL, + NULL); + errno = -ret; + trav->dict.dict_len = 0; goto out; + } + } - frame = create_frame (conn->this, req->svc->ctx->pool); - GF_VALIDATE_OR_GOTO("server", frame, out); + if (prev) + prev->nextentry = trav; + else + rsp->reply = trav; - state = GF_CALLOC (1, sizeof (*state), gf_server_mt_state_t); - GF_VALIDATE_OR_GOTO("server", state, out); + prev = trav; + trav = NULL; + } - if (conn->bound_xl) - state->itable = conn->bound_xl->itable; + ret = 0; +out: + GF_FREE(trav); - state->xprt = req->trans; - state->conn = conn; + return ret; +} - state->resolve.fd_no = -1; - state->resolve2.fd_no = -1; +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; - frame->root->state = state; /* which socket */ - frame->root->unique = 0; /* which call */ + prev = trav; + trav = NULL; + } - frame->this = conn->this; + ret = 0; out: - return frame; -} - + GF_FREE(trav); + return ret; +} -call_frame_t * -get_frame_from_request (rpcsvc_request_t *req) +int +serialize_rsp_dirent(gf_dirent_t *entries, gfs3_readdir_rsp *rsp) { - call_frame_t *frame = NULL; + gf_dirent_t *entry = NULL; + gfs3_dirlist *trav = NULL; + 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; - frame = server_alloc_frame (req); - if (!frame) - goto out; - - frame->root->op = req->procnum; - frame->root->type = req->type; + prev = trav; + } - frame->root->unique = req->xid; + ret = 0; +out: + return ret; +} - frame->root->uid = req->uid; - frame->root->gid = req->gid; - frame->root->pid = req->pid; - frame->root->trans = req->trans; - frame->root->lk_owner = req->lk_owner; +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); + 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; - server_decode_groups (frame, req); + prev = trav; + } - frame->local = req; + ret = 0; out: - return frame; + return ret; } - int -server_build_config (xlator_t *this, server_conf_t *conf) +readdir_rsp_cleanup(gfs3_readdir_rsp *rsp) { - data_t *data = NULL; - int ret = -1; - struct stat buf = {0,}; - - ret = dict_get_int32 (this->options, "inode-lru-limit", - &conf->inode_lru_limit); - if (ret < 0) { - conf->inode_lru_limit = 1024; - } + gfs3_dirlist *prev = NULL; + gfs3_dirlist *trav = NULL; + + trav = rsp->reply; + prev = trav; + while (trav) { + trav = trav->nextentry; + GF_FREE(prev); + prev = trav; + } - conf->verify_volfile = 1; - data = dict_get (this->options, "verify-volfile-checksum"); - if (data) { - ret = gf_string2boolean(data->data, &conf->verify_volfile); - if (ret != 0) { - gf_log (this->name, GF_LOG_WARNING, - "wrong value for 'verify-volfile-checksum', " - "Neglecting option"); - } - } + return 0; +} - data = dict_get (this->options, "trace"); - if (data) { - ret = gf_string2boolean (data->data, &conf->trace); - if (ret != 0) { - gf_log (this->name, GF_LOG_WARNING, - "'trace' takes on only boolean values. " - "Neglecting option"); - } - } - - /* TODO: build_rpc_config (); */ - ret = dict_get_int32 (this->options, "limits.transaction-size", - &conf->rpc_conf.max_block_size); - if (ret < 0) { - gf_log (this->name, GF_LOG_TRACE, - "defaulting limits.transaction-size to %d", - DEFAULT_BLOCK_SIZE); - conf->rpc_conf.max_block_size = DEFAULT_BLOCK_SIZE; - } +int +readdirp_rsp_cleanup(gfs3_readdirp_rsp *rsp) +{ + gfs3_dirplist *prev = NULL; + gfs3_dirplist *trav = NULL; + + trav = rsp->reply; + prev = trav; + while (trav) { + trav = trav->nextentry; + GF_FREE(prev->dict.dict_val); + GF_FREE(prev); + prev = trav; + } - data = dict_get (this->options, "config-directory"); - if (data) { - /* Check whether the specified directory exists, - or directory specified is non standard */ - ret = stat (data->data, &buf); - if ((ret != 0) || !S_ISDIR (buf.st_mode)) { - gf_log (this->name, GF_LOG_ERROR, - "Directory '%s' doesn't exist, exiting.", - data->data); - ret = -1; - goto out; - } - /* Make sure that conf-dir doesn't contain ".." in path */ - if ((gf_strstr (data->data, "/", "..")) == -1) { - ret = -1; - gf_log (this->name, GF_LOG_ERROR, - "%s: invalid conf_dir", data->data); - goto out; - } + return 0; +} - conf->conf_dir = gf_strdup (data->data); - } - ret = 0; -out: - return ret; +int +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; } -server_connection_t * -get_server_conn_state (xlator_t *this, rpc_transport_t *xprt) +int +readdirp_rsp_cleanup_v2(gfx_readdirp_rsp *rsp) { - return (server_connection_t *)xprt->xl_private; + 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; } -server_connection_t * -create_server_conn_state (xlator_t *this, rpc_transport_t *xprt) +static int +common_rsp_locklist(lock_migration_info_t *locklist, gfs3_locklist **reply) { - server_connection_t *conn = NULL; - int ret = -1; + lock_migration_info_t *tmp = NULL; + gfs3_locklist *trav = NULL; + gfs3_locklist *prev = NULL; + int ret = -1; + + GF_VALIDATE_OR_GOTO("server", locklist, out); + + list_for_each_entry(tmp, &locklist->list, list) + { + trav = GF_CALLOC(1, sizeof(*trav), gf_server_mt_lock_mig_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; - conn = GF_CALLOC (1, sizeof (*conn), gf_server_mt_conn_t); - if (!conn) - goto out; + default: + gf_smsg(THIS->name, GF_LOG_ERROR, 0, PS_MSG_LOCK_ERROR, + "lock_type=%" PRId32, tmp->flock.l_type, NULL); + break; + } - pthread_mutex_init (&conn->lock, NULL); + gf_proto_flock_from_flock(&trav->flock, &tmp->flock); - conn->fdtable = gf_fd_fdtable_alloc (); - if (!conn->fdtable) - goto out; + trav->lk_flags = tmp->lk_flags; - conn->ltable = gf_lock_table_new (); - if (!conn->ltable) - goto out; + trav->client_uid = tmp->client_uid; - conn->this = this; + if (prev) + prev->nextentry = trav; + else + *reply = trav; - xprt->xl_private = conn; + prev = trav; + trav = NULL; + } - ret = 0; + ret = 0; out: - if (ret) - destroy_server_conn_state (conn); - - return conn; + GF_FREE(trav); + return ret; } -void -destroy_server_conn_state (server_connection_t *conn) +int +serialize_rsp_locklist(lock_migration_info_t *locklist, + gfs3_getactivelk_rsp *rsp) { - if (!conn) { - return; - } - - if (conn->ltable) { - /* TODO */ - //FREE (conn->ltable); - ; - } - - if (conn->fdtable) - gf_fd_fdtable_destroy (conn->fdtable); - - pthread_mutex_destroy (&conn->lock); + int ret = 0; - GF_FREE (conn); - - return; + 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; +} -void -print_caller (char *str, int size, call_frame_t *frame) +int +getactivelkinfo_rsp_cleanup(gfs3_getactivelk_rsp *rsp) { - server_state_t *state = NULL; + gfs3_locklist *prev = NULL; + gfs3_locklist *trav = NULL; - state = CALL_STATE (frame); + trav = rsp->reply; + prev = trav; - snprintf (str, size, - " Callid=%"PRId64", Client=%s", - frame->root->unique, - state->xprt->peerinfo.identifier); + while (trav) { + trav = trav->nextentry; + GF_FREE(prev); + prev = trav; + } - return; + return 0; } - - -void -server_print_resolve (char *str, int size, server_resolve_t *resolve) +int +getactivelkinfo_rsp_cleanup_v2(gfx_getactivelk_rsp *rsp) { - int filled = 0; + gfs3_locklist *prev = NULL; + gfs3_locklist *trav = NULL; - if (!resolve) { - snprintf (str, size, "<nul>"); - return; - } + trav = rsp->reply; + prev = trav; - filled += snprintf (str + filled, size - filled, - " Resolve={"); - if (resolve->fd_no != -1) - filled += snprintf (str + filled, size - filled, - "fd=%"PRId64",", (uint64_t) resolve->fd_no); - if (resolve->ino) - filled += snprintf (str + filled, size - filled, - "ino=%"PRIu64",", (uint64_t) resolve->ino); - if (resolve->par) - filled += snprintf (str + filled, size - filled, - "par=%"PRIu64",", (uint64_t) resolve->par); - if (resolve->gen) - filled += snprintf (str + filled, size - filled, - "gen=%"PRIu64",", (uint64_t) resolve->gen); - if (resolve->bname) - filled += snprintf (str + filled, size - filled, - "bname=%s,", resolve->bname); - if (resolve->path) - filled += snprintf (str + filled, size - filled, - "path=%s", resolve->path); - - snprintf (str + filled, size - filled, "}"); -} + while (trav) { + trav = trav->nextentry; + GF_FREE(prev); + prev = trav; + } + return 0; +} -void -server_print_loc (char *str, int size, loc_t *loc) +int +gf_server_check_getxattr_cmd(call_frame_t *frame, const char *key) { - int filled = 0; + server_conf_t *conf = NULL; + rpc_transport_t *xprt = NULL; - if (!loc) { - snprintf (str, size, "<nul>"); - return; - } + conf = frame->this->private; + if (!conf) + return 0; - filled += snprintf (str + filled, size - filled, - " Loc={"); + if (fnmatch("*list*mount*point*", key, 0) == 0) { + /* list all the client protocol connecting to this process */ + pthread_mutex_lock(&conf->mutex); + { + list_for_each_entry(xprt, &conf->xprt_list, list) + { + gf_smsg("mount-point-list", GF_LOG_INFO, 0, + PS_MSG_MOUNT_PT_FAIL, "identifier=%s", + xprt->peerinfo.identifier, NULL); + } + } + pthread_mutex_unlock(&conf->mutex); + } - if (loc->path) - filled += snprintf (str + filled, size - filled, - "path=%s,", loc->path); - if (loc->inode) - filled += snprintf (str + filled, size - filled, - "inode=%p,", loc->inode); - if (loc->parent) - filled += snprintf (str + filled, size - filled, - "parent=%p", loc->parent); + /* Add more options/keys here */ - snprintf (str + filled, size - filled, "}"); + return 0; } - -void -server_print_params (char *str, int size, server_state_t *state) +int +gf_server_check_setxattr_cmd(call_frame_t *frame, dict_t *dict) { - int filled = 0; - - filled += snprintf (str + filled, size - filled, - " Params={"); - - if (state->fd) - filled += snprintf (str + filled, size - filled, - "fd=%p,", state->fd); - if (state->valid) - filled += snprintf (str + filled, size - filled, - "valid=%d,", state->valid); - if (state->flags) - filled += snprintf (str + filled, size - filled, - "flags=%d,", state->flags); - if (state->wbflags) - filled += snprintf (str + filled, size - filled, - "wbflags=%d,", state->wbflags); - if (state->size) - filled += snprintf (str + filled, size - filled, - "size=%zu,", state->size); - if (state->offset) - filled += snprintf (str + filled, size - filled, - "offset=%"PRId64",", state->offset); - if (state->cmd) - filled += snprintf (str + filled, size - filled, - "cmd=%d,", state->cmd); - if (state->type) - filled += snprintf (str + filled, size - filled, - "type=%d,", state->type); - if (state->name) - filled += snprintf (str + filled, size - filled, - "name=%s,", state->name); - if (state->mask) - filled += snprintf (str + filled, size - filled, - "mask=%d,", state->mask); - if (state->volume) - filled += snprintf (str + filled, size - filled, - "volume=%s,", state->volume); + server_conf_t *conf = NULL; + rpc_transport_t *xprt = NULL; + uint64_t total_read = 0; + uint64_t total_write = 0; - snprintf (str + filled, size - filled, - "bound_xl=%s}", state->conn->bound_xl->name); + conf = frame->this->private; + if (!conf || !dict) + return 0; + + if (dict_foreach_fnmatch(dict, "*io*stat*dump", dict_null_foreach_fn, + NULL) > 0) { + list_for_each_entry(xprt, &conf->xprt_list, list) + { + total_read += xprt->total_bytes_read; + total_write += xprt->total_bytes_write; + } + gf_smsg("stats", GF_LOG_INFO, 0, PS_MSG_RW_STAT, "total-read=%" PRIu64, + total_read, "total-write=%" PRIu64, total_write, NULL); + } + + return 0; } -int -server_resolve_is_empty (server_resolve_t *resolve) +server_ctx_t * +server_ctx_get(client_t *client, xlator_t *xlator) { - if (resolve->fd_no != -1) - return 0; + void *tmp = NULL; + server_ctx_t *ctx = NULL; + server_ctx_t *setted_ctx = NULL; - if (resolve->ino != 0) - return 0; + client_ctx_get(client, xlator, &tmp); - if (resolve->gen != 0) - return 0; + ctx = tmp; - if (resolve->par != 0) - return 0; + if (ctx != NULL) + goto out; - if (resolve->path != 0) - return 0; + ctx = GF_CALLOC(1, sizeof(server_ctx_t), gf_server_mt_server_conf_t); - if (resolve->bname != 0) - return 0; + if (ctx == NULL) + goto out; - return 1; -} + ctx->fdtable = gf_fd_fdtable_alloc(); -void -server_print_reply (call_frame_t *frame, int op_ret, int op_errno) -{ - server_conf_t *conf = NULL; - server_state_t *state = NULL; - xlator_t *this = NULL; - char caller[512]; - char fdstr[32]; - char *op = "UNKNOWN"; + if (ctx->fdtable == NULL) { + GF_FREE(ctx); + ctx = NULL; + goto out; + } - this = frame->this; - conf = this->private; + LOCK_INIT(&ctx->fdtable_lock); - if (!conf->trace) - return; + setted_ctx = client_ctx_set(client, xlator, ctx); + if (ctx != setted_ctx) { + LOCK_DESTROY(&ctx->fdtable_lock); + GF_FREE(ctx->fdtable); + GF_FREE(ctx); + ctx = setted_ctx; + } - state = CALL_STATE (frame); +out: + return ctx; +} - print_caller (caller, 256, frame); +int +auth_set_username_passwd(dict_t *input_params, dict_t *config_params, + client_t *client) +{ + int ret = 0; + data_t *allow_user = NULL; + data_t *passwd_data = NULL; + char *username = NULL; + char *password = NULL; + char *brick_name = NULL; + char *searchstr = NULL; + char *username_str = NULL; + char *tmp = NULL; + char *username_cpy = NULL; + + ret = dict_get_str(input_params, "username", &username); + if (ret) { + gf_msg_debug("auth/login", 0, + "username not found, returning " + "DONT-CARE"); + /* For non trusted clients username and password + will not be there. So don't reject the client. + */ + ret = 0; + goto out; + } + + ret = dict_get_str(input_params, "password", &password); + if (ret) { + gf_smsg("auth/login", GF_LOG_WARNING, 0, PS_MSG_PASSWORD_NOT_FOUND, + NULL); + goto out; + } + + ret = dict_get_str(input_params, "remote-subvolume", &brick_name); + if (ret) { + gf_smsg("auth/login", GF_LOG_ERROR, 0, + PS_MSG_REMOTE_SUBVOL_NOT_SPECIFIED, NULL); + ret = -1; + goto out; + } + + ret = gf_asprintf(&searchstr, "auth.login.%s.allow", brick_name); + if (-1 == ret) { + ret = 0; + goto out; + } + + allow_user = dict_get(config_params, searchstr); + GF_FREE(searchstr); + + if (allow_user) { + username_cpy = gf_strdup(allow_user->data); + if (!username_cpy) + goto out; + + username_str = strtok_r(username_cpy, " ,", &tmp); + + while (username_str) { + if (!fnmatch(username_str, username, 0)) { + ret = gf_asprintf(&searchstr, "auth.login.%s.password", + username); + if (-1 == ret) + goto out; + + passwd_data = dict_get(config_params, searchstr); + GF_FREE(searchstr); + + if (!passwd_data) { + gf_smsg("auth/login", GF_LOG_ERROR, 0, PS_MSG_LOGIN_ERROR, + NULL); + ret = -1; + goto out; + } - switch (frame->root->type) { - case GF_OP_TYPE_FOP: - op = gf_fop_list[frame->root->op]; - break; - case GF_OP_TYPE_MGMT: - op = gf_mgmt_list[frame->root->op]; + ret = strcmp(data_to_str(passwd_data), password); + if (!ret) { + client->auth.username = gf_strdup(username); + client->auth.passwd = gf_strdup(password); + } else { + gf_smsg("auth/login", GF_LOG_ERROR, 0, PS_MSG_LOGIN_ERROR, + "username=%s", username, NULL); + } break; - default: - op = ""; + } + username_str = strtok_r(NULL, " ,", &tmp); } + } - fdstr[0] = '\0'; - if (state->fd) - snprintf (fdstr, 32, " fd=%p", state->fd); +out: + GF_FREE(username_cpy); - gf_log (this->name, GF_LOG_NORMAL, - "%s%s => (%d, %d)%s", - op, caller, op_ret, op_errno, fdstr); + return ret; } +inode_t * +server_inode_new(inode_table_t *itable, uuid_t gfid) +{ + if (__is_root_gfid(gfid)) + return itable->root; + else + return inode_new(itable); +} -void -server_print_request (call_frame_t *frame) +int +unserialize_req_locklist(gfs3_setactivelk_req *req, lock_migration_info_t *lmi) { - server_conf_t *conf = NULL; - xlator_t *this = NULL; - server_state_t *state = NULL; - char resolve_vars[256]; - char resolve2_vars[256]; - char loc_vars[256]; - char loc2_vars[256]; - char other_vars[512]; - char caller[512]; - char *op = "UNKNOWN"; - - this = frame->this; - conf = this->private; - - state = CALL_STATE (frame); - - if (!conf->trace) - return; - - memset (resolve_vars, '\0', 256); - memset (resolve2_vars, '\0', 256); - memset (loc_vars, '\0', 256); - memset (loc2_vars, '\0', 256); - memset (other_vars, '\0', 256); - - print_caller (caller, 256, frame); - - if (!server_resolve_is_empty (&state->resolve)) { - server_print_resolve (resolve_vars, 256, &state->resolve); - server_print_loc (loc_vars, 256, &state->loc); - } + struct gfs3_locklist *trav = NULL; + lock_migration_info_t *temp = NULL; + int ret = -1; - if (!server_resolve_is_empty (&state->resolve2)) { - server_print_resolve (resolve2_vars, 256, &state->resolve2); - server_print_loc (loc2_vars, 256, &state->loc2); - } + trav = req->request; - server_print_params (other_vars, 512, state); + INIT_LIST_HEAD(&lmi->list); - switch (frame->root->type) { - case GF_OP_TYPE_FOP: - op = gf_fop_list[frame->root->op]; - break; - case GF_OP_TYPE_MGMT: - op = gf_mgmt_list[frame->root->op]; - break; - default: - op = ""; - break; + while (trav) { + temp = GF_CALLOC(1, sizeof(*lmi), gf_common_mt_lock_mig); + if (temp == NULL) { + gf_smsg(THIS->name, GF_LOG_ERROR, 0, PS_MSG_NO_MEM, NULL); + goto out; } - gf_log (this->name, GF_LOG_NORMAL, - "%s%s%s%s%s%s%s", - op, caller, - resolve_vars, loc_vars, resolve2_vars, loc2_vars, other_vars); -} + INIT_LIST_HEAD(&temp->list); -int -serialize_rsp_direntp (gf_dirent_t *entries, gfs3_readdirp_rsp *rsp) -{ - gf_dirent_t *entry = NULL; - gfs3_dirplist *trav = NULL; - gfs3_dirplist *prev = NULL; - int ret = -1; + gf_proto_flock_to_flock(&trav->flock, &temp->flock); - list_for_each_entry (entry, &entries->list, list) { - trav = GF_CALLOC (1, sizeof (*trav), gf_server_mt_dirent_rsp_t); - if (!trav) - goto out; + temp->lk_flags = trav->lk_flags; - 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 = memdup (entry->d_name, entry->d_len + 1); - trav->name = entry->d_name; + temp->client_uid = gf_strdup(trav->client_uid); - gf_stat_from_iatt (&trav->stat, &entry->d_stat); + list_add_tail(&temp->list, &lmi->list); - if (prev) - prev->nextentry = trav; - else - rsp->reply = trav; + trav = trav->nextentry; + } - prev = trav; - } - - ret = 0; + ret = 0; out: - return ret; + return ret; } - int -serialize_rsp_dirent (gf_dirent_t *entries, gfs3_readdir_rsp *rsp) +unserialize_req_locklist_v2(gfx_setactivelk_req *req, + lock_migration_info_t *lmi) { - gf_dirent_t *entry = NULL; - gfs3_dirlist *trav = NULL; - gfs3_dirlist *prev = NULL; - int ret = -1; - - 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; - } + struct gfs3_locklist *trav = NULL; + lock_migration_info_t *temp = NULL; + int ret = -1; - ret = 0; -out: - return ret; -} + trav = req->request; -int -readdir_rsp_cleanup (gfs3_readdir_rsp *rsp) -{ - gfs3_dirlist *prev = NULL; - gfs3_dirlist *trav = NULL; + INIT_LIST_HEAD(&lmi->list); - trav = rsp->reply; - prev = trav; - while (trav) { - trav = trav->nextentry; - GF_FREE (prev); - prev = trav; + while (trav) { + temp = GF_CALLOC(1, sizeof(*lmi), gf_common_mt_lock_mig); + if (temp == NULL) { + gf_smsg(THIS->name, GF_LOG_ERROR, 0, PS_MSG_NO_MEM, NULL); + goto out; } - return 0; -} + INIT_LIST_HEAD(&temp->list); -int -readdirp_rsp_cleanup (gfs3_readdirp_rsp *rsp) -{ - gfs3_dirplist *prev = NULL; - gfs3_dirplist *trav = NULL; + gf_proto_flock_to_flock(&trav->flock, &temp->flock); - trav = rsp->reply; - prev = trav; - while (trav) { - trav = trav->nextentry; - GF_FREE (prev); - prev = trav; - } + temp->lk_flags = trav->lk_flags; - return 0; + temp->client_uid = gf_strdup(trav->client_uid); + + list_add_tail(&temp->list, &lmi->list); + + trav = trav->nextentry; + } + + ret = 0; +out: + return ret; } diff --git a/xlators/protocol/server/src/server-helpers.h b/xlators/protocol/server/src/server-helpers.h index 94c4d509b02..837fdc84f17 100644 --- a/xlators/protocol/server/src/server-helpers.h +++ b/xlators/protocol/server/src/server-helpers.h @@ -1,86 +1,107 @@ /* - Copyright (c) 2010 Gluster, Inc. <http://www.gluster.com> + Copyright (c) 2010-2013 Red Hat, Inc. <http://www.redhat.com> This file is part of GlusterFS. - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. + 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. */ #ifndef _SERVER_HELPERS_H #define _SERVER_HELPERS_H #include "server.h" +#include <glusterfs/defaults.h> -#define CALL_STATE(frame) ((server_state_t *)frame->root->state) - -#define BOUND_XL(frame) ((xlator_t *) CALL_STATE(frame)->conn->bound_xl) +#define CALL_STATE(frame) ((server_state_t *)frame->root->state) -#define XPRT_FROM_FRAME(frame) ((rpc_transport_t *) CALL_STATE(frame)->xprt) +#define XPRT_FROM_FRAME(frame) ((rpc_transport_t *)CALL_STATE(frame)->xprt) -#define SERVER_CONNECTION(frame) \ - ((server_connection_t *) CALL_STATE(frame)->conn) - -#define SERVER_CONF(frame) \ - ((server_conf_t *)XPRT_FROM_FRAME(frame)->this->private) +#define SERVER_CONF(frame) \ + ((server_conf_t *)XPRT_FROM_FRAME(frame)->this->private) #define XPRT_FROM_XLATOR(this) ((((server_conf_t *)this->private))->listen) -#define INODE_LRU_LIMIT(this) \ - (((server_conf_t *)(this->private))->config.inode_lru_limit) +#define INODE_LRU_LIMIT(this) \ + (((server_conf_t *)(this->private))->config.inode_lru_limit) #define IS_ROOT_INODE(inode) (inode == inode->table->root) -#define IS_NOT_ROOT(pathlen) ((pathlen > 2)? 1 : 0) - -void free_state (server_state_t *state); +#define IS_NOT_ROOT(pathlen) ((pathlen > 2) ? 1 : 0) -void server_loc_wipe (loc_t *loc); - -int32_t -gf_add_locker (struct _lock_table *table, const char *volume, - loc_t *loc, - fd_t *fd, - pid_t pid, - uint64_t owner); +void +free_state(server_state_t *state); -int32_t -gf_del_locker (struct _lock_table *table, const char *volume, - loc_t *loc, - fd_t *fd, - uint64_t owner); +void +server_loc_wipe(loc_t *loc); void -server_print_request (call_frame_t *frame); +server_print_request(call_frame_t *frame); call_frame_t * -get_frame_from_request (rpcsvc_request_t *req); +get_frame_from_request(rpcsvc_request_t *req); -server_connection_t * -get_server_conn_state (xlator_t *this, rpc_transport_t *xptr); +int +server_connection_cleanup(xlator_t *this, struct _client *client, int32_t flags, + gf_boolean_t *fd_exist); -server_connection_t * -create_server_conn_state (xlator_t *this, rpc_transport_t *xptr); +int +server_build_config(xlator_t *this, server_conf_t *conf); -void -destroy_server_conn_state (server_connection_t *conn); +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); +server_ctx_t * +server_ctx_get(client_t *client, xlator_t *xlator); int -server_build_config (xlator_t *this, server_conf_t *conf); +server_process_event_upcall(xlator_t *this, void *data); -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); +inode_t * +server_inode_new(inode_table_t *itable, uuid_t gfid); + +int +serialize_rsp_locklist(lock_migration_info_t *locklist, + 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 +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); #endif /* !_SERVER_HELPERS_H */ diff --git a/xlators/protocol/server/src/server-mem-types.h b/xlators/protocol/server/src/server-mem-types.h index 32f31fae783..081e9f40e84 100644 --- a/xlators/protocol/server/src/server-mem-types.h +++ b/xlators/protocol/server/src/server-mem-types.h @@ -1,38 +1,27 @@ /* - Copyright (c) 2010 Gluster, Inc. <http://www.gluster.com> - This file is part of GlusterFS. + Copyright (c) 2010-2013 Red Hat, Inc. <http://www.redhat.com> + This file is part of GlusterFS. - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. + 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. */ - #ifndef __SERVER_MEM_TYPES_H__ #define __SERVER_MEM_TYPES_H__ -#include "mem-types.h" +#include <glusterfs/mem-types.h> enum gf_server_mem_types_ { - gf_server_mt_server_conf_t = gf_common_mt_end + 1, - gf_server_mt_resolv_comp_t, - gf_server_mt_state_t, - gf_server_mt_locker_t, - gf_server_mt_lock_table_t, - gf_server_mt_conn_t, - gf_server_mt_dirent_rsp_t, - gf_server_mt_rsp_buf_t, - gf_server_mt_volfile_ctx_t, - gf_server_mt_end, + gf_server_mt_server_conf_t = gf_common_mt_end + 1, + gf_server_mt_state_t, + gf_server_mt_dirent_rsp_t, + gf_server_mt_rsp_buf_t, + gf_server_mt_setvolume_rsp_t, + gf_server_mt_lock_mig_t, + gf_server_mt_compound_rsp_t, + gf_server_mt_child_status, + gf_server_mt_end, }; #endif /* __SERVER_MEM_TYPES_H__ */ diff --git a/xlators/protocol/server/src/server-messages.h b/xlators/protocol/server/src/server-messages.h new file mode 100644 index 00000000000..1b2e149cb7d --- /dev/null +++ b/xlators/protocol/server/src/server-messages.h @@ -0,0 +1,168 @@ +/* + Copyright (c) 2015 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. +*/ + +#ifndef _PS_MESSAGES_H__ +#define _PS_MESSAGES_H__ + +#include <glusterfs/glfs-message-id.h> + +/* To add new message IDs, append new identifiers at the end of the list. + * + * Never remove a message ID. If it's not used anymore, you can rename it or + * leave it as it is, but not delete it. This is to prevent reutilization of + * IDs by other messages. + * + * The component name must match one of the entries defined in + * glfs-message-id.h. + */ + +GLFS_MSGID( + PS, PS_MSG_AUTHENTICATE_ERROR, PS_MSG_VOL_VALIDATE_FAILED, + PS_MSG_AUTH_INIT_FAILED, PS_MSG_REMOTE_CLIENT_REFUSED, + PS_MSG_GFID_RESOLVE_FAILED, PS_MSG_ANONYMOUS_FD_CREATE_FAILED, + PS_MSG_NO_MEMORY, PS_MSG_FD_NOT_FOUND, PS_MSG_INVALID_ENTRY, + PS_MSG_GET_UID_FAILED, PS_MSG_UID_NOT_FOUND, PS_MSG_MAPPING_ERROR, + PS_MSG_FD_CLEANUP, PS_MSG_SERVER_CTX_GET_FAILED, PS_MSG_FDENTRY_NULL, + PS_MSG_DIR_NOT_FOUND, PS_MSG_SERVER_MSG, PS_MSG_DICT_SERIALIZE_FAIL, + PS_MSG_RW_STAT, PS_MSG_DICT_GET_FAILED, PS_MSG_LOGIN_ERROR, + PS_MSG_REMOUNT_CLIENT_REQD, PS_MSG_DEFAULTING_FILE, + PS_MSG_VOL_FILE_OPEN_FAILED, PS_MSG_STAT_ERROR, PS_MSG_SSL_NAME_SET_FAILED, + PS_MSG_ASPRINTF_FAILED, PS_MSG_CLIENT_VERSION_NOT_SET, + PS_MSG_CLIENT_ACCEPTED, PS_MSG_CLIENT_LK_VERSION_ERROR, + PS_MSG_GRACE_TIMER_EXPD, PS_MSG_SERIALIZE_REPLY_FAILED, + PS_MSG_AUTH_IP_ERROR, PS_MSG_SKIP_FORMAT_CHK, PS_MSG_INTERNET_ADDR_ERROR, + PS_MSG_CLIENT_DISCONNECTING, PS_MSG_GRACE_TIMER_START, + PS_MSG_STATEDUMP_PATH_ERROR, PS_MSG_GRP_CACHE_ERROR, PS_MSG_RPC_CONF_ERROR, + PS_MSG_TRANSPORT_ERROR, PS_MSG_SUBVOL_NULL, PS_MSG_PARENT_VOL_ERROR, + PS_MSG_RPCSVC_CREATE_FAILED, PS_MSG_RPCSVC_LISTENER_CREATE_FAILED, + PS_MSG_RPCSVC_NOTIFY, PS_MSG_PGM_REG_FAILED, PS_MSG_ULIMIT_SET_FAILED, + PS_MSG_STATFS, PS_MSG_LOOKUP_INFO, PS_MSG_LK_INFO, PS_MSG_LOCK_ERROR, + PS_MSG_INODELK_INFO, PS_MSG_ENTRYLK_INFO, PS_MSG_ACCESS_INFO, + PS_MSG_DIR_INFO, PS_MSG_MKNOD_INFO, PS_MSG_REMOVEXATTR_INFO, + PS_MSG_GETXATTR_INFO, PS_MSG_SETXATTR_INFO, PS_MSG_RENAME_INFO, + PS_MSG_LINK_INFO, PS_MSG_TRUNCATE_INFO, PS_MSG_FSTAT_INFO, + PS_MSG_FLUSH_INFO, PS_MSG_SYNC_INFO, PS_MSG_WRITE_INFO, PS_MSG_READ_INFO, + PS_MSG_CHKSUM_INFO, PS_MSG_OPEN_INFO, PS_MSG_CREATE_INFO, + PS_MSG_SETATTR_INFO, PS_MSG_XATTROP_INFO, PS_MSG_ALLOC_INFO, + PS_MSG_DISCARD_INFO, PS_MSG_ZEROFILL_INFO, PS_MSG_FD_CREATE_FAILED, + PS_MSG_WRONG_STATE, PS_MSG_CONF_DIR_INVALID, PS_MSG_MOUNT_PT_FAIL, + PS_MSG_STAT_INFO, PS_MSG_FILE_OP_FAILED, PS_MSG_GRACE_TIMER_CANCELLED, + PS_MSG_ENCODE_MSG_FAILED, PS_MSG_REPLY_SUBMIT_FAILED, + PS_MSG_RPC_NOTIFY_ERROR, PS_MSG_SERVER_EVENT_UPCALL_FAILED, + PS_MSG_SERVER_IPC_INFO, PS_MSG_SEEK_INFO, PS_MSG_COMPOUND_INFO, + PS_MSG_CLIENT_OPVERSION_GET_FAILED, PS_MSG_CHILD_STATUS_FAILED, + PS_MSG_PUT_INFO, PS_MSG_UNAUTHORIZED_CLIENT, PS_MSG_RECONFIGURE_FAILED, + PS_MSG_SET_STATEDUMP_PATH_ERROR, PS_MSG_INIT_GRP_CACHE_ERROR, + PS_MSG_RPC_CONFIGURE_FAILED, PS_MSG_TRANSPORT_TYPE_NOT_SET, + PS_MSG_GET_TOTAL_AVAIL_TRANSPORT_FAILED, PS_MSG_INVLAID_UPCALL_EVENT, + PS_MSG_SERVER_CHILD_EVENT_FAILED, PS_MSG_SETACTIVELK_INFO, + PS_MSG_GETACTIVELK_INFO, PS_MSG_WRONG_VALUE, PS_MSG_PASSWORD_NOT_FOUND, + PS_MSG_REMOTE_SUBVOL_NOT_SPECIFIED, PS_MSG_NO_MEM); + +#define PS_MSG_SERIALIZE_REPLY_FAILED_STR "Failed to serialize reply" +#define PS_MSG_AUTH_IP_ERROR_STR "assuming 'auth.ip' to be 'auth.addr'" +#define PS_MSG_SKIP_FORMAT_CHK_STR "skip format check for non-addr auth option" +#define PS_MSG_INTERNET_ADDR_ERROR_STR \ + "internet address does not confirm to standards" +#define PS_MSG_AUTHENTICATE_ERROR_STR \ + "volume defined as subvolume, but no authentication defined for the same" +#define PS_MSG_CLIENT_DISCONNECTING_STR "disconnecting connection" +#define PS_MSG_DICT_GET_FAILED_STR "failed to get" +#define PS_MSG_NO_MEMORY_STR "Memory accounting init failed" +#define PS_MSG_INVALID_ENTRY_STR \ + "'trace' takes on only boolean values. Neglecting option" +#define PS_MSG_STATEDUMP_PATH_ERROR_STR \ + "Error while reconfiguring statedump path" +#define PS_MSG_GRP_CACHE_ERROR_STR "Failed to reconfigure group cache." +#define PS_MSG_RPC_CONF_ERROR_STR "No rpc_conf !!!!" +#define PS_MSG_CLIENT_ACCEPTED_STR \ + "authorized client, hence we continue with this connection" +#define PS_MSG_UNAUTHORIZED_CLIENT_STR \ + "unauthorized client, hence terminating the connection" +#define PS_MSG_RECONFIGURE_FAILED_STR \ + "Failed to reconfigure outstanding-rpc-limit" +#define PS_MSG_TRANSPORT_ERROR_STR "Reconfigure not found for transport" +#define PS_MSG_SUBVOL_NULL_STR "protocol/server should have subvolume" +#define PS_MSG_PARENT_VOL_ERROR_STR \ + "protocol/server should not have parent volumes" +#define PS_MSG_SET_STATEDUMP_PATH_ERROR_STR "Error setting statedump path" +#define PS_MSG_INIT_GRP_CACHE_ERROR_STR "Failed to initialize group cache." +#define PS_MSG_RPCSVC_CREATE_FAILED_STR "creation of rpcsvc failed" +#define PS_MSG_RPC_CONFIGURE_FAILED_STR \ + "Failed to configure outstanding-rpc-limit" +#define PS_MSG_TRANSPORT_TYPE_NOT_SET_STR "option transport-type not set" +#define PS_MSG_GET_TOTAL_AVAIL_TRANSPORT_FAILED_STR \ + "failed to get total number of available tranpsorts" +#define PS_MSG_RPCSVC_LISTENER_CREATE_FAILED_STR "creation of listener failed" +#define PS_MSG_RPCSVC_NOTIFY_STR "registration of notify with rpcsvc failed" +#define PS_MSG_PGM_REG_FAILED_STR "registration of program failed" +#define PS_MSG_ULIMIT_SET_FAILED_STR "WARNING: Failed to set 'ulimit -n 1M'" +#define PS_MSG_FD_NOT_FOUND_STR "Failed to set max open fd to 64k" +#define PS_MSG_VOL_FILE_OPEN_FAILED_STR \ + "volfile-id argument not given. This is mandatory argument, defaulting " \ + "to 'gluster'" +#define PS_MSG_INVLAID_UPCALL_EVENT_STR "Received invalid upcall event" +#define PS_MSG_CHILD_STATUS_FAILED_STR "No xlator is found in child status list" +#define PS_MSG_SERVER_EVENT_UPCALL_FAILED_STR \ + "server_process_event_upcall failed" +#define PS_MSG_SERVER_CHILD_EVENT_FAILED_STR "server_process_child_event failed" +#define PS_MSG_STATFS_STR "STATFS" +#define PS_MSG_LOOKUP_INFO_STR "LOOKUP info" +#define PS_MSG_LK_INFO_STR "LEASE info" +#define PS_MSG_INODELK_INFO_STR "INODELK info" +#define PS_MSG_DIR_INFO_STR "MKDIR info" +#define PS_MSG_MKNOD_INFO_STR "MKNOD info" +#define PS_MSG_REMOVEXATTR_INFO_STR "REMOVEXATTR info" +#define PS_MSG_GETXATTR_INFO_STR "GETXATTR info" +#define PS_MSG_SETXATTR_INFO_STR "SETXATTR info" +#define PS_MSG_RENAME_INFO_STR "RENAME inf" +#define PS_MSG_LINK_INFO_STR "LINK info" +#define PS_MSG_TRUNCATE_INFO_STR "TRUNCATE info" +#define PS_MSG_STAT_INFO_STR "STAT info" +#define PS_MSG_FLUSH_INFO_STR "FLUSH info" +#define PS_MSG_SYNC_INFO_STR "SYNC info" +#define PS_MSG_WRITE_INFO_STR "WRITE info" +#define PS_MSG_READ_INFO_STR "READ info" +#define PS_MSG_CHKSUM_INFO_STR "CHKSUM info" +#define PS_MSG_OPEN_INFO_STR "OPEN info" +#define PS_MSG_XATTROP_INFO_STR "XATTROP info" +#define PS_MSG_ALLOC_INFO_STR "ALLOC info" +#define PS_MSG_DISCARD_INFO_STR "DISCARD info" +#define PS_MSG_ZEROFILL_INFO_STR "ZEROFILL info" +#define PS_MSG_SERVER_IPC_INFO_STR "IPC info" +#define PS_MSG_SEEK_INFO_STR "SEEK info" +#define PS_MSG_SETACTIVELK_INFO_STR "SETACTIVELK info" +#define PS_MSG_CREATE_INFO_STR "CREATE info" +#define PS_MSG_PUT_INFO_STR "PUT info" +#define PS_MSG_FD_CREATE_FAILED_STR "could not create the fd" +#define PS_MSG_GETACTIVELK_INFO_STR "GETACTIVELK info" +#define PS_MSG_ENTRYLK_INFO_STR "ENTRYLK info" +#define PS_MSG_ACCESS_INFO_STR "ACCESS info" +#define PS_MSG_SETATTR_INFO_STR "SETATTR info" +#define PS_MSG_SERVER_CTX_GET_FAILED_STR "server_ctx_get() failed" +#define PS_MSG_LOCK_ERROR_STR "Unknown lock type" +#define PS_MSG_GET_UID_FAILED_STR "getpwuid_r failed" +#define PS_MSG_UID_NOT_FOUND_STR "getpwuid_r found nothing" +#define PS_MSG_MAPPING_ERROR_STR "could not map to group list" +#define PS_MSG_FD_CLEANUP_STR "fd cleanup" +#define PS_MSG_FDENTRY_NULL_STR "no fdentry to clean" +#define PS_MSG_WRONG_VALUE_STR \ + "wrong value for 'verify-volfile-checksum', Neglecting option" +#define PS_MSG_DIR_NOT_FOUND_STR "Directory doesnot exist" +#define PS_MSG_CONF_DIR_INVALID_STR "invalid conf_dir" +#define PS_MSG_SERVER_MSG_STR "server msg" +#define PS_MSG_DICT_SERIALIZE_FAIL_STR "failed to serialize reply dict" +#define PS_MSG_MOUNT_PT_FAIL_STR "mount point fail" +#define PS_MSG_RW_STAT_STR "stat" +#define PS_MSG_PASSWORD_NOT_FOUND_STR "password not found, returning DONT-CARE" +#define PS_MSG_REMOTE_SUBVOL_NOT_SPECIFIED_STR "remote-subvolume not specified" +#define PS_MSG_LOGIN_ERROR_STR "wrong password for user" +#define PS_MSG_NO_MEM_STR "No memory" +#endif /* !_PS_MESSAGES_H__ */ diff --git a/xlators/protocol/server/src/server-resolve.c b/xlators/protocol/server/src/server-resolve.c index e7c1cc85fd5..ec768acba44 100644 --- a/xlators/protocol/server/src/server-resolve.c +++ b/xlators/protocol/server/src/server-resolve.c @@ -1,312 +1,266 @@ /* - Copyright (c) 2010 Gluster, Inc. <http://www.gluster.com> + Copyright (c) 2010-2013 Red Hat, Inc. <http://www.redhat.com> This file is part of GlusterFS. - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. + 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. */ -#ifndef _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif - #include "server.h" #include "server-helpers.h" - +#include "server-messages.h" int -server_resolve_all (call_frame_t *frame); +server_resolve_all(call_frame_t *frame); int -resolve_entry_simple (call_frame_t *frame); +resolve_entry_simple(call_frame_t *frame); int -resolve_inode_simple (call_frame_t *frame); +resolve_inode_simple(call_frame_t *frame); int -resolve_path_simple (call_frame_t *frame); - +resolve_continue(call_frame_t *frame); int -component_count (const char *path) -{ - int count = 0; - const char *trav = NULL; - - for (trav = path; *trav; trav++) { - if (*trav == '/') - count++; - } - - return count + 2; -} - +resolve_anonfd_simple(call_frame_t *frame); int -prepare_components (call_frame_t *frame) +resolve_loc_touchup(call_frame_t *frame) { - server_state_t *state = NULL; - server_resolve_t *resolve = NULL; - char *resolved = NULL; - int count = 0; - struct resolve_comp *components = NULL; - int i = 0; - char *trav = NULL; - - - state = CALL_STATE (frame); - resolve = state->resolve_now; - - resolved = gf_strdup (resolve->path); - resolve->resolved = resolved; - - count = component_count (resolve->path); - components = GF_CALLOC (sizeof (*components), count, - gf_server_mt_resolv_comp_t); - if (!components) - goto out; - resolve->components = components; - - components[0].basename = ""; - components[0].ino = 1; - components[0].gen = 0; - components[0].inode = state->itable->root; - - i = 1; - for (trav = resolved; *trav; trav++) { - if (*trav == '/') { - components[i].basename = trav + 1; - *trav = 0; - i++; - } - } -out: - return 0; -} + server_state_t *state = NULL; + server_resolve_t *resolve = NULL; + loc_t *loc = NULL; + state = CALL_STATE(frame); -int -resolve_loc_touchup (call_frame_t *frame) -{ - server_state_t *state = NULL; - server_resolve_t *resolve = NULL; - loc_t *loc = NULL; - char *path = NULL; - int ret = 0; - - state = CALL_STATE (frame); - - resolve = state->resolve_now; - loc = state->loc_now; - - if (!loc->path) { - if (loc->parent) { - ret = inode_path (loc->parent, resolve->bname, &path); - } else if (loc->inode) { - ret = inode_path (loc->inode, NULL, &path); - } - if (ret) - gf_log ("", GF_LOG_DEBUG, - "return value inode_path %d", ret); - - if (!path) - path = gf_strdup (resolve->path); - - loc->path = path; - } - - loc->name = strrchr (loc->path, '/'); - if (loc->name) - loc->name++; - - if (!loc->parent && loc->inode) { - loc->parent = inode_parent (loc->inode, 0, NULL); - } + resolve = state->resolve_now; + loc = state->loc_now; - return 0; + loc_touchup(loc, resolve->bname); + return 0; } - int -resolve_deep_continue (call_frame_t *frame) +resolve_gfid_entry_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int op_ret, int op_errno, inode_t *inode, + struct iatt *buf, dict_t *xdata, struct iatt *postparent) { - server_state_t *state = NULL; - xlator_t *this = NULL; - server_resolve_t *resolve = NULL; - int ret = 0; + server_state_t *state = NULL; + server_resolve_t *resolve = NULL; + inode_t *link_inode = NULL; + loc_t *resolve_loc = NULL; + + state = CALL_STATE(frame); + resolve = state->resolve_now; + resolve_loc = &resolve->resolve_loc; + + if (op_ret == -1) { + if (op_errno == ENOENT) { + gf_msg_debug(this->name, 0, "%s/%s: failed to resolve (%s)", + uuid_utoa(resolve_loc->pargfid), resolve_loc->name, + strerror(op_errno)); + if (resolve->type == RESOLVE_NOT) { + do { + inode = inode_grep(state->itable, resolve_loc->parent, + resolve->bname); + + if (inode) { + gf_msg_debug(this->name, 0, + "%s/%s: " + "removing stale dentry", + uuid_utoa(resolve_loc->pargfid), + resolve->bname); + inode_unlink(inode, resolve_loc->parent, + resolve->bname); + } + } while (inode); + } + } else { + gf_msg(this->name, GF_LOG_WARNING, op_errno, + PS_MSG_GFID_RESOLVE_FAILED, + "%s/%s: failed to " + "resolve (%s)", + uuid_utoa(resolve_loc->pargfid), resolve_loc->name, + strerror(op_errno)); + } + goto out; + } - state = CALL_STATE (frame); - this = frame->this; - resolve = state->resolve_now; + link_inode = inode_link(inode, resolve_loc->parent, resolve_loc->name, buf); - resolve->op_ret = 0; - resolve->op_errno = 0; + if (!link_inode) + goto out; - if (resolve->pargfid) - ret = resolve_entry_simple (frame); - else if (resolve->gfid) - ret = resolve_inode_simple (frame); - else if (resolve->path) - ret = resolve_path_simple (frame); - if (ret) - gf_log (this->name, GF_LOG_DEBUG, - "return value of resolve_*_simple %d", ret); + inode_lookup(link_inode); - resolve_loc_touchup (frame); + inode_unref(link_inode); - server_resolve_all (frame); +out: + loc_wipe(resolve_loc); - return 0; + resolve_continue(frame); + return 0; } - int -resolve_deep_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int op_ret, int op_errno, inode_t *inode, struct iatt *buf, - dict_t *xattr, struct iatt *postparent) +resolve_gfid_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int op_ret, + int op_errno, inode_t *inode, struct iatt *buf, dict_t *xdata, + struct iatt *postparent) { - server_state_t *state = NULL; - server_resolve_t *resolve = NULL; - struct resolve_comp *components = NULL; - int i = 0; - inode_t *link_inode = NULL; - - state = CALL_STATE (frame); - resolve = state->resolve_now; - components = resolve->components; - - i = (long) cookie; - - if (op_ret == -1) { - goto get_out_of_here; - } - - if (i != 0) { - /* no linking for root inode */ - link_inode = inode_link (inode, resolve->deep_loc.parent, - resolve->deep_loc.name, buf); - inode_lookup (link_inode); - components[i].inode = link_inode; - link_inode = NULL; - } - - loc_wipe (&resolve->deep_loc); - - i++; /* next component */ - - if (!components[i].basename) { - /* all components of the path are resolved */ - goto get_out_of_here; + server_state_t *state = NULL; + server_resolve_t *resolve = NULL; + inode_t *link_inode = NULL; + loc_t *resolve_loc = NULL; + dict_t *dict = NULL; + + state = CALL_STATE(frame); + resolve = state->resolve_now; + resolve_loc = &resolve->resolve_loc; + + if (op_ret == -1) { + if (op_errno == ENOENT) { + gf_msg_debug(this->name, GF_LOG_DEBUG, "%s: failed to resolve (%s)", + uuid_utoa(resolve_loc->gfid), strerror(op_errno)); + } else { + gf_msg(this->name, GF_LOG_WARNING, op_errno, + PS_MSG_GFID_RESOLVE_FAILED, "%s: failed to resolve (%s)", + uuid_utoa(resolve_loc->gfid), strerror(op_errno)); } - - /* join the current component with the path resolved until now */ - *(components[i].basename - 1) = '/'; - - resolve->deep_loc.path = gf_strdup (resolve->resolved); - resolve->deep_loc.parent = inode_ref (components[i-1].inode); - resolve->deep_loc.inode = inode_new (state->itable); - resolve->deep_loc.name = components[i].basename; - - STACK_WIND_COOKIE (frame, resolve_deep_cbk, (void *) (long) i, - BOUND_XL (frame), BOUND_XL (frame)->fops->lookup, - &resolve->deep_loc, NULL); - return 0; - -get_out_of_here: - resolve_deep_continue (frame); - return 0; + loc_wipe(&resolve->resolve_loc); + goto out; + } + + link_inode = inode_link(inode, NULL, NULL, buf); + + if (!link_inode) { + loc_wipe(resolve_loc); + goto out; + } + + inode_lookup(link_inode); + + /* wipe the loc only after the inode has been linked to the inode + table. Otherwise before inode gets linked to the inode table, + inode would have been unrefed (this might have been destroyed + if refcount becomes 0, and put back to mempool). So once the + inode gets destroyed, inode_link is a redundant operation. But + without knowing that the destroyed inode's pointer is saved in + the resolved_loc as parent (while constructing loc for resolving + the entry) and the inode_new call for resolving the entry will + return the same pointer to the inode as the parent (because in + reality the inode is a free inode present in cold list of the + inode mem-pool). + */ + loc_wipe(resolve_loc); + + if (gf_uuid_is_null(resolve->pargfid)) { + inode_unref(link_inode); + goto out; + } + + resolve_loc->parent = link_inode; + gf_uuid_copy(resolve_loc->pargfid, resolve_loc->parent->gfid); + + resolve_loc->name = resolve->bname; + + resolve_loc->inode = server_inode_new(state->itable, resolve_loc->gfid); + + inode_path(resolve_loc->parent, resolve_loc->name, + (char **)&resolve_loc->path); + + if (state->xdata) { + dict = dict_copy_with_ref(state->xdata, NULL); + if (!dict) + gf_msg(this->name, GF_LOG_ERROR, ENOMEM, PS_MSG_NO_MEMORY, + "BUG: dict allocation failed (pargfid: %s, name: %s), " + "still continuing", + uuid_utoa(resolve_loc->gfid), resolve_loc->name); + } + + STACK_WIND(frame, resolve_gfid_entry_cbk, frame->root->client->bound_xl, + frame->root->client->bound_xl->fops->lookup, + &resolve->resolve_loc, dict); + if (dict) + dict_unref(dict); + return 0; +out: + resolve_continue(frame); + return 0; } - int -resolve_path_deep (call_frame_t *frame) +resolve_gfid(call_frame_t *frame) { - server_state_t *state = NULL; - server_resolve_t *resolve = NULL; - int i = 0; - - state = CALL_STATE (frame); - resolve = state->resolve_now; - - gf_log (BOUND_XL (frame)->name, GF_LOG_TRACE, - "RESOLVE %s() seeking deep resolution of %s", - gf_fop_list[frame->root->op], resolve->path); - - prepare_components (frame); - - /* start from the root */ - resolve->deep_loc.inode = state->itable->root; - resolve->deep_loc.path = gf_strdup ("/"); - resolve->deep_loc.name = ""; - - STACK_WIND_COOKIE (frame, resolve_deep_cbk, (void *) (long) i, - BOUND_XL (frame), BOUND_XL (frame)->fops->lookup, - &resolve->deep_loc, NULL); - return 0; + server_state_t *state = NULL; + xlator_t *this = NULL; + server_resolve_t *resolve = NULL; + loc_t *resolve_loc = NULL; + dict_t *xdata = NULL; + + state = CALL_STATE(frame); + this = frame->this; + resolve = state->resolve_now; + resolve_loc = &resolve->resolve_loc; + + if (!gf_uuid_is_null(resolve->pargfid)) + gf_uuid_copy(resolve_loc->gfid, resolve->pargfid); + else if (!gf_uuid_is_null(resolve->gfid)) + gf_uuid_copy(resolve_loc->gfid, resolve->gfid); + + resolve_loc->inode = server_inode_new(state->itable, resolve_loc->gfid); + (void)loc_path(resolve_loc, NULL); + + if (state->xdata) { + xdata = dict_copy_with_ref(state->xdata, NULL); + if (!xdata) + gf_msg(this->name, GF_LOG_ERROR, ENOMEM, PS_MSG_NO_MEMORY, + "BUG: dict allocation failed (gfid: %s), " + "still continuing", + uuid_utoa(resolve_loc->gfid)); + } + + STACK_WIND(frame, resolve_gfid_cbk, frame->root->client->bound_xl, + frame->root->client->bound_xl->fops->lookup, + &resolve->resolve_loc, xdata); + + if (xdata) + dict_unref(xdata); + + return 0; } - int -resolve_path_simple (call_frame_t *frame) +resolve_continue(call_frame_t *frame) { - server_state_t *state = NULL; - server_resolve_t *resolve = NULL; - struct resolve_comp *components = NULL; - int ret = -1; - int par_idx = 0; - int ino_idx = 0; - int i = 0; - - state = CALL_STATE (frame); - resolve = state->resolve_now; - components = resolve->components; - - if (!components) { - resolve->op_ret = -1; - resolve->op_errno = ENOENT; - goto out; - } - - for (i = 0; components[i].basename; i++) { - par_idx = ino_idx; - ino_idx = i; - } - - if (!components[par_idx].inode) { - resolve->op_ret = -1; - resolve->op_errno = ENOENT; - goto out; - } - - if (!components[ino_idx].inode && - (resolve->type == RESOLVE_MUST || resolve->type == RESOLVE_EXACT)) { - resolve->op_ret = -1; - resolve->op_errno = ENOENT; - goto out; - } - - if (components[ino_idx].inode && resolve->type == RESOLVE_NOT) { - resolve->op_ret = -1; - resolve->op_errno = EEXIST; - goto out; - } - - if (components[ino_idx].inode) - state->loc_now->inode = inode_ref (components[ino_idx].inode); - state->loc_now->parent = inode_ref (components[par_idx].inode); - - ret = 0; - + server_state_t *state = NULL; + xlator_t *this = NULL; + server_resolve_t *resolve = NULL; + int ret = 0; + + state = CALL_STATE(frame); + this = frame->this; + resolve = state->resolve_now; + + resolve->op_ret = 0; + resolve->op_errno = 0; + + if (resolve->fd_no != -1) { + ret = resolve_anonfd_simple(frame); + goto out; + } else if (!gf_uuid_is_null(resolve->pargfid)) + ret = resolve_entry_simple(frame); + else if (!gf_uuid_is_null(resolve->gfid)) + ret = resolve_inode_simple(frame); + if (ret) + gf_msg_debug(this->name, 0, + "return value of resolve_*_" + "simple %d", + ret); + + resolve_loc_touchup(frame); out: - return ret; + server_resolve_all(frame); + + return 0; } /* @@ -317,302 +271,413 @@ out: */ int -resolve_entry_simple (call_frame_t *frame) +resolve_entry_simple(call_frame_t *frame) { - server_state_t *state = NULL; - xlator_t *this = NULL; - server_resolve_t *resolve = NULL; - inode_t *parent = NULL; - inode_t *inode = NULL; - int ret = 0; - - state = CALL_STATE (frame); - this = frame->this; - resolve = state->resolve_now; - - parent = inode_find (state->itable, resolve->pargfid); - if (!parent) { - /* simple resolution is indecisive. need to perform - deep resolution */ - resolve->op_ret = -1; + server_state_t *state = NULL; + xlator_t *this = NULL; + server_resolve_t *resolve = NULL; + inode_t *parent = NULL; + inode_t *inode = NULL; + int ret = 0; + + state = CALL_STATE(frame); + this = frame->this; + resolve = state->resolve_now; + + parent = inode_find(state->itable, resolve->pargfid); + if (!parent) { + /* simple resolution is indecisive. need to perform + deep resolution */ + resolve->op_ret = -1; + resolve->op_errno = ESTALE; + ret = 1; + goto out; + } + + if (parent->ia_type != IA_IFDIR) { + /* Parent type should be 'directory', and nothing else */ + gf_msg(this->name, GF_LOG_ERROR, EPERM, PS_MSG_GFID_RESOLVE_FAILED, + "%s: parent type not directory (%d)", uuid_utoa(parent->gfid), + parent->ia_type); + resolve->op_ret = -1; + resolve->op_errno = EPERM; + ret = 1; + goto out; + } + + /* expected @parent was found from the inode cache */ + gf_uuid_copy(state->loc_now->pargfid, resolve->pargfid); + state->loc_now->parent = inode_ref(parent); + if (strchr(resolve->bname, '/')) { + /* basename should be a string (without '/') in a directory, + it can't span multiple levels. This can also lead to + resolving outside the parent's tree, which is not allowed */ + gf_msg(this->name, GF_LOG_ERROR, EPERM, PS_MSG_GFID_RESOLVE_FAILED, + "%s: basename sent by client not allowed", resolve->bname); + resolve->op_ret = -1; + resolve->op_errno = EPERM; + ret = 1; + goto out; + } + + state->loc_now->name = resolve->bname; + + inode = inode_grep(state->itable, parent, resolve->bname); + if (!inode) { + switch (resolve->type) { + case RESOLVE_DONTCARE: + case RESOLVE_NOT: + ret = 0; + break; + case RESOLVE_MAY: + ret = 1; + break; + default: + resolve->op_ret = -1; resolve->op_errno = ENOENT; ret = 1; - - inode = inode_grep (state->itable, parent, resolve->bname); - if (inode != NULL) { - gf_log (this->name, GF_LOG_DEBUG, "%"PRId64": inode " - "(pointer:%p ino: %"PRIu64") present but parent" - " is NULL for path (%s)", frame->root->unique, - inode, inode->ino, resolve->path); - inode_unref (inode); - } - goto out; + break; } - /* expected @parent was found from the inode cache */ - state->loc_now->parent = inode_ref (parent); - - inode = inode_grep (state->itable, parent, resolve->bname); - if (!inode) { - switch (resolve->type) { - case RESOLVE_DONTCARE: - case RESOLVE_NOT: - ret = 0; - break; - case RESOLVE_MAY: - ret = 1; - break; - default: - resolve->op_ret = -1; - resolve->op_errno = ENOENT; - ret = 1; - break; - } - - goto out; - } + goto out; + } - if (resolve->type == RESOLVE_NOT) { - gf_log (this->name, GF_LOG_DEBUG, "inode (pointer: %p ino:%" - PRIu64") found for path (%s) while type is RESOLVE_NOT", - inode, inode->ino, resolve->path); - resolve->op_ret = -1; - resolve->op_errno = EEXIST; - ret = -1; - goto out; - } + if (resolve->type == RESOLVE_NOT) { + gf_msg_debug(this->name, 0, + "inode (pointer: %p gfid:%s found" + " for path (%s) while type is RESOLVE_NOT. " + "Performing lookup on backend to rule out any " + "possible stale dentries in inode table", + inode, uuid_utoa(inode->gfid), resolve->path); + resolve->op_ret = -1; + resolve->op_errno = EEXIST; + ret = 1; + goto out; + } - ret = 0; + ret = 0; - state->loc_now->inode = inode_ref (inode); + state->loc_now->inode = inode_ref(inode); out: - if (parent) - inode_unref (parent); + if (parent) + inode_unref(parent); - if (inode) - inode_unref (inode); + if (inode) + inode_unref(inode); - return ret; + return ret; } - int -server_resolve_entry (call_frame_t *frame) +server_resolve_entry(call_frame_t *frame) { - server_state_t *state = NULL; - int ret = 0; - loc_t *loc = NULL; + server_state_t *state = NULL; + int ret = 0; + loc_t *loc = NULL; - state = CALL_STATE (frame); - loc = state->loc_now; + state = CALL_STATE(frame); + loc = state->loc_now; - ret = resolve_entry_simple (frame); + ret = resolve_entry_simple(frame); - if (ret > 0) { - loc_wipe (loc); - resolve_path_deep (frame); - return 0; - } + if (ret > 0) { + loc_wipe(loc); + resolve_gfid(frame); + return 0; + } - if (ret == 0) - resolve_loc_touchup (frame); + if (ret == 0) + resolve_loc_touchup(frame); - server_resolve_all (frame); + server_resolve_all(frame); - return 0; + return 0; } - int -resolve_inode_simple (call_frame_t *frame) +resolve_inode_simple(call_frame_t *frame) { - server_state_t *state = NULL; - server_resolve_t *resolve = NULL; - inode_t *inode = NULL; - int ret = 0; + server_state_t *state = NULL; + server_resolve_t *resolve = NULL; + inode_t *inode = NULL; + int ret = 0; - state = CALL_STATE (frame); - resolve = state->resolve_now; + state = CALL_STATE(frame); + resolve = state->resolve_now; - inode = inode_find (state->itable, resolve->gfid); + inode = inode_find(state->itable, resolve->gfid); - if (!inode) { - resolve->op_ret = -1; - resolve->op_errno = ENOENT; - ret = 1; - goto out; - } + if (!inode) { + resolve->op_ret = -1; + resolve->op_errno = ESTALE; + ret = 1; + goto out; + } - ret = 0; + ret = 0; - state->loc_now->inode = inode_ref (inode); + state->loc_now->inode = inode_ref(inode); + gf_uuid_copy(state->loc_now->gfid, resolve->gfid); out: - if (inode) - inode_unref (inode); + if (inode) + inode_unref(inode); - return ret; + return ret; } - int -server_resolve_inode (call_frame_t *frame) +server_resolve_inode(call_frame_t *frame) { - server_state_t *state = NULL; - int ret = 0; - loc_t *loc = NULL; + server_state_t *state = NULL; + int ret = 0; + loc_t *loc = NULL; - state = CALL_STATE (frame); - loc = state->loc_now; + state = CALL_STATE(frame); + loc = state->loc_now; - ret = resolve_inode_simple (frame); + ret = resolve_inode_simple(frame); - if (ret > 0) { - loc_wipe (loc); - resolve_path_deep (frame); - return 0; - } + if (ret > 0) { + loc_wipe(loc); + resolve_gfid(frame); + return 0; + } - if (ret == 0) - resolve_loc_touchup (frame); + if (ret == 0) + resolve_loc_touchup(frame); - server_resolve_all (frame); + server_resolve_all(frame); - return 0; + return 0; } - int -server_resolve_fd (call_frame_t *frame) +resolve_anonfd_simple(call_frame_t *frame) { - server_state_t *state = NULL; - server_resolve_t *resolve = NULL; - server_connection_t *conn = NULL; - uint64_t fd_no = -1; + server_state_t *state = NULL; + server_resolve_t *resolve = NULL; + inode_t *inode = NULL; + int ret = 0; - state = CALL_STATE (frame); - resolve = state->resolve_now; - conn = SERVER_CONNECTION (frame); + state = CALL_STATE(frame); + resolve = state->resolve_now; - fd_no = resolve->fd_no; + inode = inode_find(state->itable, resolve->gfid); - state->fd = gf_fd_fdptr_get (conn->fdtable, fd_no); + if (!inode) { + resolve->op_ret = -1; + resolve->op_errno = ENOENT; + ret = 1; + goto out; + } - if (!state->fd) { - resolve->op_ret = -1; - resolve->op_errno = EBADF; - } - - server_resolve_all (frame); + ret = 0; - return 0; + if (frame->root->op == GF_FOP_READ || frame->root->op == GF_FOP_WRITE) + state->fd = fd_anonymous_with_flags(inode, state->flags); + else + state->fd = fd_anonymous(inode); +out: + if (inode) + inode_unref(inode); + + if (ret != 0) + gf_msg_debug("server", 0, + "inode for the gfid" + "(%s) is not found. anonymous fd creation failed", + uuid_utoa(resolve->gfid)); + return ret; } - int -server_resolve (call_frame_t *frame) +server_resolve_anonfd(call_frame_t *frame) { - server_state_t *state = NULL; - server_resolve_t *resolve = NULL; + server_state_t *state = NULL; + int ret = 0; + loc_t *loc = NULL; - state = CALL_STATE (frame); - resolve = state->resolve_now; + state = CALL_STATE(frame); + loc = state->loc_now; - if (resolve->fd_no != -1) { + ret = resolve_anonfd_simple(frame); - server_resolve_fd (frame); + if (ret > 0) { + loc_wipe(loc); + resolve_gfid(frame); + return 0; + } - } else if (!uuid_is_null (resolve->pargfid)) { + server_resolve_all(frame); - server_resolve_entry (frame); + return 0; +} - } else if (!uuid_is_null (resolve->gfid)) { +int +server_resolve_fd(call_frame_t *frame) +{ + server_ctx_t *serv_ctx = NULL; + server_state_t *state = NULL; + client_t *client = NULL; + server_resolve_t *resolve = NULL; + uint64_t fd_no = -1; - server_resolve_inode (frame); + state = CALL_STATE(frame); + resolve = state->resolve_now; - } else if (resolve->path) { + fd_no = resolve->fd_no; - resolve_path_deep (frame); + if (fd_no == GF_ANON_FD_NO) { + server_resolve_anonfd(frame); + return 0; + } - } else { + client = frame->root->client; - resolve->op_ret = -1; - resolve->op_errno = EINVAL; + serv_ctx = server_ctx_get(client, client->this); - server_resolve_all (frame); + if (serv_ctx == NULL) { + gf_msg("", GF_LOG_INFO, ENOMEM, PS_MSG_NO_MEMORY, + "server_ctx_get() failed"); + resolve->op_ret = -1; + resolve->op_errno = ENOMEM; + return 0; + } + + /* + * With copy_file_range, there will be 2 fds to resolve. + * This same function is called to resolve both the source + * fd and the destination fd. As of now, this function does + * not have any mechanism to distinguish between the 2 fds + * being resolved except for checking the value of state->fd. + * The assumption is that, if source fd the one which is + * being resolved here, then state->fd would be NULL. If it + * is not NULL, then it is the destination fd which is being + * resolved. + * This method (provided the above assumption is true) is + * to achieve the ability to distinguish between 2 fds with + * minimum changes being done to this function. If this way + * is not correct, then more changes might be needed. + */ + if (!state->fd) { + state->fd = gf_fd_fdptr_get(serv_ctx->fdtable, fd_no); + if (!state->fd) { + gf_msg("", GF_LOG_INFO, EBADF, PS_MSG_FD_NOT_FOUND, + "fd not " + "found in context"); + resolve->op_ret = -1; + resolve->op_errno = EBADF; } + } else { + state->fd_out = gf_fd_fdptr_get(serv_ctx->fdtable, fd_no); + if (!state->fd_out) { + gf_msg("", GF_LOG_INFO, EBADF, PS_MSG_FD_NOT_FOUND, + "fd not " + "found in context"); + resolve->op_ret = -1; + resolve->op_errno = EBADF; + } + } - return 0; -} + server_resolve_all(frame); + return 0; +} int -server_resolve_done (call_frame_t *frame) +server_resolve(call_frame_t *frame) { - server_state_t *state = NULL; - xlator_t *bound_xl = NULL; + server_state_t *state = NULL; + server_resolve_t *resolve = NULL; - state = CALL_STATE (frame); - bound_xl = BOUND_XL (frame); + state = CALL_STATE(frame); + resolve = state->resolve_now; - server_print_request (frame); + if (resolve->fd_no != -1) { + server_resolve_fd(frame); - state->resume_fn (frame, bound_xl); + } else if (!gf_uuid_is_null(resolve->pargfid)) { + server_resolve_entry(frame); - return 0; + } else if (!gf_uuid_is_null(resolve->gfid)) { + server_resolve_inode(frame); + + } else { + if (resolve == &state->resolve) + gf_msg(frame->this->name, GF_LOG_WARNING, 0, PS_MSG_INVALID_ENTRY, + "no resolution type for %s (%s)", resolve->path, + gf_fop_list[frame->root->op]); + + resolve->op_ret = -1; + resolve->op_errno = EINVAL; + + server_resolve_all(frame); + } + + return 0; } +int +server_resolve_done(call_frame_t *frame) +{ + server_state_t *state = NULL; + + state = CALL_STATE(frame); + + server_print_request(frame); + + state->resume_fn(frame, frame->root->client->bound_xl); + + return 0; +} /* * This function is called multiple times, once per resolving one location/fd. * state->resolve_now is used to decide which location/fd is to be resolved now */ int -server_resolve_all (call_frame_t *frame) +server_resolve_all(call_frame_t *frame) { - server_state_t *state = NULL; - xlator_t *this = NULL; - - this = frame->this; - state = CALL_STATE (frame); + server_state_t *state = NULL; + xlator_t *this = NULL; - if (state->resolve_now == NULL) { + this = frame->this; + state = CALL_STATE(frame); - state->resolve_now = &state->resolve; - state->loc_now = &state->loc; + if (state->resolve_now == NULL) { + state->resolve_now = &state->resolve; + state->loc_now = &state->loc; - server_resolve (frame); + server_resolve(frame); - } else if (state->resolve_now == &state->resolve) { + } else if (state->resolve_now == &state->resolve) { + state->resolve_now = &state->resolve2; + state->loc_now = &state->loc2; - state->resolve_now = &state->resolve2; - state->loc_now = &state->loc2; + server_resolve(frame); - server_resolve (frame); + } else if (state->resolve_now == &state->resolve2) { + server_resolve_done(frame); - } else if (state->resolve_now == &state->resolve2) { + } else { + gf_msg(this->name, GF_LOG_ERROR, EINVAL, PS_MSG_INVALID_ENTRY, + "Invalid pointer for " + "state->resolve_now"); + } - server_resolve_done (frame); - - } else { - gf_log (this->name, GF_LOG_ERROR, - "Invalid pointer for state->resolve_now"); - } - - return 0; + return 0; } - int -resolve_and_resume (call_frame_t *frame, server_resume_fn_t fn) +resolve_and_resume(call_frame_t *frame, server_resume_fn_t fn) { - server_state_t *state = NULL; + server_state_t *state = NULL; - state = CALL_STATE (frame); - state->resume_fn = fn; + state = CALL_STATE(frame); + state->resume_fn = fn; - server_resolve_all (frame); + server_resolve_all(frame); - return 0; + return 0; } diff --git a/xlators/protocol/server/src/server-rpc-fops.c b/xlators/protocol/server/src/server-rpc-fops.c new file mode 100644 index 00000000000..4d8b7be5a34 --- /dev/null +++ b/xlators/protocol/server/src/server-rpc-fops.c @@ -0,0 +1,6084 @@ +/* + Copyright (c) 2010-2013 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 "glusterfs3-xdr.h" +#include "glusterfs3.h" +#include <glusterfs/compat-errno.h> +#include "server-messages.h" +#include <glusterfs/defaults.h> +#include <glusterfs/default-args.h> +#include "server-common.h" +#include <glusterfs/xlator.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) + +void +forget_inode_if_no_dentry(inode_t *inode) +{ + if (!inode) { + return; + } + + if (!inode_has_dentry(inode)) + inode_forget(inode, 0); + + return; +} + +void +set_resolve_gfid(client_t *client, uuid_t resolve_gfid, char *on_wire_gfid) +{ + if (client->subdir_mount && __is_root_gfid((unsigned char *)on_wire_gfid)) { + /* set the subdir_mount's gfid for proper resolution */ + gf_uuid_copy(resolve_gfid, client->subdir_gfid); + } else { + memcpy(resolve_gfid, on_wire_gfid, 16); + } +} + +/* Callback function section */ +int +server_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) +{ + gfs3_statfs_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) { + 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; + } + + server_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_gfs3_statfs_rsp); + + GF_FREE(rsp.xdata.xdata_val); + + return 0; +} + +int +server_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, + }; + gfs3_lookup_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, server_lookup_cbk, frame->root->client->bound_xl, + frame->root->client->bound_xl->fops->lookup, &fresh_loc, + state->xdata); + + loc_wipe(&fresh_loc); + return 0; + } + + gf_stat_from_iatt(&rsp.postparent, postparent); + + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, &rsp.xdata.xdata_val, + rsp.xdata.xdata_len, op_errno, out); + + 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 (at least gfid based + * lookups will be successful, if the lookup + * is a soft lookup) + */ + forget_inode_if_no_dentry(state->loc.inode); + } + } + goto out; + } + + server_post_lookup(&rsp, frame, state, inode, stbuf, postparent); +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_gfs3_lookup_rsp); + + GF_FREE(rsp.xdata.xdata_val); + + return 0; +} + +int +server_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) +{ + gfs3_lease_rsp rsp = { + 0, + }; + rpcsvc_request_t *req = NULL; + server_state_t *state = NULL; + + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, &rsp.xdata.xdata_val, + rsp.xdata.xdata_len, op_errno, out); + + 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; + } + server_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_gfs3_lease_rsp); + + GF_FREE(rsp.xdata.xdata_val); + + return 0; +} + +int +server_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) +{ + gfs3_lk_rsp rsp = { + 0, + }; + rpcsvc_request_t *req = NULL; + server_state_t *state = NULL; + + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, &rsp.xdata.xdata_val, + rsp.xdata.xdata_len, op_errno, out); + + 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; + } + + server_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_gfs3_lk_rsp); + + GF_FREE(rsp.xdata.xdata_val); + + return 0; +} + +int +server_inodelk_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata) +{ + gf_common_rsp rsp = { + 0, + }; + server_state_t *state = NULL; + rpcsvc_request_t *req = NULL; + + 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, 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_gf_common_rsp); + + GF_FREE(rsp.xdata.xdata_val); + + return 0; +} + +int +server_finodelk_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata) +{ + gf_common_rsp rsp = { + 0, + }; + server_state_t *state = NULL; + rpcsvc_request_t *req = NULL; + + 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, 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_gf_common_rsp); + + GF_FREE(rsp.xdata.xdata_val); + + return 0; +} + +int +server_entrylk_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata) +{ + gf_common_rsp rsp = { + 0, + }; + server_state_t *state = NULL; + rpcsvc_request_t *req = NULL; + + 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, 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_gf_common_rsp); + + GF_FREE(rsp.xdata.xdata_val); + + return 0; +} + +int +server_fentrylk_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata) +{ + gf_common_rsp rsp = { + 0, + }; + server_state_t *state = NULL; + rpcsvc_request_t *req = NULL; + + 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, 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_gf_common_rsp); + + GF_FREE(rsp.xdata.xdata_val); + + return 0; +} + +int +server_access_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata) +{ + gf_common_rsp rsp = { + 0, + }; + rpcsvc_request_t *req = NULL; + server_state_t *state = NULL; + + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, &rsp.xdata.xdata_val, + rsp.xdata.xdata_len, op_errno, out); + + 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_gf_common_rsp); + + GF_FREE(rsp.xdata.xdata_val); + + return 0; +} + +int +server_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) +{ + gfs3_rmdir_rsp rsp = { + 0, + }; + server_state_t *state = NULL; + rpcsvc_request_t *req = NULL; + + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, &rsp.xdata.xdata_val, + rsp.xdata.xdata_len, op_errno, out); + + 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; + } + + server_post_rmdir(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_gfs3_rmdir_rsp); + + GF_FREE(rsp.xdata.xdata_val); + + return 0; +} + +int +server_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) +{ + gfs3_mkdir_rsp rsp = { + 0, + }; + server_state_t *state = NULL; + rpcsvc_request_t *req = NULL; + + 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, 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; + } + + server_post_mkdir(state, &rsp, inode, stbuf, preparent, postparent, xdata); +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_gfs3_mkdir_rsp); + + GF_FREE(rsp.xdata.xdata_val); + + return 0; +} + +int +server_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) +{ + gfs3_mknod_rsp rsp = { + 0, + }; + server_state_t *state = NULL; + rpcsvc_request_t *req = NULL; + + 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, 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; + } + + server_post_mknod(state, &rsp, stbuf, preparent, postparent, inode); +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_gfs3_mknod_rsp); + + GF_FREE(rsp.xdata.xdata_val); + + return 0; +} + +int +server_fsyncdir_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata) +{ + gf_common_rsp rsp = { + 0, + }; + server_state_t *state = NULL; + 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) { + 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_gf_common_rsp); + + GF_FREE(rsp.xdata.xdata_val); + + return 0; +} + +int +server_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) +{ + gfs3_readdir_rsp rsp = { + 0, + }; + server_state_t *state = NULL; + rpcsvc_request_t *req = NULL; + int ret = 0; + + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, &rsp.xdata.xdata_val, + rsp.xdata.xdata_len, op_errno, out); + + 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 = server_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_gfs3_readdir_rsp); + + GF_FREE(rsp.xdata.xdata_val); + + readdir_rsp_cleanup(&rsp); + + return 0; +} + +int +server_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; + gfs3_opendir_rsp rsp = { + 0, + }; + uint64_t fd_no = 0; + + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, &rsp.xdata.xdata_val, + rsp.xdata.xdata_len, op_errno, out); + + 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 = server_post_opendir(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_gfs3_opendir_rsp); + + GF_FREE(rsp.xdata.xdata_val); + + return 0; +} + +int +server_removexattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata) +{ + gf_common_rsp rsp = { + 0, + }; + rpcsvc_request_t *req = NULL; + server_state_t *state = NULL; + gf_loglevel_t loglevel = GF_LOG_NONE; + + if (gf_replace_old_iatt_in_dict(xdata)) { + op_errno = errno; + op_ret = -1; + goto out; + } + + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, &rsp.xdata.xdata_val, + rsp.xdata.xdata_len, op_errno, out); + + 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_gf_common_rsp); + + GF_FREE(rsp.xdata.xdata_val); + + return 0; +} + +int +server_fremovexattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata) +{ + gf_common_rsp rsp = { + 0, + }; + rpcsvc_request_t *req = NULL; + server_state_t *state = NULL; + + if (gf_replace_old_iatt_in_dict(xdata)) { + op_errno = errno; + op_ret = -1; + goto out; + } + + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, &rsp.xdata.xdata_val, + rsp.xdata.xdata_len, op_errno, out); + + 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_gf_common_rsp); + + GF_FREE(rsp.xdata.xdata_val); + + return 0; +} + +int +server_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) +{ + gfs3_getxattr_rsp rsp = { + 0, + }; + rpcsvc_request_t *req = NULL; + server_state_t *state = NULL; + + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, &rsp.xdata.xdata_val, + rsp.xdata.xdata_len, op_errno, out); + + 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; + } + + GF_PROTOCOL_DICT_SERIALIZE(this, dict, &rsp.dict.dict_val, + rsp.dict.dict_len, op_errno, 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_gfs3_getxattr_rsp); + + GF_FREE(rsp.dict.dict_val); + + GF_FREE(rsp.xdata.xdata_val); + + return 0; +} + +int +server_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) +{ + gfs3_fgetxattr_rsp rsp = { + 0, + }; + server_state_t *state = NULL; + 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 == -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; + } + + GF_PROTOCOL_DICT_SERIALIZE(this, dict, &rsp.dict.dict_val, + rsp.dict.dict_len, op_errno, 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_gfs3_fgetxattr_rsp); + + GF_FREE(rsp.dict.dict_val); + + GF_FREE(rsp.xdata.xdata_val); + + return 0; +} + +/* print every key */ +int +_gf_server_log_setxattr_failure(dict_t *d, char *k, data_t *v, void *tmp) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + + frame = tmp; + state = CALL_STATE(frame); + + gf_msg(THIS->name, GF_LOG_INFO, 0, PS_MSG_SETXATTR_INFO, + "%" PRId64 + ": SETXATTR %s (%s) ==> %s, client: %s, " + "error-xlator: %s", + frame->root->unique, state->loc.path, uuid_utoa(state->resolve.gfid), + k, STACK_CLIENT_NAME(frame->root), STACK_ERR_XL_NAME(frame->root)); + return 0; +} + +int +server_setxattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata) +{ + gf_common_rsp rsp = { + 0, + }; + rpcsvc_request_t *req = NULL; + server_state_t *state = NULL; + + if (gf_replace_old_iatt_in_dict(xdata)) { + op_errno = errno; + op_ret = -1; + goto out; + } + + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, &rsp.xdata.xdata_val, + rsp.xdata.xdata_len, op_errno, out); + + 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_gf_common_rsp); + + GF_FREE(rsp.xdata.xdata_val); + + return 0; +} + +/* print every key here */ +static int +_gf_server_log_fsetxattr_failure(dict_t *d, char *k, data_t *v, void *tmp) +{ + call_frame_t *frame = NULL; + server_state_t *state = NULL; + + frame = tmp; + state = CALL_STATE(frame); + + gf_msg(THIS->name, GF_LOG_INFO, 0, PS_MSG_SETXATTR_INFO, + "%" PRId64 ": FSETXATTR %" PRId64 + " (%s) ==> %s, client: %s, " + "error-xlator: %s", + frame->root->unique, state->resolve.fd_no, + uuid_utoa(state->resolve.gfid), k, STACK_CLIENT_NAME(frame->root), + STACK_ERR_XL_NAME(frame->root)); + + return 0; +} + +int +server_fsetxattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata) +{ + gf_common_rsp rsp = { + 0, + }; + rpcsvc_request_t *req = NULL; + server_state_t *state = NULL; + + if (gf_replace_old_iatt_in_dict(xdata)) { + op_errno = errno; + op_ret = -1; + goto out; + } + + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, &rsp.xdata.xdata_val, + rsp.xdata.xdata_len, op_errno, out); + + if (op_ret == -1) { + state = CALL_STATE(frame); + if (op_errno != ENOTSUP) { + dict_foreach(state->dict, _gf_server_log_fsetxattr_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_gf_common_rsp); + + GF_FREE(rsp.xdata.xdata_val); + + return 0; +} + +int +server_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) +{ + gfs3_rename_rsp rsp = { + 0, + }; + server_state_t *state = NULL; + rpcsvc_request_t *req = NULL; + char oldpar_str[50] = { + 0, + }; + char newpar_str[50] = { + 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 == -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; + } + + server_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_gfs3_rename_rsp); + + GF_FREE(rsp.xdata.xdata_val); + + return 0; +} + +int +server_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) +{ + gfs3_unlink_rsp rsp = { + 0, + }; + server_state_t *state = NULL; + rpcsvc_request_t *req = NULL; + + if (gf_replace_old_iatt_in_dict(xdata)) { + op_errno = errno; + op_ret = -1; + goto out; + } + + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, &rsp.xdata.xdata_val, + rsp.xdata.xdata_len, op_errno, out); + + 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); + + server_post_unlink(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_gfs3_unlink_rsp); + + GF_FREE(rsp.xdata.xdata_val); + + return 0; +} + +int +server_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) +{ + gfs3_symlink_rsp rsp = { + 0, + }; + server_state_t *state = NULL; + rpcsvc_request_t *req = NULL; + + 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_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; + } + + server_post_symlink(state, &rsp, inode, stbuf, preparent, postparent, + xdata); + +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_gfs3_symlink_rsp); + + GF_FREE(rsp.xdata.xdata_val); + + return 0; +} + +int +server_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) +{ + gfs3_link_rsp rsp = { + 0, + }; + server_state_t *state = NULL; + rpcsvc_request_t *req = NULL; + char gfid_str[50] = { + 0, + }; + char newpar_str[50] = { + 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) { + 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; + } + + server_post_link(state, &rsp, inode, stbuf, preparent, postparent, xdata); + +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_gfs3_link_rsp); + + GF_FREE(rsp.xdata.xdata_val); + + return 0; +} + +int +server_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) +{ + gfs3_truncate_rsp rsp = { + 0, + }; + server_state_t *state = NULL; + 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) { + 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; + } + + server_post_truncate(&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_gfs3_truncate_rsp); + + GF_FREE(rsp.xdata.xdata_val); + + return 0; +} + +int +server_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) +{ + gfs3_fstat_rsp rsp = { + 0, + }; + server_state_t *state = NULL; + rpcsvc_request_t *req = NULL; + + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, &rsp.xdata.xdata_val, + rsp.xdata.xdata_len, op_errno, out); + + 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; + } + + server_post_fstat(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_gfs3_fstat_rsp); + + GF_FREE(rsp.xdata.xdata_val); + + return 0; +} + +int +server_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) +{ + gfs3_ftruncate_rsp rsp = {0}; + server_state_t *state = NULL; + 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) { + 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; + } + + server_post_ftruncate(&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_gfs3_ftruncate_rsp); + + GF_FREE(rsp.xdata.xdata_val); + + return 0; +} + +int +server_flush_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata) +{ + gf_common_rsp rsp = { + 0, + }; + server_state_t *state = NULL; + 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) { + 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_gf_common_rsp); + + GF_FREE(rsp.xdata.xdata_val); + + return 0; +} + +int +server_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) +{ + gfs3_fsync_rsp rsp = { + 0, + }; + server_state_t *state = NULL; + 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) { + 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; + } + + server_post_fsync(&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_gfs3_fsync_rsp); + + GF_FREE(rsp.xdata.xdata_val); + + return 0; +} + +int +server_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) +{ + gfs3_write_rsp rsp = { + 0, + }; + server_state_t *state = NULL; + 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) { + 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; + } + + server_post_writev(&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_gfs3_write_rsp); + + GF_FREE(rsp.xdata.xdata_val); + + return 0; +} + +int +server_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) +{ + gfs3_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 + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, &rsp.xdata.xdata_val, + rsp.xdata.xdata_len, op_errno, out); + + 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; + } + + server_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_gfs3_read_rsp); + + GF_FREE(rsp.xdata.xdata_val); + + return 0; +} + +int +server_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) +{ + gfs3_rchecksum_rsp rsp = { + 0, + }; + rpcsvc_request_t *req = NULL; + server_state_t *state = NULL; + + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, &rsp.xdata.xdata_val, + rsp.xdata.xdata_len, op_errno, out); + + 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; + } + + server_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_gfs3_rchecksum_rsp); + + GF_FREE(rsp.xdata.xdata_val); + + return 0; +} + +int +server_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; + gfs3_open_rsp rsp = { + 0, + }; + + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, &rsp.xdata.xdata_val, + rsp.xdata.xdata_len, op_errno, out); + + 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 = server_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_gfs3_open_rsp); + GF_FREE(rsp.xdata.xdata_val); + + return 0; +} + +int +server_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; + 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 + ": 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 = server_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_gfs3_create_rsp); + + GF_FREE(rsp.xdata.xdata_val); + + return 0; +} + +int +server_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) +{ + gfs3_readlink_rsp rsp = { + 0, + }; + server_state_t *state = NULL; + 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) { + 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; + } + + server_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_gfs3_readlink_rsp); + + GF_FREE(rsp.xdata.xdata_val); + + return 0; +} + +int +server_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) +{ + gfs3_stat_rsp rsp = { + 0, + }; + server_state_t *state = NULL; + rpcsvc_request_t *req = NULL; + + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, &rsp.xdata.xdata_val, + rsp.xdata.xdata_len, op_errno, out); + + 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; + } + + server_post_stat(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_gfs3_stat_rsp); + + GF_FREE(rsp.xdata.xdata_val); + + return 0; +} + +int +server_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) +{ + gfs3_setattr_rsp rsp = { + 0, + }; + server_state_t *state = NULL; + 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) { + 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; + } + + server_post_setattr(&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_gfs3_setattr_rsp); + + GF_FREE(rsp.xdata.xdata_val); + + return 0; +} + +int +server_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) +{ + gfs3_fsetattr_rsp rsp = { + 0, + }; + server_state_t *state = NULL; + 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) { + 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; + } + + server_post_fsetattr(&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_gfs3_fsetattr_rsp); + + GF_FREE(rsp.xdata.xdata_val); + + return 0; +} + +int +server_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) +{ + gfs3_xattrop_rsp rsp = { + 0, + }; + server_state_t *state = NULL; + 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) { + 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; + } + + GF_PROTOCOL_DICT_SERIALIZE(this, dict, &rsp.dict.dict_val, + rsp.dict.dict_len, op_errno, 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_gfs3_xattrop_rsp); + + GF_FREE(rsp.dict.dict_val); + + GF_FREE(rsp.xdata.xdata_val); + + return 0; +} + +int +server_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) +{ + gfs3_xattrop_rsp rsp = { + 0, + }; + server_state_t *state = NULL; + 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) { + 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; + } + + GF_PROTOCOL_DICT_SERIALIZE(this, dict, &rsp.dict.dict_val, + rsp.dict.dict_len, op_errno, 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_gfs3_fxattrop_rsp); + + GF_FREE(rsp.dict.dict_val); + + GF_FREE(rsp.xdata.xdata_val); + + return 0; +} + +int +server_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) +{ + gfs3_readdirp_rsp rsp = { + 0, + }; + server_state_t *state = NULL; + rpcsvc_request_t *req = NULL; + int ret = 0; + + state = CALL_STATE(frame); + + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, &rsp.xdata.xdata_val, + rsp.xdata.xdata_len, op_errno, out); + + 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 = server_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_gfs3_readdirp_rsp); + + GF_FREE(rsp.xdata.xdata_val); + + readdirp_rsp_cleanup(&rsp); + + return 0; +} + +int +server_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) +{ + gfs3_fallocate_rsp rsp = { + 0, + }; + server_state_t *state = NULL; + 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) { + 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; + } + + server_post_fallocate(&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_gfs3_fallocate_rsp); + + GF_FREE(rsp.xdata.xdata_val); + + return 0; +} + +int +server_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) +{ + gfs3_discard_rsp rsp = { + 0, + }; + server_state_t *state = NULL; + 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) { + 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; + } + + server_post_discard(&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_gfs3_discard_rsp); + + GF_FREE(rsp.xdata.xdata_val); + + return 0; +} + +int +server_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) +{ + gfs3_zerofill_rsp rsp = { + 0, + }; + server_state_t *state = NULL; + rpcsvc_request_t *req = NULL; + + req = frame->local; + state = CALL_STATE(frame); + + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, (&rsp.xdata.xdata_val), + rsp.xdata.xdata_len, op_errno, out); + + 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; + } + + server_post_zerofill(&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_gfs3_zerofill_rsp); + + GF_FREE(rsp.xdata.xdata_val); + + return 0; +} + +int +server_ipc_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata) +{ + gf_common_rsp rsp = { + 0, + }; + server_state_t *state = NULL; + rpcsvc_request_t *req = NULL; + + req = frame->local; + state = CALL_STATE(frame); + + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, (&rsp.xdata.xdata_val), + rsp.xdata.xdata_len, op_errno, out); + + 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_gf_common_rsp); + + GF_FREE(rsp.xdata.xdata_val); + + return 0; +} + +int +server_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 gfs3_seek_rsp rsp = { + 0, + }; + server_state_t *state = NULL; + rpcsvc_request_t *req = NULL; + + req = frame->local; + state = CALL_STATE(frame); + + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, (&rsp.xdata.xdata_val), + rsp.xdata.xdata_len, op_errno, out); + + 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; + } + + server_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_gfs3_seek_rsp); + + GF_FREE(rsp.xdata.xdata_val); + + return 0; +} + +static int +server_setactivelk_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata) +{ + gfs3_setactivelk_rsp rsp = { + 0, + }; + server_state_t *state = NULL; + rpcsvc_request_t *req = NULL; + + state = CALL_STATE(frame); + + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, &rsp.xdata.xdata_val, + rsp.xdata.xdata_len, op_errno, out); + + 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_gfs3_setactivelk_rsp); + + GF_FREE(rsp.xdata.xdata_val); + + return 0; +} + +/* Resume function section */ + +int +server_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, server_rchecksum_cbk, bound_xl, bound_xl->fops->rchecksum, + state->fd, state->offset, state->size, state->xdata); + + return 0; +err: + server_rchecksum_cbk(frame, NULL, frame->this, op_ret, op_errno, 0, NULL, + NULL); + + return 0; +} + +int +server_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, server_lease_cbk, bound_xl, bound_xl->fops->lease, + &state->loc, &state->lease, state->xdata); + + return 0; + +err: + server_lease_cbk(frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL, NULL); + return 0; +} + +int +server_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, server_lk_cbk, bound_xl, bound_xl->fops->lk, state->fd, + state->cmd, &state->flock, state->xdata); + + return 0; + +err: + server_lk_cbk(frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL, NULL); + return 0; +} + +int +server_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, server_rename_cbk, bound_xl, bound_xl->fops->rename, + &state->loc, &state->loc2, state->xdata); + return 0; +err: + server_rename_cbk(frame, NULL, frame->this, op_ret, op_errno, NULL, NULL, + NULL, NULL, NULL, NULL); + return 0; +} + +int +server_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, server_link_cbk, bound_xl, bound_xl->fops->link, + &state->loc, &state->loc2, state->xdata); + + return 0; +err: + server_link_cbk(frame, NULL, frame->this, op_ret, op_errno, NULL, NULL, + NULL, NULL, NULL); + return 0; +} + +int +server_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, server_symlink_cbk, bound_xl, bound_xl->fops->symlink, + state->name, &state->loc, state->umask, state->xdata); + + return 0; +err: + server_symlink_cbk(frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL, NULL, NULL, NULL, NULL); + return 0; +} + +int +server_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, server_access_cbk, bound_xl, bound_xl->fops->access, + &state->loc, state->mask, state->xdata); + return 0; +err: + server_access_cbk(frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL); + return 0; +} + +int +server_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, server_fentrylk_cbk, bound_xl, bound_xl->fops->fentrylk, + state->volume, state->fd, state->name, state->cmd, state->type, + state->xdata); + + return 0; +err: + server_fentrylk_cbk(frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL); + return 0; +} + +int +server_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, server_entrylk_cbk, bound_xl, bound_xl->fops->entrylk, + state->volume, &state->loc, state->name, state->cmd, state->type, + state->xdata); + return 0; +err: + server_entrylk_cbk(frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL); + return 0; +} + +int +server_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, server_finodelk_cbk, bound_xl, bound_xl->fops->finodelk, + state->volume, state->fd, state->cmd, &state->flock, + state->xdata); + + return 0; +err: + server_finodelk_cbk(frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL); + + return 0; +} + +int +server_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, server_inodelk_cbk, bound_xl, bound_xl->fops->inodelk, + state->volume, &state->loc, state->cmd, &state->flock, + state->xdata); + return 0; +err: + server_inodelk_cbk(frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL); + return 0; +} + +int +server_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, server_rmdir_cbk, bound_xl, bound_xl->fops->rmdir, + &state->loc, state->flags, state->xdata); + return 0; +err: + server_rmdir_cbk(frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL, NULL, NULL); + return 0; +} + +int +server_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, server_mkdir_cbk, bound_xl, bound_xl->fops->mkdir, + &(state->loc), state->mode, state->umask, state->xdata); + + return 0; +err: + server_mkdir_cbk(frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL, NULL, NULL, NULL, NULL); + return 0; +} + +int +server_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, server_mknod_cbk, bound_xl, bound_xl->fops->mknod, + &(state->loc), state->mode, state->dev, state->umask, + state->xdata); + + return 0; +err: + server_mknod_cbk(frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL, NULL, NULL, NULL, NULL); + return 0; +} + +int +server_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, server_fsyncdir_cbk, bound_xl, bound_xl->fops->fsyncdir, + state->fd, state->flags, state->xdata); + return 0; + +err: + server_fsyncdir_cbk(frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL); + return 0; +} + +int +server_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, server_readdir_cbk, bound_xl, bound_xl->fops->readdir, + state->fd, state->size, state->offset, state->xdata); + + return 0; +err: + server_readdir_cbk(frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL, NULL); + return 0; +} + +int +server_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, server_readdirp_cbk, bound_xl, bound_xl->fops->readdirp, + state->fd, state->size, state->offset, state->dict); + + return 0; +err: + server_readdirp_cbk(frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL, NULL); + return 0; +} + +int +server_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, server_opendir_cbk, bound_xl, bound_xl->fops->opendir, + &state->loc, state->fd, state->xdata); + return 0; +err: + server_opendir_cbk(frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL, NULL); + return 0; +} + +int +server_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, server_statfs_cbk, bound_xl, bound_xl->fops->statfs, + &state->loc, state->xdata); + return 0; + +err: + server_statfs_cbk(frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL, NULL); + return 0; +} + +int +server_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, server_removexattr_cbk, bound_xl, + bound_xl->fops->removexattr, &state->loc, state->name, + state->xdata); + return 0; +err: + server_removexattr_cbk(frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL); + return 0; +} + +int +server_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, server_fremovexattr_cbk, bound_xl, + bound_xl->fops->fremovexattr, state->fd, state->name, + state->xdata); + return 0; +err: + server_fremovexattr_cbk(frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL); + return 0; +} + +int +server_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, server_fgetxattr_cbk, bound_xl, bound_xl->fops->fgetxattr, + state->fd, state->name, state->xdata); + return 0; +err: + server_fgetxattr_cbk(frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL, NULL); + return 0; +} + +int +server_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, server_xattrop_cbk, bound_xl, bound_xl->fops->xattrop, + &state->loc, state->flags, state->dict, state->xdata); + return 0; +err: + server_xattrop_cbk(frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL, NULL); + return 0; +} + +int +server_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, server_fxattrop_cbk, bound_xl, bound_xl->fops->fxattrop, + state->fd, state->flags, state->dict, state->xdata); + return 0; +err: + server_fxattrop_cbk(frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL, NULL); + return 0; +} + +int +server_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, server_setxattr_cbk, bound_xl, bound_xl->fops->fsetxattr, + state->fd, state->dict, state->flags, state->xdata); + return 0; +err: + server_fsetxattr_cbk(frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL); + + return 0; +} + +int +server_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, server_unlink_cbk, bound_xl, bound_xl->fops->unlink, + &state->loc, state->flags, state->xdata); + return 0; +err: + server_unlink_cbk(frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL, NULL, NULL); + return 0; +} + +int +server_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, server_truncate_cbk, bound_xl, bound_xl->fops->truncate, + &state->loc, state->offset, state->xdata); + return 0; +err: + server_truncate_cbk(frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL, NULL, NULL); + return 0; +} + +int +server_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, server_fstat_cbk, bound_xl, bound_xl->fops->fstat, + state->fd, state->xdata); + return 0; +err: + server_fstat_cbk(frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL, NULL); + return 0; +} + +int +server_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, server_setxattr_cbk, bound_xl, bound_xl->fops->setxattr, + &state->loc, state->dict, state->flags, state->xdata); + return 0; +err: + server_setxattr_cbk(frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL); + + return 0; +} + +int +server_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, server_getxattr_cbk, bound_xl, bound_xl->fops->getxattr, + &state->loc, state->name, state->xdata); + return 0; +err: + server_getxattr_cbk(frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL, NULL); + return 0; +} + +int +server_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, server_ftruncate_cbk, bound_xl, bound_xl->fops->ftruncate, + state->fd, state->offset, state->xdata); + return 0; +err: + server_ftruncate_cbk(frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL, NULL, NULL); + + return 0; +} + +int +server_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, server_flush_cbk, bound_xl, bound_xl->fops->flush, + state->fd, state->xdata); + return 0; +err: + server_flush_cbk(frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL); + + return 0; +} + +int +server_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, server_fsync_cbk, bound_xl, bound_xl->fops->fsync, + state->fd, state->flags, state->xdata); + return 0; +err: + server_fsync_cbk(frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL, NULL, NULL); + + return 0; +} + +int +server_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, server_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: + server_writev_cbk(frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL, NULL, NULL); + return 0; +} + +int +server_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, server_readv_cbk, bound_xl, bound_xl->fops->readv, + state->fd, state->size, state->offset, state->flags, + state->xdata); + + return 0; +err: + server_readv_cbk(frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL, 0, NULL, NULL, NULL); + return 0; +} + +int +server_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, server_create_cbk, bound_xl, bound_xl->fops->create, + &(state->loc), state->flags, state->mode, state->umask, + state->fd, state->xdata); + + return 0; +err: + server_create_cbk(frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL, NULL, NULL, NULL, NULL, + NULL); + return 0; +} + +int +server_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, server_open_cbk, bound_xl, bound_xl->fops->open, + &state->loc, state->flags, state->fd, state->xdata); + + return 0; +err: + server_open_cbk(frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL, NULL); + return 0; +} + +int +server_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, server_readlink_cbk, bound_xl, bound_xl->fops->readlink, + &state->loc, state->size, state->xdata); + return 0; +err: + server_readlink_cbk(frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL, NULL, NULL); + return 0; +} + +int +server_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, server_fsetattr_cbk, bound_xl, bound_xl->fops->fsetattr, + state->fd, &state->stbuf, state->valid, state->xdata); + return 0; +err: + server_fsetattr_cbk(frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL, NULL, NULL); + + return 0; +} + +int +server_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, server_setattr_cbk, bound_xl, bound_xl->fops->setattr, + &state->loc, &state->stbuf, state->valid, state->xdata); + return 0; +err: + server_setattr_cbk(frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL, NULL, NULL); + + return 0; +} + +int +server_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, server_stat_cbk, bound_xl, bound_xl->fops->stat, + &state->loc, state->xdata); + return 0; +err: + server_stat_cbk(frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL, NULL); + return 0; +} + +int +server_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, server_lookup_cbk, bound_xl, bound_xl->fops->lookup, + &state->loc, state->xdata); + + return 0; +err: + server_lookup_cbk(frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL, NULL, NULL, NULL); + + return 0; +} + +int +server_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, server_fallocate_cbk, bound_xl, bound_xl->fops->fallocate, + state->fd, state->flags, state->offset, state->size, + state->xdata); + return 0; +err: + server_fallocate_cbk(frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL, NULL, NULL); + + return 0; +} + +int +server_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, server_discard_cbk, bound_xl, bound_xl->fops->discard, + state->fd, state->offset, state->size, state->xdata); + return 0; +err: + server_discard_cbk(frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL, NULL, NULL); + + return 0; +} + +int +server_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, server_zerofill_cbk, bound_xl, bound_xl->fops->zerofill, + state->fd, state->offset, state->size, state->xdata); + return 0; +err: + server_zerofill_cbk(frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL, NULL, NULL); + + return 0; +} + +int +server_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, server_seek_cbk, bound_xl, bound_xl->fops->seek, + state->fd, state->offset, state->what, state->xdata); + return 0; +err: + server_seek_cbk(frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, 0, NULL); + + return 0; +} + +static int +server_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) +{ + gfs3_getactivelk_rsp rsp = { + 0, + }; + server_state_t *state = NULL; + rpcsvc_request_t *req = NULL; + int ret = 0; + + state = CALL_STATE(frame); + + GF_PROTOCOL_DICT_SERIALIZE(this, xdata, &rsp.xdata.xdata_val, + rsp.xdata.xdata_len, op_errno, out); + + 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(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_gfs3_getactivelk_rsp); + + GF_FREE(rsp.xdata.xdata_val); + + getactivelkinfo_rsp_cleanup(&rsp); + + return 0; +} + +int +server_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, server_getactivelk_cbk, bound_xl, + bound_xl->fops->getactivelk, &state->loc, state->xdata); + return 0; +err: + server_getactivelk_cbk(frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL, NULL); + return 0; +} + +int +server_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, server_setactivelk_cbk, bound_xl, + bound_xl->fops->setactivelk, &state->loc, &state->locklist, + state->xdata); + return 0; +err: + server_setactivelk_cbk(frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL); + return 0; +} + +/* Fop section */ +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) +{ + int ret = -1; + ssize_t len = 0; + + len = xdr_to_generic(req->msg[0], args, (xdrproc_t)xdrfn); + if (len < 0) { + /* failed to decode msg; */ + SERVER_REQ_SET_ERROR(req, ret); + goto out; + } + + /* Few fops use the xdr size to get the vector sizes */ + if (xdrlen) + *xdrlen = len; + + *fr = get_frame_from_request(req); + if (!(*fr)) { + /* something wrong, mostly no memory */ + SERVER_REQ_SET_ERROR(req, ret); + goto out; + } + (*fr)->root->op = fop; + + *st = CALL_STATE((*fr)); + if (!(*fr)->root->client->bound_xl) { + /* auth failure, mostly setvolume is not successful */ + SERVER_REQ_SET_ERROR(req, ret); + goto out; + } + + if (!(*fr)->root->client->bound_xl->itable) { + /* inode_table is not allocated successful in server_setvolume */ + SERVER_REQ_SET_ERROR(req, ret); + goto out; + } + + ret = 0; + +out: + return ret; +} + +int +server3_3_stat(rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfs3_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_gfs3_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); + + 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_stat_resume); + +out: + free(args.xdata.xdata_val); + + if (op_errno) + SERVER_REQ_SET_ERROR(req, ret); + + return ret; +} + +int +server3_3_setattr(rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfs3_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_gfs3_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); + + 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_setattr_resume); + +out: + if (op_errno) + SERVER_REQ_SET_ERROR(req, ret); + + free(args.xdata.xdata_val); + + return ret; +} + +int +server3_3_fsetattr(rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfs3_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_gfs3_fsetattr_req, GF_FOP_FSETATTR); + if (ret != 0) { + goto out; + } + + state->resolve.type = RESOLVE_MUST; + state->resolve.fd_no = args.fd; + + 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 +server3_3_fallocate(rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfs3_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_gfs3_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); + + 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_fallocate_resume); + +out: + free(args.xdata.xdata_val); + + if (op_errno) + SERVER_REQ_SET_ERROR(req, ret); + + return ret; +} + +int +server3_3_discard(rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfs3_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_gfs3_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); + + 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_discard_resume); + +out: + free(args.xdata.xdata_val); + + if (op_errno) + SERVER_REQ_SET_ERROR(req, ret); + + return ret; +} + +int +server3_3_zerofill(rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfs3_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_gfs3_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); + + 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_zerofill_resume); + +out: + free(args.xdata.xdata_val); + + if (op_errno) + req->rpc_err = GARBAGE_ARGS; + + return ret; +} + +int +server3_3_ipc(rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfs3_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_gfs3_ipc_req, + GF_FOP_IPC); + if (ret != 0) { + goto out; + } + + bound_xl = frame->root->client->bound_xl; + GF_PROTOCOL_DICT_UNSERIALIZE(bound_xl, state->xdata, args.xdata.xdata_val, + args.xdata.xdata_len, ret, op_errno, out); + + ret = 0; + STACK_WIND(frame, server_ipc_cbk, bound_xl, bound_xl->fops->ipc, args.op, + state->xdata); + +out: + free(args.xdata.xdata_val); + + if (op_errno) + req->rpc_err = GARBAGE_ARGS; + + return ret; +} + +int +server3_3_seek(rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfs3_seek_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_gfs3_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); + + bound_xl = frame->root->client->bound_xl; + GF_PROTOCOL_DICT_UNSERIALIZE(bound_xl, state->xdata, args.xdata.xdata_val, + args.xdata.xdata_len, ret, op_errno, out); + + ret = 0; + resolve_and_resume(frame, server_seek_resume); + +out: + free(args.xdata.xdata_val); + + if (op_errno) + SERVER_REQ_SET_ERROR(req, ret); + + return ret; +} + +int +server3_3_readlink(rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfs3_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_gfs3_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; + + 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_readlink_resume); + +out: + free(args.xdata.xdata_val); + + if (op_errno) + SERVER_REQ_SET_ERROR(req, ret); + + return ret; +} + +int +server3_3_create(rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfs3_create_req args = { + { + 0, + }, + }; + int ret = -1; + int op_errno = 0; + + if (!req) + return ret; + + ret = rpc_receive_common(req, &frame, &state, NULL, &args, + xdr_gfs3_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; + } + + /* 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_create_resume); + +out: + /* memory allocated by libc, don't use GF_FREE */ + free(args.xdata.xdata_val); + free(args.bname); + + if (op_errno) + SERVER_REQ_SET_ERROR(req, ret); + + return ret; +} + +int +server3_3_open(rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfs3_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_gfs3_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); + + 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_open_resume); +out: + if (op_errno) + SERVER_REQ_SET_ERROR(req, ret); + + free(args.xdata.xdata_val); + + return ret; +} + +int +server3_3_readv(rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfs3_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_gfs3_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); + + 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_readv_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_writev(rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfs3_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_gfs3_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); + + GF_PROTOCOL_DICT_UNSERIALIZE(frame->root->client->bound_xl, state->xdata, + args.xdata.xdata_val, args.xdata.xdata_len, + ret, op_errno, out); + +#ifdef GF_TESTING_IO_XDATA + dict_dump_to_log(state->xdata); +#endif + + ret = 0; + resolve_and_resume(frame, server_writev_resume); +out: + free(args.xdata.xdata_val); + + if (op_errno) + SERVER_REQ_SET_ERROR(req, ret); + + return ret; +} + +#define SERVER3_3_VECWRITE_START 0 +#define SERVER3_3_VECWRITE_READING_HDR 1 +#define SERVER3_3_VECWRITE_READING_OPAQUE 2 + +int +server3_3_writev_vecsizer(int state, ssize_t *readsize, char *base_addr, + char *curr_addr) +{ + ssize_t size = 0; + int nextstate = 0; + gfs3_write_req write_req = { + { + 0, + }, + }; + XDR xdr; + + switch (state) { + case SERVER3_3_VECWRITE_START: + size = xdr_sizeof((xdrproc_t)xdr_gfs3_write_req, &write_req); + *readsize = size; + nextstate = SERVER3_3_VECWRITE_READING_HDR; + break; + case SERVER3_3_VECWRITE_READING_HDR: + size = xdr_sizeof((xdrproc_t)xdr_gfs3_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_gfs3_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 = gf_roof(write_req.xdata.xdata_len, 4); + + *readsize = size; + + if (!size) + nextstate = SERVER3_3_VECWRITE_START; + else + nextstate = SERVER3_3_VECWRITE_READING_OPAQUE; + + free(write_req.xdata.xdata_val); + + break; + + case SERVER3_3_VECWRITE_READING_OPAQUE: + *readsize = 0; + nextstate = SERVER3_3_VECWRITE_START; + break; + default: + gf_msg("server", GF_LOG_ERROR, 0, PS_MSG_WRONG_STATE, + "wrong state: %d", state); + } + + return nextstate; +} + +int +server3_3_release(rpcsvc_request_t *req) +{ + client_t *client = NULL; + server_ctx_t *serv_ctx = NULL; + gfs3_release_req args = { + { + 0, + }, + }; + gf_common_rsp rsp = { + 0, + }; + int ret = -1; + + ret = xdr_to_generic(req->msg[0], &args, (xdrproc_t)xdr_gfs3_release_req); + if (ret < 0) { + // failed to decode msg; + 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_gf_common_rsp); + + ret = 0; +out: + free(args.xdata.xdata_val); + return ret; +} + +int +server3_3_releasedir(rpcsvc_request_t *req) +{ + client_t *client = NULL; + server_ctx_t *serv_ctx = NULL; + gfs3_releasedir_req args = { + { + 0, + }, + }; + gf_common_rsp rsp = { + 0, + }; + int ret = -1; + + ret = xdr_to_generic(req->msg[0], &args, (xdrproc_t)xdr_gfs3_release_req); + if (ret < 0) { + // failed to decode msg; + 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_gf_common_rsp); + + ret = 0; +out: + free(args.xdata.xdata_val); + return ret; +} + +int +server3_3_fsync(rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfs3_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_gfs3_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); + + 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_fsync_resume); +out: + free(args.xdata.xdata_val); + + if (op_errno) + SERVER_REQ_SET_ERROR(req, ret); + + return ret; +} + +int +server3_3_flush(rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfs3_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_gfs3_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); + + 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_flush_resume); +out: + free(args.xdata.xdata_val); + + if (op_errno) + SERVER_REQ_SET_ERROR(req, ret); + + return ret; +} + +int +server3_3_ftruncate(rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfs3_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_gfs3_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); + + 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_ftruncate_resume); +out: + free(args.xdata.xdata_val); + + if (op_errno) + SERVER_REQ_SET_ERROR(req, ret); + + return ret; +} + +int +server3_3_fstat(rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfs3_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_gfs3_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); + + 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_fstat_resume); +out: + free(args.xdata.xdata_val); + + if (op_errno) + SERVER_REQ_SET_ERROR(req, ret); + + return ret; +} + +int +server3_3_truncate(rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfs3_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_gfs3_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; + + 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_truncate_resume); +out: + free(args.xdata.xdata_val); + + if (op_errno) + SERVER_REQ_SET_ERROR(req, ret); + + return ret; +} + +int +server3_3_unlink(rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfs3_unlink_req args = { + { + 0, + }, + }; + int ret = -1; + int op_errno = 0; + + if (!req) + return ret; + + ret = rpc_receive_common(req, &frame, &state, NULL, &args, + xdr_gfs3_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; + + 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_unlink_resume); +out: + free(args.xdata.xdata_val); + free(args.bname); + + if (op_errno) + SERVER_REQ_SET_ERROR(req, ret); + + return ret; +} + +int +server3_3_setxattr(rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + dict_t *dict = NULL; + call_frame_t *frame = NULL; + gfs3_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_gfs3_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); + + GF_PROTOCOL_DICT_UNSERIALIZE(frame->root->client->bound_xl, dict, + (args.dict.dict_val), (args.dict.dict_len), + ret, op_errno, out); + + state->dict = dict; + + /* There can be some commands hidden in key, check and proceed */ + gf_server_check_setxattr_cmd(frame, dict); + + 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_setxattr_resume); + + /* 'dict' will be destroyed later when 'state' is not needed anymore */ + dict = NULL; + +out: + free(args.xdata.xdata_val); + free(args.dict.dict_val); + + if (op_errno) + SERVER_REQ_SET_ERROR(req, ret); + + if (dict) + dict_unref(dict); + + return ret; +} + +int +server3_3_fsetxattr(rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + dict_t *dict = NULL; + call_frame_t *frame = NULL; + gfs3_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_gfs3_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); + + GF_PROTOCOL_DICT_UNSERIALIZE(frame->root->client->bound_xl, dict, + (args.dict.dict_val), (args.dict.dict_len), + ret, op_errno, out); + + state->dict = dict; + + 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_fsetxattr_resume); + + /* 'dict' will be destroyed later when 'state' is not needed anymore */ + dict = NULL; + +out: + free(args.xdata.xdata_val); + free(args.dict.dict_val); + + if (op_errno) + SERVER_REQ_SET_ERROR(req, ret); + + if (dict) + dict_unref(dict); + + return ret; +} + +int +server3_3_fxattrop(rpcsvc_request_t *req) +{ + dict_t *dict = NULL; + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfs3_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_gfs3_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); + + GF_PROTOCOL_DICT_UNSERIALIZE(frame->root->client->bound_xl, dict, + (args.dict.dict_val), (args.dict.dict_len), + ret, op_errno, out); + + state->dict = dict; + + 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_fxattrop_resume); + + /* 'dict' will be destroyed later when 'state' is not needed anymore */ + dict = NULL; + +out: + free(args.xdata.xdata_val); + free(args.dict.dict_val); + + if (op_errno) + SERVER_REQ_SET_ERROR(req, ret); + + if (dict) + dict_unref(dict); + + return ret; +} + +int +server3_3_xattrop(rpcsvc_request_t *req) +{ + dict_t *dict = NULL; + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfs3_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_gfs3_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); + + GF_PROTOCOL_DICT_UNSERIALIZE(frame->root->client->bound_xl, dict, + (args.dict.dict_val), (args.dict.dict_len), + ret, op_errno, out); + + state->dict = dict; + + 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_xattrop_resume); + + /* 'dict' will be destroyed later when 'state' is not needed anymore */ + dict = NULL; + +out: + free(args.xdata.xdata_val); + free(args.dict.dict_val); + + if (op_errno) + SERVER_REQ_SET_ERROR(req, ret); + + if (dict) + dict_unref(dict); + + return ret; +} + +int +server3_3_getxattr(rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfs3_getxattr_req args = { + { + 0, + }, + }; + int ret = -1; + int op_errno = 0; + + if (!req) + return ret; + + ret = rpc_receive_common(req, &frame, &state, NULL, &args, + xdr_gfs3_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); + } + + 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_getxattr_resume); +out: + free(args.xdata.xdata_val); + free(args.name); + + if (op_errno) + SERVER_REQ_SET_ERROR(req, ret); + + return ret; +} + +int +server3_3_fgetxattr(rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfs3_fgetxattr_req args = { + { + 0, + }, + }; + int ret = -1; + int op_errno = 0; + + if (!req) + return ret; + + ret = rpc_receive_common(req, &frame, &state, NULL, &args, + xdr_gfs3_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); + + 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_fgetxattr_resume); +out: + free(args.xdata.xdata_val); + free(args.name); + + if (op_errno) + SERVER_REQ_SET_ERROR(req, ret); + + return ret; +} + +int +server3_3_removexattr(rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfs3_removexattr_req args = { + { + 0, + }, + }; + int ret = -1; + int op_errno = 0; + + if (!req) + return ret; + + ret = rpc_receive_common(req, &frame, &state, NULL, &args, + xdr_gfs3_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); + + 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_removexattr_resume); +out: + free(args.xdata.xdata_val); + free(args.name); + + if (op_errno) + SERVER_REQ_SET_ERROR(req, ret); + + return ret; +} + +int +server3_3_fremovexattr(rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfs3_fremovexattr_req args = { + { + 0, + }, + }; + int ret = -1; + int op_errno = 0; + + if (!req) + return ret; + + ret = rpc_receive_common(req, &frame, &state, NULL, &args, + xdr_gfs3_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); + + 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_fremovexattr_resume); +out: + free(args.xdata.xdata_val); + free(args.name); + + if (op_errno) + SERVER_REQ_SET_ERROR(req, ret); + + return ret; +} + +int +server3_3_opendir(rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfs3_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_gfs3_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); + + 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_opendir_resume); +out: + free(args.xdata.xdata_val); + + if (op_errno) + SERVER_REQ_SET_ERROR(req, ret); + + return ret; +} + +int +server3_3_readdirp(rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfs3_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_gfs3_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(gfs3_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 */ + GF_PROTOCOL_DICT_UNSERIALIZE(frame->root->client->bound_xl, state->dict, + (args.dict.dict_val), (args.dict.dict_len), + ret, op_errno, out); + + ret = 0; + resolve_and_resume(frame, server_readdirp_resume); +out: + if (op_errno) + SERVER_REQ_SET_ERROR(req, ret); + + free(args.dict.dict_val); + + return ret; +} + +int +server3_3_readdir(rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfs3_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_gfs3_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(gfs3_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); + + 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_readdir_resume); +out: + free(args.xdata.xdata_val); + + if (op_errno) + SERVER_REQ_SET_ERROR(req, ret); + + return ret; +} + +int +server3_3_fsyncdir(rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfs3_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_gfs3_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); + + 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_fsyncdir_resume); +out: + free(args.xdata.xdata_val); + + if (op_errno) + SERVER_REQ_SET_ERROR(req, ret); + + return ret; +} + +int +server3_3_mknod(rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfs3_mknod_req args = { + { + 0, + }, + }; + int ret = -1; + int op_errno = 0; + + if (!req) + return ret; + + ret = rpc_receive_common(req, &frame, &state, NULL, &args, + xdr_gfs3_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; + + 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_mknod_resume); + +out: + if (op_errno) + SERVER_REQ_SET_ERROR(req, ret); + + /* memory allocated by libc, don't use GF_FREE */ + free(args.xdata.xdata_val); + free(args.bname); + + return ret; +} + +int +server3_3_mkdir(rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfs3_mkdir_req args = { + { + 0, + }, + }; + int ret = -1; + int op_errno = 0; + + if (!req) + return ret; + + ret = rpc_receive_common(req, &frame, &state, NULL, &args, + xdr_gfs3_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; + + /* 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_mkdir_resume); + +out: + if (op_errno) + SERVER_REQ_SET_ERROR(req, ret); + + free(args.xdata.xdata_val); + free(args.bname); + + return ret; +} + +int +server3_3_rmdir(rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfs3_rmdir_req args = { + { + 0, + }, + }; + int ret = -1; + int op_errno = 0; + + if (!req) + return ret; + + ret = rpc_receive_common(req, &frame, &state, NULL, &args, + xdr_gfs3_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; + + 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_rmdir_resume); +out: + free(args.xdata.xdata_val); + free(args.bname); + + if (op_errno) + SERVER_REQ_SET_ERROR(req, ret); + + return ret; +} + +int +server3_3_inodelk(rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfs3_inodelk_req args = { + { + 0, + }, + }; + int cmd = 0; + int ret = -1; + int op_errno = 0; + + if (!req) + return ret; + + ret = rpc_receive_common(req, &frame, &state, NULL, &args, + xdr_gfs3_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; + } + + 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_inodelk_resume); +out: + free(args.xdata.xdata_val); + free(args.volume); + + free(args.flock.lk_owner.lk_owner_val); + + if (op_errno) + SERVER_REQ_SET_ERROR(req, ret); + + return ret; +} + +int +server3_3_finodelk(rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfs3_finodelk_req args = { + { + 0, + }, + }; + int ret = -1; + int op_errno = 0; + + if (!req) + return ret; + + ret = rpc_receive_common(req, &frame, &state, NULL, &args, + xdr_gfs3_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; + } + + 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_finodelk_resume); +out: + free(args.xdata.xdata_val); + free(args.volume); + + free(args.flock.lk_owner.lk_owner_val); + + if (op_errno) + SERVER_REQ_SET_ERROR(req, ret); + + return ret; +} + +int +server3_3_entrylk(rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfs3_entrylk_req args = { + { + 0, + }, + }; + int ret = -1; + int op_errno = 0; + + if (!req) + return ret; + + ret = rpc_receive_common(req, &frame, &state, NULL, &args, + xdr_gfs3_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; + + 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_entrylk_resume); +out: + free(args.xdata.xdata_val); + free(args.volume); + free(args.name); + + if (op_errno) + SERVER_REQ_SET_ERROR(req, ret); + + return ret; +} + +int +server3_3_fentrylk(rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfs3_fentrylk_req args = { + { + 0, + }, + }; + int ret = -1; + int op_errno = 0; + + if (!req) + return ret; + + ret = rpc_receive_common(req, &frame, &state, NULL, &args, + xdr_gfs3_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); + + 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_fentrylk_resume); +out: + free(args.xdata.xdata_val); + free(args.volume); + free(args.name); + + if (op_errno) + SERVER_REQ_SET_ERROR(req, ret); + + return ret; +} + +int +server3_3_access(rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfs3_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_gfs3_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; + + 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_access_resume); +out: + free(args.xdata.xdata_val); + + if (op_errno) + SERVER_REQ_SET_ERROR(req, ret); + + return ret; +} + +int +server3_3_symlink(rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfs3_symlink_req args = { + { + 0, + }, + }; + int ret = -1; + int op_errno = 0; + + if (!req) + return ret; + + ret = rpc_receive_common(req, &frame, &state, NULL, &args, + xdr_gfs3_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; + + 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_symlink_resume); + +out: + if (op_errno) + SERVER_REQ_SET_ERROR(req, ret); + + /* memory allocated by libc, don't use GF_FREE */ + free(args.xdata.xdata_val); + free(args.linkname); + free(args.bname); + + return ret; +} + +int +server3_3_link(rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfs3_link_req args = { + { + 0, + }, + }; + int ret = -1; + int op_errno = 0; + + if (!req) + return ret; + + ret = rpc_receive_common(req, &frame, &state, NULL, &args, + xdr_gfs3_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); + + 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_link_resume); +out: + free(args.xdata.xdata_val); + free(args.newbname); + + if (op_errno) + SERVER_REQ_SET_ERROR(req, ret); + + return ret; +} + +int +server3_3_rename(rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfs3_rename_req args = { + { + 0, + }, + }; + int ret = -1; + int op_errno = 0; + + if (!req) + return ret; + + ret = rpc_receive_common(req, &frame, &state, NULL, &args, + xdr_gfs3_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); + + 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_rename_resume); +out: + free(args.xdata.xdata_val); + free(args.newbname); + free(args.oldbname); + + if (op_errno) + SERVER_REQ_SET_ERROR(req, ret); + + return ret; +} + +int +server3_3_lease(rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfs3_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_gfs3_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); + + 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_lease_resume); +out: + free(args.xdata.xdata_val); + + if (op_errno) + SERVER_REQ_SET_ERROR(req, ret); + + return ret; +} + +int +server3_3_lk(rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfs3_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_gfs3_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; + } + + 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_lk_resume); +out: + free(args.xdata.xdata_val); + + free(args.flock.lk_owner.lk_owner_val); + + if (op_errno) + SERVER_REQ_SET_ERROR(req, ret); + + return ret; +} + +int +server3_3_rchecksum(rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfs3_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_gfs3_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; + + 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; +} + +int +server_null(rpcsvc_request_t *req) +{ + gf_common_rsp rsp = { + 0, + }; + + /* Accepted */ + rsp.op_ret = 0; + + server_submit_reply(NULL, req, &rsp, NULL, 0, NULL, + (xdrproc_t)xdr_gf_common_rsp); + + return 0; +} + +int +server3_3_lookup(rpcsvc_request_t *req) +{ + call_frame_t *frame = NULL; + server_state_t *state = NULL; + gfs3_lookup_req args = { + { + 0, + }, + }; + int ret = -1; + + GF_VALIDATE_OR_GOTO("server", req, err); + + ret = rpc_receive_common(req, &frame, &state, NULL, &args, + xdr_gfs3_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); + } + + GF_PROTOCOL_DICT_UNSERIALIZE(frame->root->client->bound_xl, state->xdata, + args.xdata.xdata_val, args.xdata.xdata_len, + ret, ret, out); + + ret = 0; + resolve_and_resume(frame, server_lookup_resume); + + free(args.bname); + free(args.xdata.xdata_val); + + return ret; +out: + free(args.bname); + free(args.xdata.xdata_val); + + server_lookup_cbk(frame, NULL, frame->this, -1, EINVAL, NULL, NULL, NULL, + NULL); + ret = 0; + +err: + return ret; +} + +int +server3_3_statfs(rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfs3_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_gfs3_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); + + 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_statfs_resume); +out: + free(args.xdata.xdata_val); + + if (op_errno) + SERVER_REQ_SET_ERROR(req, ret); + + return ret; +} + +static int +server3_3_getactivelk(rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfs3_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_gfs3_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 */ + 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_getactivelk_resume); +out: + free(args.xdata.xdata_val); + + if (op_errno) + SERVER_REQ_SET_ERROR(req, ret); + + return ret; +} + +static int +server3_3_setactivelk(rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfs3_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_gfs3_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 */ + GF_PROTOCOL_DICT_UNSERIALIZE(frame->root->client->bound_xl, state->xdata, + (args.xdata.xdata_val), (args.xdata.xdata_len), + ret, op_errno, out); + + ret = unserialize_req_locklist(&args, &state->locklist); + if (ret) + goto out; + + ret = 0; + + resolve_and_resume(frame, server_setactivelk_resume); +out: + free(args.xdata.xdata_val); + + if (op_errno) + SERVER_REQ_SET_ERROR(req, ret); + + return ret; +} + +int +server3_3_compound(rpcsvc_request_t *req) +{ + int ret = -1; + SERVER_REQ_SET_ERROR(req, ret); + return ret; +} + +static rpcsvc_actor_t glusterfs3_3_fop_actors[GLUSTER_FOP_PROCCNT] = { + [GFS3_OP_NULL] = {"NULL", server_null, NULL, GFS3_OP_NULL, DRC_NA, 0}, + [GFS3_OP_STAT] = {"STAT", server3_3_stat, NULL, GFS3_OP_STAT, DRC_NA, 0}, + [GFS3_OP_READLINK] = {"READLINK", server3_3_readlink, NULL, + GFS3_OP_READLINK, DRC_NA, 0}, + [GFS3_OP_MKNOD] = {"MKNOD", server3_3_mknod, NULL, GFS3_OP_MKNOD, DRC_NA, + 0}, + [GFS3_OP_MKDIR] = {"MKDIR", server3_3_mkdir, NULL, GFS3_OP_MKDIR, DRC_NA, + 0}, + [GFS3_OP_UNLINK] = {"UNLINK", server3_3_unlink, NULL, GFS3_OP_UNLINK, + DRC_NA, 0}, + [GFS3_OP_RMDIR] = {"RMDIR", server3_3_rmdir, NULL, GFS3_OP_RMDIR, DRC_NA, + 0}, + [GFS3_OP_SYMLINK] = {"SYMLINK", server3_3_symlink, NULL, GFS3_OP_SYMLINK, + DRC_NA, 0}, + [GFS3_OP_RENAME] = {"RENAME", server3_3_rename, NULL, GFS3_OP_RENAME, + DRC_NA, 0}, + [GFS3_OP_LINK] = {"LINK", server3_3_link, NULL, GFS3_OP_LINK, DRC_NA, 0}, + [GFS3_OP_TRUNCATE] = {"TRUNCATE", server3_3_truncate, NULL, + GFS3_OP_TRUNCATE, DRC_NA, 0}, + [GFS3_OP_OPEN] = {"OPEN", server3_3_open, NULL, GFS3_OP_OPEN, DRC_NA, 0}, + [GFS3_OP_READ] = {"READ", server3_3_readv, NULL, GFS3_OP_READ, DRC_NA, 0}, + [GFS3_OP_WRITE] = {"WRITE", server3_3_writev, server3_3_writev_vecsizer, + GFS3_OP_WRITE, DRC_NA, 0}, + [GFS3_OP_STATFS] = {"STATFS", server3_3_statfs, NULL, GFS3_OP_STATFS, + DRC_NA, 0}, + [GFS3_OP_FLUSH] = {"FLUSH", server3_3_flush, NULL, GFS3_OP_FLUSH, DRC_NA, + 0}, + [GFS3_OP_FSYNC] = {"FSYNC", server3_3_fsync, NULL, GFS3_OP_FSYNC, DRC_NA, + 0}, + [GFS3_OP_SETXATTR] = {"SETXATTR", server3_3_setxattr, NULL, + GFS3_OP_SETXATTR, DRC_NA, 0}, + [GFS3_OP_GETXATTR] = {"GETXATTR", server3_3_getxattr, NULL, + GFS3_OP_GETXATTR, DRC_NA, 0}, + [GFS3_OP_REMOVEXATTR] = {"REMOVEXATTR", server3_3_removexattr, NULL, + GFS3_OP_REMOVEXATTR, DRC_NA, 0}, + [GFS3_OP_OPENDIR] = {"OPENDIR", server3_3_opendir, NULL, GFS3_OP_OPENDIR, + DRC_NA, 0}, + [GFS3_OP_FSYNCDIR] = {"FSYNCDIR", server3_3_fsyncdir, NULL, + GFS3_OP_FSYNCDIR, DRC_NA, 0}, + [GFS3_OP_ACCESS] = {"ACCESS", server3_3_access, NULL, DRC_NA, 0}, + [GFS3_OP_CREATE] = {"CREATE", server3_3_create, NULL, GFS3_OP_ACCESS, + DRC_NA, 0}, + [GFS3_OP_FTRUNCATE] = {"FTRUNCATE", server3_3_ftruncate, NULL, + GFS3_OP_FTRUNCATE, DRC_NA, 0}, + [GFS3_OP_FSTAT] = {"FSTAT", server3_3_fstat, NULL, GFS3_OP_FSTAT, DRC_NA, + 0}, + [GFS3_OP_LK] = {"LK", server3_3_lk, NULL, GFS3_OP_LK, DRC_NA, 0}, + [GFS3_OP_LOOKUP] = {"LOOKUP", server3_3_lookup, NULL, GFS3_OP_LOOKUP, + DRC_NA, 0}, + [GFS3_OP_READDIR] = {"READDIR", server3_3_readdir, NULL, GFS3_OP_READDIR, + DRC_NA, 0}, + [GFS3_OP_INODELK] = {"INODELK", server3_3_inodelk, NULL, GFS3_OP_INODELK, + DRC_NA, 0}, + [GFS3_OP_FINODELK] = {"FINODELK", server3_3_finodelk, NULL, + GFS3_OP_FINODELK, DRC_NA, 0}, + [GFS3_OP_ENTRYLK] = {"ENTRYLK", server3_3_entrylk, NULL, GFS3_OP_ENTRYLK, + DRC_NA, 0}, + [GFS3_OP_FENTRYLK] = {"FENTRYLK", server3_3_fentrylk, NULL, + GFS3_OP_FENTRYLK, DRC_NA, 0}, + [GFS3_OP_XATTROP] = {"XATTROP", server3_3_xattrop, NULL, GFS3_OP_XATTROP, + DRC_NA, 0}, + [GFS3_OP_FXATTROP] = {"FXATTROP", server3_3_fxattrop, NULL, + GFS3_OP_FXATTROP, DRC_NA, 0}, + [GFS3_OP_FGETXATTR] = {"FGETXATTR", server3_3_fgetxattr, NULL, + GFS3_OP_FGETXATTR, DRC_NA, 0}, + [GFS3_OP_FSETXATTR] = {"FSETXATTR", server3_3_fsetxattr, NULL, + GFS3_OP_FSETXATTR, DRC_NA, 0}, + [GFS3_OP_RCHECKSUM] = {"RCHECKSUM", server3_3_rchecksum, NULL, + GFS3_OP_RCHECKSUM, DRC_NA, 0}, + [GFS3_OP_SETATTR] = {"SETATTR", server3_3_setattr, NULL, GFS3_OP_SETATTR, + DRC_NA, 0}, + [GFS3_OP_FSETATTR] = {"FSETATTR", server3_3_fsetattr, NULL, + GFS3_OP_FSETATTR, DRC_NA, 0}, + [GFS3_OP_READDIRP] = {"READDIRP", server3_3_readdirp, NULL, + GFS3_OP_READDIRP, DRC_NA, 0}, + [GFS3_OP_RELEASE] = {"RELEASE", server3_3_release, NULL, GFS3_OP_RELEASE, + DRC_NA, 0}, + [GFS3_OP_RELEASEDIR] = + { + "RELEASEDIR", + server3_3_releasedir, + NULL, + GFS3_OP_RELEASEDIR, + DRC_NA, + 0, + }, + [GFS3_OP_FREMOVEXATTR] = {"FREMOVEXATTR", server3_3_fremovexattr, NULL, + GFS3_OP_FREMOVEXATTR, DRC_NA, 0}, + [GFS3_OP_FALLOCATE] = {"FALLOCATE", server3_3_fallocate, NULL, + GFS3_OP_FALLOCATE, DRC_NA, 0}, + [GFS3_OP_DISCARD] = {"DISCARD", server3_3_discard, NULL, GFS3_OP_DISCARD, + DRC_NA, 0}, + [GFS3_OP_ZEROFILL] = {"ZEROFILL", server3_3_zerofill, NULL, + GFS3_OP_ZEROFILL, DRC_NA, 0}, + [GFS3_OP_IPC] = {"IPC", server3_3_ipc, NULL, GFS3_OP_IPC, DRC_NA, 0}, + [GFS3_OP_SEEK] = {"SEEK", server3_3_seek, NULL, GFS3_OP_SEEK, DRC_NA, 0}, + [GFS3_OP_LEASE] = {"LEASE", server3_3_lease, NULL, GFS3_OP_LEASE, DRC_NA, + 0}, + [GFS3_OP_GETACTIVELK] = {"GETACTIVELK", server3_3_getactivelk, NULL, + GFS3_OP_GETACTIVELK, DRC_NA, 0}, + [GFS3_OP_SETACTIVELK] = {"SETACTIVELK", server3_3_setactivelk, NULL, + GFS3_OP_SETACTIVELK, DRC_NA, 0}, + [GFS3_OP_COMPOUND] = {"COMPOUND", server3_3_compound, NULL, + GFS3_OP_COMPOUND, DRC_NA, 0}, +}; + +struct rpcsvc_program glusterfs3_3_fop_prog = { + .progname = "GlusterFS 3.3", + .prognum = GLUSTER_FOP_PROGRAM, + .progver = GLUSTER_FOP_VERSION, + .numactors = GLUSTER_FOP_PROCCNT, + .actors = glusterfs3_3_fop_actors, + .ownthread = _gf_true, +}; 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..c267f8f7832 --- /dev/null +++ b/xlators/protocol/server/src/server-rpc-fops_v2.c @@ -0,0 +1,6031 @@ +/* + 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 <glusterfs/compat-errno.h> +#include "server-messages.h" +#include <glusterfs/defaults.h> +#include <glusterfs/default-args.h> +#include "server-common.h" +#include <glusterfs/xlator.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 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_smsg(this->name, GF_LOG_WARNING, op_errno, PS_MSG_STATFS, + "frame=%" PRId64, frame->root->unique, "client=%s", + STACK_CLIENT_NAME(frame->root), "error-xlator=%s", + STACK_ERR_XL_NAME(frame->root), NULL); + 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 (at least 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_smsg(this->name, fop_log_level(GF_FOP_LOOKUP, op_errno), + op_errno, PS_MSG_LOOKUP_INFO, "frame=%" PRId64, + frame->root->unique, "path=%s", state->loc.path, + "uuid_utoa=%s", uuid_utoa(state->resolve.pargfid), + "bname=%s", state->resolve.bname, "client=%s", + STACK_CLIENT_NAME(frame->root), "error-xlator=%s", + STACK_ERR_XL_NAME(frame->root), NULL); + } else { + gf_smsg(this->name, fop_log_level(GF_FOP_LOOKUP, op_errno), + op_errno, PS_MSG_LOOKUP_INFO, "frame=%" PRId64, + frame->root->unique, "path=%s", state->loc.path, + "uuid_utoa=%s", uuid_utoa(state->resolve.gfid), "client=%s", + STACK_CLIENT_NAME(frame->root), "error-xlator=%s", + STACK_ERR_XL_NAME(frame->root), NULL); + } + } + + 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_smsg(this->name, fop_log_level(GF_FOP_LEASE, op_errno), op_errno, + PS_MSG_LK_INFO, "frame=%" PRId64, frame->root->unique, + "path=%s", state->loc.path, "uuid_utoa=%s", + uuid_utoa(state->resolve.gfid), "client=%s", + STACK_CLIENT_NAME(frame->root), "error-xlator=%s", + STACK_ERR_XL_NAME(frame->root), NULL); + } + server4_post_lease(&rsp, lease); + + 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_smsg(this->name, fop_log_level(GF_FOP_LK, op_errno), op_errno, + PS_MSG_LK_INFO, "frame=%" PRId64, frame->root->unique, + "fd_no=%" PRId64, state->resolve.fd_no, "uuid_utoa=%s", + uuid_utoa(state->resolve.gfid), "client=%s", + STACK_CLIENT_NAME(frame->root), "error-xlator=%s", + STACK_ERR_XL_NAME(frame->root), NULL); + 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_smsg(this->name, fop_log_level(GF_FOP_INODELK, op_errno), op_errno, + PS_MSG_INODELK_INFO, "frame=%" PRId64, frame->root->unique, + "path=%s", state->loc.path, "uuuid_utoa=%s", + uuid_utoa(state->resolve.gfid), "client=%s", + STACK_CLIENT_NAME(frame->root), "error-xlator=%s", + STACK_ERR_XL_NAME(frame->root), NULL); + 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_smsg(this->name, fop_log_level(GF_FOP_FINODELK, op_errno), op_errno, + PS_MSG_INODELK_INFO, "frame=%" PRId64, frame->root->unique, + "FINODELK_fd_no=%" PRId64, state->resolve.fd_no, "uuid_utoa=%s", + uuid_utoa(state->resolve.gfid), "client=%s", + STACK_CLIENT_NAME(frame->root), "error-xlator=%s", + STACK_ERR_XL_NAME(frame->root), NULL); + 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_smsg(this->name, fop_log_level(GF_FOP_ENTRYLK, op_errno), op_errno, + PS_MSG_ENTRYLK_INFO, "frame=%" PRId64, frame->root->unique, + "path=%s", state->loc.path, "uuid_utoa=%s", + uuid_utoa(state->resolve.gfid), "client=%s", + STACK_CLIENT_NAME(frame->root), "error-xlator=%s", + STACK_ERR_XL_NAME(frame->root), NULL); + 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_smsg(this->name, fop_log_level(GF_FOP_FENTRYLK, op_errno), op_errno, + PS_MSG_ENTRYLK_INFO, "frame=%" PRId64, frame->root->unique, + "FENTRYLK_fd_no=%" PRId64, state->resolve.fd_no, "uuid_utoa=%s", + uuid_utoa(state->resolve.gfid), "client=%s", + STACK_CLIENT_NAME(frame->root), "error-xlator: %s", + STACK_ERR_XL_NAME(frame->root), NULL); + 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_smsg(this->name, GF_LOG_INFO, op_errno, PS_MSG_ACCESS_INFO, + "frame=%" PRId64, frame->root->unique, "path=%s", + (state->loc.path) ? state->loc.path : "", "uuid_utoa=%s", + uuid_utoa(state->resolve.gfid), "client=%s", + STACK_CLIENT_NAME(frame->root), "error-xlator=%s", + STACK_ERR_XL_NAME(frame->root), NULL); + 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_smsg(this->name, GF_LOG_INFO, op_errno, PS_MSG_DIR_INFO, + "frame=%" PRId64, frame->root->unique, "RMDIR_pat=%s", + (state->loc.path) ? state->loc.path : "", "uuid_utoa=%s", + uuid_utoa(state->resolve.pargfid), "bname=%s", + state->resolve.bname, "client=%s", + STACK_CLIENT_NAME(frame->root), "error-xlator=%s", + STACK_ERR_XL_NAME(frame->root), NULL); + 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_smsg(this->name, fop_log_level(GF_FOP_MKDIR, op_errno), op_errno, + PS_MSG_DIR_INFO, "frame=%" PRId64, frame->root->unique, + "MKDIR_path=%s", (state->loc.path) ? state->loc.path : "", + "uuid_utoa=%s", uuid_utoa(state->resolve.pargfid), "bname=%s", + state->resolve.bname, "client=%s", + STACK_CLIENT_NAME(frame->root), "error-xlator=%s", + STACK_ERR_XL_NAME(frame->root), NULL); + 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_smsg(this->name, fop_log_level(GF_FOP_MKNOD, op_errno), op_errno, + PS_MSG_MKNOD_INFO, "frame=%" PRId64, frame->root->unique, + "path=%s", state->loc.path, "uuid_utoa=%s", + uuid_utoa(state->resolve.pargfid), "bname=%s", + state->resolve.bname, "client=%s", + STACK_CLIENT_NAME(frame->root), "error-xlator=%s", + STACK_ERR_XL_NAME(frame->root), NULL); + 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_smsg(this->name, fop_log_level(GF_FOP_FSYNCDIR, op_errno), op_errno, + PS_MSG_DIR_INFO, "frame=%" PRId64, frame->root->unique, + "FSYNCDIR_fd_no=%" PRId64, state->resolve.fd_no, "uuid_utoa=%s", + uuid_utoa(state->resolve.gfid), "client=%s", + STACK_CLIENT_NAME(frame->root), "error-xlator=%s", + STACK_ERR_XL_NAME(frame->root), NULL); + 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_smsg(this->name, fop_log_level(GF_FOP_READDIR, op_errno), op_errno, + PS_MSG_DIR_INFO, "frame=%" PRId64, frame->root->unique, + "READDIR_fd_no=%" PRId64, state->resolve.fd_no, "uuid_utoa=%s", + uuid_utoa(state->resolve.gfid), "client=%s", + STACK_CLIENT_NAME(frame->root), "error-xlator=%s", + STACK_ERR_XL_NAME(frame->root), NULL); + 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_smsg(this->name, fop_log_level(GF_FOP_OPENDIR, op_errno), op_errno, + PS_MSG_DIR_INFO, "frame=%" PRId64, frame->root->unique, + "OPENDIR_path=%s", (state->loc.path) ? state->loc.path : "", + "uuid_utoa=%s", uuid_utoa(state->resolve.gfid), "client=%s", + STACK_CLIENT_NAME(frame->root), "error-xlator=%s", + STACK_ERR_XL_NAME(frame->root), NULL); + 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_smsg(this->name, loglevel, op_errno, PS_MSG_REMOVEXATTR_INFO, + "frame=%" PRId64, frame->root->unique, "path=%s", + state->loc.path, "uuid_utoa=%s", uuid_utoa(state->resolve.gfid), + "name=%s", state->name, "client=%s", + STACK_CLIENT_NAME(frame->root), "error-xlator=%s", + STACK_ERR_XL_NAME(frame->root), NULL); + 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_smsg(this->name, fop_log_level(GF_FOP_FREMOVEXATTR, op_errno), + op_errno, PS_MSG_REMOVEXATTR_INFO, "frame=%" PRId64, + frame->root->unique, "FREMOVEXATTR_fd_no%" PRId64, + state->resolve.fd_no, "uuid_utoa=%s", + uuid_utoa(state->resolve.gfid), "name=%s", state->name, + "client=%s", STACK_CLIENT_NAME(frame->root), "error-xlator: %s", + STACK_ERR_XL_NAME(frame->root), NULL); + 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_smsg(this->name, fop_log_level(GF_FOP_GETXATTR, op_errno), op_errno, + PS_MSG_GETXATTR_INFO, "frame=%" PRId64, frame->root->unique, + "path=%s", state->loc.path, "uuid_utoa=%s", + uuid_utoa(state->resolve.gfid), "name=%s", state->name, + "client=%s", STACK_CLIENT_NAME(frame->root), "error-xlator=%s", + STACK_ERR_XL_NAME(frame->root), NULL); + 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_smsg(this->name, fop_log_level(GF_FOP_FGETXATTR, op_errno), op_errno, + PS_MSG_GETXATTR_INFO, "frame=%" PRId64, frame->root->unique, + "FGETXATTR_fd_no=%" PRId64, state->resolve.fd_no, + "uuid_utoa=%s", uuid_utoa(state->resolve.gfid), "name=%s", + state->name, "client=%s", STACK_CLIENT_NAME(frame->root), + "error-xlator=%s", STACK_ERR_XL_NAME(frame->root), NULL); + 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_smsg(THIS->name, GF_LOG_INFO, op_errno, PS_MSG_SETXATTR_INFO, + "client=%s", STACK_CLIENT_NAME(frame->root), + "error-xlator=%s", STACK_ERR_XL_NAME(frame->root), NULL); + } + 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_smsg(THIS->name, GF_LOG_INFO, op_errno, PS_MSG_SETXATTR_INFO, + "client=%s", STACK_CLIENT_NAME(frame->root), + "error-xlator=%s", STACK_ERR_XL_NAME(frame->root), NULL); + } + 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_smsg(this->name, GF_LOG_INFO, op_errno, PS_MSG_RENAME_INFO, + "frame=%" PRId64, frame->root->unique, "loc.path=%s", + state->loc.path, "oldpar_str=%s", oldpar_str, "resolve-name=%s", + state->resolve.bname, "loc2.path=%s", state->loc2.path, + "newpar_str=%s", newpar_str, "resolve2=%s", + state->resolve2.bname, "client=%s", + STACK_CLIENT_NAME(frame->root), "error-xlator=%s", + STACK_ERR_XL_NAME(frame->root), NULL); + 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_smsg(this->name, fop_log_level(GF_FOP_UNLINK, op_errno), op_errno, + PS_MSG_LINK_INFO, "frame=%" PRId64, frame->root->unique, + "UNLINK_path=%s", state->loc.path, "uuid_utoa=%s", + uuid_utoa(state->resolve.pargfid), "bname=%s", + state->resolve.bname, "client=%s", + STACK_CLIENT_NAME(frame->root), "error-xlator: %s", + STACK_ERR_XL_NAME(frame->root), NULL); + 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_smsg(this->name, GF_LOG_INFO, op_errno, PS_MSG_LINK_INFO, + "frame=%" PRId64, frame->root->unique, "SYMLINK_path= %s", + (state->loc.path) ? state->loc.path : "", "uuid_utoa=%s", + uuid_utoa(state->resolve.pargfid), "bname=%s", + state->resolve.bname, "client=%s", + STACK_CLIENT_NAME(frame->root), "error-xlator=%s", + STACK_ERR_XL_NAME(frame->root), NULL); + 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_smsg(this->name, GF_LOG_INFO, op_errno, PS_MSG_LINK_INFO, + "frame=%" PRId64, frame->root->unique, "LINK_path=%s", + state->loc.path, "gfid_str=%s", gfid_str, "newpar_str=%s", + newpar_str, "resolve2.bname=%s", state->resolve2.bname, + "client=%s", STACK_CLIENT_NAME(frame->root), "error-xlator=%s", + STACK_ERR_XL_NAME(frame->root), NULL); + 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_smsg(this->name, GF_LOG_INFO, op_errno, PS_MSG_TRUNCATE_INFO, + "frame=%" PRId64, frame->root->unique, "TRUNCATE_path=%s", + state->loc.path, "uuid_utoa=%s", uuid_utoa(state->resolve.gfid), + "client=%s", STACK_CLIENT_NAME(frame->root), "error-xlator=%s", + STACK_ERR_XL_NAME(frame->root), NULL); + 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_smsg(this->name, fop_log_level(GF_FOP_FSTAT, op_errno), op_errno, + PS_MSG_STAT_INFO, "frame=%" PRId64, frame->root->unique, + "FSTAT_fd_no=%" PRId64, state->resolve.fd_no, "uuid_utoa=%s", + uuid_utoa(state->resolve.gfid), "client=%s", + STACK_CLIENT_NAME(frame->root), "error-xlator=%s", + STACK_ERR_XL_NAME(frame->root), NULL); + 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_smsg(this->name, fop_log_level(GF_FOP_FTRUNCATE, op_errno), op_errno, + PS_MSG_TRUNCATE_INFO, "frame=%" PRId64, frame->root->unique, + "FTRUNCATE_fd_no=%" PRId64, state->resolve.fd_no, + "uuid_utoa=%s", uuid_utoa(state->resolve.gfid), "client=%s", + STACK_CLIENT_NAME(frame->root), "error-xlator=%s", + STACK_ERR_XL_NAME(frame->root), NULL); + 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_smsg(this->name, fop_log_level(GF_FOP_FLUSH, op_errno), op_errno, + PS_MSG_FLUSH_INFO, "frame=%" PRId64, frame->root->unique, + "FLUSH_fd_no=%" PRId64, state->resolve.fd_no, "uuid_utoa=%s", + uuid_utoa(state->resolve.gfid), "client=%s", + STACK_CLIENT_NAME(frame->root), "error-xlator: %s", + STACK_ERR_XL_NAME(frame->root), NULL); + 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_smsg(this->name, fop_log_level(GF_FOP_FSYNC, op_errno), op_errno, + PS_MSG_SYNC_INFO, "frame=%" PRId64, frame->root->unique, + "FSYNC_fd_no=%" PRId64, state->resolve.fd_no, "uuid_utoa=%s", + uuid_utoa(state->resolve.gfid), "client=%s", + STACK_CLIENT_NAME(frame->root), "error-xlator: %s", + STACK_ERR_XL_NAME(frame->root), NULL); + 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_smsg(this->name, fop_log_level(GF_FOP_WRITE, op_errno), op_errno, + PS_MSG_WRITE_INFO, "frame=%" PRId64, frame->root->unique, + "WRITEV_fd_no=%" PRId64, state->resolve.fd_no, "uuid_utoa=%s", + uuid_utoa(state->resolve.gfid), "client=%s", + STACK_CLIENT_NAME(frame->root), "error-xlator=%s", + STACK_ERR_XL_NAME(frame->root), NULL); + 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_smsg(this->name, fop_log_level(GF_FOP_READ, op_errno), op_errno, + PS_MSG_READ_INFO, "frame=%" PRId64, frame->root->unique, + "READV_fd_no=%" PRId64, state->resolve.fd_no, "uuid_utoa=%s", + uuid_utoa(state->resolve.gfid), "client=%s", + STACK_CLIENT_NAME(frame->root), "error-xlator=%s", + STACK_ERR_XL_NAME(frame->root), NULL); + 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_smsg(this->name, fop_log_level(GF_FOP_RCHECKSUM, op_errno), op_errno, + PS_MSG_CHKSUM_INFO, "frame=%" PRId64, frame->root->unique, + "RCHECKSUM_fd_no=%" PRId64, state->resolve.fd_no, + "uuid_utoa=%s", uuid_utoa(state->resolve.gfid), "client=%s", + STACK_CLIENT_NAME(frame->root), "error-xlator=%s", + STACK_ERR_XL_NAME(frame->root), NULL); + 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_smsg(this->name, fop_log_level(GF_FOP_OPEN, op_errno), op_errno, + PS_MSG_OPEN_INFO, "frame=%" PRId64, frame->root->unique, + "OPEN_path=%s", state->loc.path, "uuid_utoa=%s", + uuid_utoa(state->resolve.gfid), "client=%s", + STACK_CLIENT_NAME(frame->root), "error-xlator=%s", + STACK_ERR_XL_NAME(frame->root), NULL); + 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_smsg( + this->name, GF_LOG_INFO, op_errno, PS_MSG_CREATE_INFO, + "frame=%" PRId64, frame->root->unique, "path=%s", state->loc.path, + "uuid_utoa=%s", uuid_utoa(state->resolve.pargfid), "bname=%s", + state->resolve.bname, "client=%s", STACK_CLIENT_NAME(frame->root), + "error-xlator=%s", STACK_ERR_XL_NAME(frame->root), NULL); + 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_smsg(this->name, GF_LOG_INFO, op_errno, PS_MSG_LINK_INFO, + "frame=%" PRId64, frame->root->unique, "READLINK_path=%s", + state->loc.path, "uuid_utoa=%s", uuid_utoa(state->resolve.gfid), + "client=%s", STACK_CLIENT_NAME(frame->root), "error-xlator=%s", + STACK_ERR_XL_NAME(frame->root), NULL); + 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_smsg(this->name, fop_log_level(GF_FOP_STAT, op_errno), op_errno, + PS_MSG_STAT_INFO, "frame=%" PRId64, frame->root->unique, + "path=%s", (state->loc.path) ? state->loc.path : "", + "uuid_utoa=%s", uuid_utoa(state->resolve.gfid), "client=%s", + STACK_CLIENT_NAME(frame->root), "error-xlator=%s", + STACK_ERR_XL_NAME(frame->root), NULL); + 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_smsg(this->name, GF_LOG_INFO, op_errno, PS_MSG_SETATTR_INFO, + "frame=%" PRId64, frame->root->unique, "path=%s", + (state->loc.path) ? state->loc.path : "", "uuid_utoa=%s", + uuid_utoa(state->resolve.gfid), "client=%s", + STACK_CLIENT_NAME(frame->root), "error-xlator=%s", + STACK_ERR_XL_NAME(frame->root), NULL); + 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_smsg(this->name, fop_log_level(GF_FOP_FSETATTR, op_errno), op_errno, + PS_MSG_SETATTR_INFO, "frame=%" PRId64, + "FSETATTR_fd_no=%" PRId64, state->resolve.fd_no, "uuid_utoa=%s", + uuid_utoa(state->resolve.gfid), "client=%s", + STACK_CLIENT_NAME(frame->root), "error-xlator=%s", + STACK_ERR_XL_NAME(frame->root), NULL); + 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_smsg(this->name, fop_log_level(GF_FOP_XATTROP, op_errno), op_errno, + PS_MSG_XATTROP_INFO, "frame=%" PRId64, frame->root->unique, + "path=%s", state->loc.path, "uuid_utoa=%s", + uuid_utoa(state->resolve.gfid), "client=%s", + STACK_CLIENT_NAME(frame->root), "error-xlator=%s", + STACK_ERR_XL_NAME(frame->root), NULL); + 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_smsg(this->name, fop_log_level(GF_FOP_FXATTROP, op_errno), op_errno, + PS_MSG_XATTROP_INFO, "frame=%" PRId64, frame->root->unique, + "FXATTROP_fd_no=%" PRId64, state->resolve.fd_no, "uuid_utoa=%s", + uuid_utoa(state->resolve.gfid), "client=%s", + STACK_CLIENT_NAME(frame->root), "error-xlator=%s", + STACK_ERR_XL_NAME(frame->root), NULL); + 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_smsg(this->name, fop_log_level(GF_FOP_READDIRP, op_errno), op_errno, + PS_MSG_DIR_INFO, "frame=%" PRId64, frame->root->unique, + "READDIRP_fd_no=%" PRId64, state->resolve.fd_no, "uuid_utoa=%s", + uuid_utoa(state->resolve.gfid), "client=%s", + STACK_CLIENT_NAME(frame->root), "error-xlator=%s", + STACK_ERR_XL_NAME(frame->root), NULL); + 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_smsg(this->name, fop_log_level(GF_FOP_FALLOCATE, op_errno), op_errno, + PS_MSG_ALLOC_INFO, "frame=%" PRId64, frame->root->unique, + "FALLOCATE_fd_no=%" PRId64, state->resolve.fd_no, + "uuid_utoa=%s", uuid_utoa(state->resolve.gfid), "client=%s", + STACK_CLIENT_NAME(frame->root), "error-xlator=%s", + STACK_ERR_XL_NAME(frame->root), NULL); + 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_smsg(this->name, fop_log_level(GF_FOP_DISCARD, op_errno), op_errno, + PS_MSG_DISCARD_INFO, "frame=%" PRId64, frame->root->unique, + "fd_no=%" PRId64, state->resolve.fd_no, "uuid_utoa=%s", + uuid_utoa(state->resolve.gfid), "client=%s", + STACK_CLIENT_NAME(frame->root), "error-xlator: %s", + STACK_ERR_XL_NAME(frame->root), NULL); + 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_smsg(this->name, fop_log_level(GF_FOP_ZEROFILL, op_errno), op_errno, + PS_MSG_ZEROFILL_INFO, "frame=%" PRId64, frame->root->unique, + "fd_no=%" PRId64, state->resolve.fd_no, "uuid_utoa=%s", + uuid_utoa(state->resolve.gfid), "client=%s", + STACK_CLIENT_NAME(frame->root), "error-xlator=%s", + STACK_ERR_XL_NAME(frame->root), NULL); + 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_smsg(this->name, GF_LOG_INFO, op_errno, PS_MSG_SERVER_IPC_INFO, + "frame=%" PRId64, frame->root->unique, "IPC=%" PRId64, + state->resolve.fd_no, "uuid_utoa=%s", + uuid_utoa(state->resolve.gfid), "client=%s", + STACK_CLIENT_NAME(frame->root), "error-xlator=%s", + STACK_ERR_XL_NAME(frame->root), NULL); + 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_smsg(this->name, fop_log_level(GF_FOP_SEEK, op_errno), op_errno, + PS_MSG_SEEK_INFO, "frame=%" PRId64, frame->root->unique, + "fd_no=%" PRId64, state->resolve.fd_no, "uuid_utoa=%s", + uuid_utoa(state->resolve.gfid), "client=%s", + STACK_CLIENT_NAME(frame->root), "error-xlator=%s", + STACK_ERR_XL_NAME(frame->root), NULL); + 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_smsg(this->name, GF_LOG_INFO, op_errno, PS_MSG_SETACTIVELK_INFO, + "frame=%" PRId64, frame->root->unique, "path==%s", + state->loc.path, "uuid_utoa=%s", uuid_utoa(state->resolve.gfid), + "client=%s", STACK_CLIENT_NAME(frame->root), "error-xlator=%s", + STACK_ERR_XL_NAME(frame->root), NULL); + 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_smsg(this->name, GF_LOG_INFO, op_errno, PS_MSG_CREATE_INFO, + "frame=%" PRId64, uuid_utoa(state->resolve.gfid), + "ICREATE_gfid=%s", uuid_utoa(state->resolve.gfid), + "op_errno=%s", strerror(op_errno), NULL); + 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; +} + +int +server4_put_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) +{ + server_state_t *state = NULL; + rpcsvc_request_t *req = NULL; + gfx_common_3iatt_rsp rsp = { + 0, + }; + + dict_to_xdr(xdata, &rsp.xdata); + + state = CALL_STATE(frame); + + if (op_ret < 0) { + gf_smsg( + this->name, GF_LOG_INFO, op_errno, PS_MSG_PUT_INFO, + "frame=%" PRId64, frame->root->unique, "path=%s", state->loc.path, + "uuid_utoa=%s", uuid_utoa(state->resolve.pargfid), "bname=%s", + state->resolve.bname, "client=%s", STACK_CLIENT_NAME(frame->root), + "error-xlator=%s", STACK_ERR_XL_NAME(frame->root), NULL); + goto out; + } + + gf_msg_trace(frame->root->client->bound_xl->name, 0, + "%" PRId64 + ": " + "PUT %s (%s)", + frame->root->unique, state->loc.name, + uuid_utoa(stbuf->ia_gfid)); + + 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_copy_file_range_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, + struct iatt *stbuf, struct iatt *prebuf_dst, + struct iatt *postbuf_dst, dict_t *xdata) +{ + gfx_common_3iatt_rsp rsp = { + 0, + }; + server_state_t *state = NULL; + rpcsvc_request_t *req = NULL; + char in_gfid[GF_UUID_BUF_SIZE] = {0}; + char out_gfid[GF_UUID_BUF_SIZE] = {0}; + + dict_to_xdr(xdata, &rsp.xdata); + + if (op_ret < 0) { + state = CALL_STATE(frame); + + uuid_utoa_r(state->resolve.gfid, in_gfid); + uuid_utoa_r(state->resolve2.gfid, out_gfid); + + gf_smsg(this->name, fop_log_level(GF_FOP_COPY_FILE_RANGE, op_errno), + op_errno, PS_MSG_WRITE_INFO, "frame=%" PRId64, + frame->root->unique, "COPY_FILE_RANGE_fd_no=%" PRId64, + state->resolve.fd_no, "in_gfid=%s", in_gfid, + "resolve2_fd_no=%" PRId64, state->resolve2.fd_no, "out_gfid=%s", + out_gfid, "client=%s", STACK_CLIENT_NAME(frame->root), + "error-xlator=%s", STACK_ERR_XL_NAME(frame->root), NULL); + goto out; + } + + /* + * server4_post_common_3iatt (ex: used by server4_put_cbk and some + * other cbks) also performs inode linking along with copying of 3 + * iatt structures to the response. But, for copy_file_range, linking + * of inode is not needed. Therefore a new function is used to + * construct the response using 3 iatt structures. + * @stbuf: iatt or stat of the source file (or fd) + * @prebuf_dst: iatt or stat of destination file (or fd) before the fop + * @postbuf_dst: iatt or stat of destination file (or fd) after the fop + */ + server4_post_common_3iatt_noinode(&rsp, stbuf, prebuf_dst, postbuf_dst); + +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; +} + +/* 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_put_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_put_cbk, bound_xl, bound_xl->fops->put, + &(state->loc), state->mode, state->umask, state->flags, + state->payload_vector, state->payload_count, state->offset, + state->iobref, state->dict, state->xdata); + + return 0; +err: + server4_put_cbk(frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL, NULL, NULL, 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_smsg("server", GF_LOG_ERROR, 0, PS_MSG_FD_CREATE_FAILED, NULL); + 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_smsg("server", GF_LOG_ERROR, 0, PS_MSG_FD_CREATE_FAILED, "inode=%s", + state->loc.inode ? uuid_utoa(state->loc.inode->gfid) : NULL, + 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_smsg(this->name, GF_LOG_INFO, op_errno, PS_MSG_GETACTIVELK_INFO, + "frame=%" PRId64, frame->root->unique, "path=%s", + state->loc.path, "gfid=%s", uuid_utoa(state->resolve.gfid), + "client=%s", STACK_CLIENT_NAME(frame->root), "error-xlator=%s", + STACK_ERR_XL_NAME(frame->root), NULL); + + 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_copy_file_range_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_copy_file_range_cbk, bound_xl, + bound_xl->fops->copy_file_range, state->fd, state->off_in, + state->fd_out, state->off_out, state->size, state->flags, + state->xdata); + + return 0; +err: + server4_copy_file_range_cbk(frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL, 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; + + 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); + + if (xdr_to_dict(&args.xdata, &state->xdata)) { + SERVER_REQ_SET_ERROR(req, ret); + goto out; + } + + ret = 0; + resolve_and_resume(frame, server4_stat_resume); + +out: + + 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; + + 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; + + if (xdr_to_dict(&args.xdata, &state->xdata)) { + SERVER_REQ_SET_ERROR(req, ret); + goto out; + } + + ret = 0; + resolve_and_resume(frame, server4_setattr_resume); + +out: + + 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; + + 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); + + if (xdr_to_dict(&args.xdata, &state->xdata)) { + SERVER_REQ_SET_ERROR(req, ret); + goto out; + } + + ret = 0; + resolve_and_resume(frame, server4_fallocate_resume); + +out: + + 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; + + 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); + + if (xdr_to_dict(&args.xdata, &state->xdata)) { + SERVER_REQ_SET_ERROR(req, ret); + goto out; + } + + ret = 0; + resolve_and_resume(frame, server4_discard_resume); + +out: + + 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) { + op_errno = -1; + 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); + + if (xdr_to_dict(&args.xdata, &state->xdata)) { + SERVER_REQ_SET_ERROR(req, ret); + goto out; + } + 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; + 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; + if (xdr_to_dict(&args.xdata, &state->xdata)) { + SERVER_REQ_SET_ERROR(req, ret); + goto out; + } + ret = 0; + STACK_WIND(frame, server4_ipc_cbk, bound_xl, bound_xl->fops->ipc, args.op, + state->xdata); + +out: + + 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; + + 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); + + if (xdr_to_dict(&args.xdata, &state->xdata)) { + SERVER_REQ_SET_ERROR(req, ret); + goto out; + } + + ret = 0; + resolve_and_resume(frame, server4_seek_resume); + +out: + 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; + + 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; + + if (xdr_to_dict(&args.xdata, &state->xdata)) { + SERVER_REQ_SET_ERROR(req, ret); + goto out; + } + + ret = 0; + resolve_and_resume(frame, server4_readlink_resume); + +out: + + 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; + + if (!req) + return ret; + + 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; + } + + if (xdr_to_dict(&args.xdata, &state->xdata)) { + SERVER_REQ_SET_ERROR(req, ret); + goto out; + } + + ret = 0; + resolve_and_resume(frame, server4_create_resume); + +out: + free(args.bname); + + 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; + + 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); + + if (xdr_to_dict(&args.xdata, &state->xdata)) { + SERVER_REQ_SET_ERROR(req, ret); + goto out; + } + + ret = 0; + resolve_and_resume(frame, server4_open_resume); +out: + 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; + + 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); + + if (xdr_to_dict(&args.xdata, &state->xdata)) { + SERVER_REQ_SET_ERROR(req, ret); + goto out; + } + + ret = 0; + resolve_and_resume(frame, server4_readv_resume); +out: + 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; + + 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); + + if (xdr_to_dict(&args.xdata, &state->xdata)) { + SERVER_REQ_SET_ERROR(req, ret); + goto out; + } + +#ifdef GF_TESTING_IO_XDATA + dict_dump_to_log(state->xdata); +#endif + + ret = 0; + resolve_and_resume(frame, server4_writev_resume); +out: + + 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 = gf_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_smsg(req->trans->name, GF_LOG_INFO, 0, PS_MSG_SERVER_CTX_GET_FAILED, + NULL); + 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_smsg(req->trans->name, GF_LOG_INFO, 0, PS_MSG_SERVER_CTX_GET_FAILED, + NULL); + 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; + + 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); + + if (xdr_to_dict(&args.xdata, &state->xdata)) { + SERVER_REQ_SET_ERROR(req, ret); + goto out; + } + + ret = 0; + resolve_and_resume(frame, server4_fsync_resume); +out: + + 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; + + 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); + + if (xdr_to_dict(&args.xdata, &state->xdata)) { + SERVER_REQ_SET_ERROR(req, ret); + goto out; + } + + ret = 0; + resolve_and_resume(frame, server4_flush_resume); +out: + + 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; + + 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); + + if (xdr_to_dict(&args.xdata, &state->xdata)) { + SERVER_REQ_SET_ERROR(req, ret); + goto out; + } + + ret = 0; + resolve_and_resume(frame, server4_ftruncate_resume); +out: + + 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; + + 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); + + if (xdr_to_dict(&args.xdata, &state->xdata)) { + SERVER_REQ_SET_ERROR(req, ret); + goto out; + } + + ret = 0; + resolve_and_resume(frame, server4_fstat_resume); +out: + + 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; + + 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; + + if (xdr_to_dict(&args.xdata, &state->xdata)) { + SERVER_REQ_SET_ERROR(req, ret); + goto out; + } + + ret = 0; + resolve_and_resume(frame, server4_truncate_resume); +out: + + 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; + + if (!req) + return ret; + + 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; + + if (xdr_to_dict(&args.xdata, &state->xdata)) { + SERVER_REQ_SET_ERROR(req, ret); + goto out; + } + + ret = 0; + resolve_and_resume(frame, server4_unlink_resume); +out: + free(args.bname); + + 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; + + 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); + + if (xdr_to_dict(&args.dict, &state->dict)) { + SERVER_REQ_SET_ERROR(req, ret); + goto out; + } + + /* There can be some commands hidden in key, check and proceed */ + gf_server_check_setxattr_cmd(frame, state->dict); + + if (xdr_to_dict(&args.xdata, &state->xdata)) { + SERVER_REQ_SET_ERROR(req, ret); + goto out; + } + + ret = 0; + resolve_and_resume(frame, server4_setxattr_resume); + +out: + 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; + + 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); + + if (xdr_to_dict(&args.dict, &state->dict)) { + SERVER_REQ_SET_ERROR(req, ret); + goto out; + } + + if (xdr_to_dict(&args.xdata, &state->xdata)) { + SERVER_REQ_SET_ERROR(req, ret); + goto out; + } + + ret = 0; + resolve_and_resume(frame, server4_fsetxattr_resume); + +out: + 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; + + 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); + + if (xdr_to_dict(&args.dict, &state->dict)) { + SERVER_REQ_SET_ERROR(req, ret); + goto out; + } + + if (xdr_to_dict(&args.xdata, &state->xdata)) { + SERVER_REQ_SET_ERROR(req, ret); + goto out; + } + + ret = 0; + resolve_and_resume(frame, server4_fxattrop_resume); + +out: + 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; + + 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); + + if (xdr_to_dict(&args.dict, &state->dict)) { + SERVER_REQ_SET_ERROR(req, ret); + goto out; + } + + if (xdr_to_dict(&args.xdata, &state->xdata)) { + SERVER_REQ_SET_ERROR(req, ret); + goto out; + } + + ret = 0; + resolve_and_resume(frame, server4_xattrop_resume); + +out: + 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; + + if (!req) + return ret; + + 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); + } + + if (xdr_to_dict(&args.xdata, &state->xdata)) { + SERVER_REQ_SET_ERROR(req, ret); + goto out; + } + + ret = 0; + resolve_and_resume(frame, server4_getxattr_resume); +out: + free(args.name); + + 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; + + if (!req) + return ret; + + 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); + + if (xdr_to_dict(&args.xdata, &state->xdata)) { + SERVER_REQ_SET_ERROR(req, ret); + goto out; + } + + ret = 0; + resolve_and_resume(frame, server4_fgetxattr_resume); +out: + free(args.name); + + 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; + + if (!req) + return ret; + + 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); + + if (xdr_to_dict(&args.xdata, &state->xdata)) { + SERVER_REQ_SET_ERROR(req, ret); + goto out; + } + + ret = 0; + resolve_and_resume(frame, server4_removexattr_resume); +out: + free(args.name); + + 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; + + if (!req) + return ret; + + 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); + + if (xdr_to_dict(&args.xdata, &state->xdata)) { + SERVER_REQ_SET_ERROR(req, ret); + goto out; + } + + ret = 0; + resolve_and_resume(frame, server4_fremovexattr_resume); +out: + free(args.name); + + 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; + + 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); + + if (xdr_to_dict(&args.xdata, &state->xdata)) { + SERVER_REQ_SET_ERROR(req, ret); + goto out; + } + + ret = 0; + resolve_and_resume(frame, server4_opendir_resume); +out: + + 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; + + 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 */ + if (xdr_to_dict(&args.xdata, &state->xdata)) { + SERVER_REQ_SET_ERROR(req, ret); + goto out; + } + + ret = 0; + resolve_and_resume(frame, server4_readdirp_resume); +out: + 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; + + 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); + + if (xdr_to_dict(&args.xdata, &state->xdata)) { + SERVER_REQ_SET_ERROR(req, ret); + goto out; + } + + ret = 0; + resolve_and_resume(frame, server4_readdir_resume); +out: + + 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; + + 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); + + if (xdr_to_dict(&args.xdata, &state->xdata)) { + SERVER_REQ_SET_ERROR(req, ret); + goto out; + } + + ret = 0; + resolve_and_resume(frame, server4_fsyncdir_resume); +out: + + 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; + + if (!req) + return ret; + + 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; + + if (xdr_to_dict(&args.xdata, &state->xdata)) { + SERVER_REQ_SET_ERROR(req, ret); + goto out; + } + + ret = 0; + resolve_and_resume(frame, server4_mknod_resume); + +out: + free(args.bname); + + 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; + + if (!req) + return ret; + + 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; + + if (xdr_to_dict(&args.xdata, &state->xdata)) { + SERVER_REQ_SET_ERROR(req, ret); + goto out; + } + + ret = 0; + resolve_and_resume(frame, server4_mkdir_resume); + +out: + free(args.bname); + + 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; + + if (!req) + return ret; + + 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; + + if (xdr_to_dict(&args.xdata, &state->xdata)) { + SERVER_REQ_SET_ERROR(req, ret); + goto out; + } + + ret = 0; + resolve_and_resume(frame, server4_rmdir_resume); +out: + free(args.bname); + + 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; + + if (!req) + return ret; + + 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; + } + + if (xdr_to_dict(&args.xdata, &state->xdata)) { + SERVER_REQ_SET_ERROR(req, ret); + goto out; + } + + ret = 0; + resolve_and_resume(frame, server4_inodelk_resume); +out: + free(args.volume); + + free(args.flock.lk_owner.lk_owner_val); + + 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; + + if (!req) + return ret; + + 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; + } + + if (xdr_to_dict(&args.xdata, &state->xdata)) { + SERVER_REQ_SET_ERROR(req, ret); + goto out; + } + + ret = 0; + resolve_and_resume(frame, server4_finodelk_resume); +out: + free(args.volume); + + free(args.flock.lk_owner.lk_owner_val); + + 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; + + if (!req) + return ret; + + 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; + + if (xdr_to_dict(&args.xdata, &state->xdata)) { + SERVER_REQ_SET_ERROR(req, ret); + goto out; + } + + ret = 0; + resolve_and_resume(frame, server4_entrylk_resume); +out: + free(args.volume); + free(args.name); + + 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; + + if (!req) + return ret; + + 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); + + if (xdr_to_dict(&args.xdata, &state->xdata)) { + SERVER_REQ_SET_ERROR(req, ret); + goto out; + } + + ret = 0; + resolve_and_resume(frame, server4_fentrylk_resume); +out: + free(args.volume); + free(args.name); + + 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; + + 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; + + if (xdr_to_dict(&args.xdata, &state->xdata)) { + SERVER_REQ_SET_ERROR(req, ret); + goto out; + } + + ret = 0; + resolve_and_resume(frame, server4_access_resume); +out: + + 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; + + if (!req) + return ret; + + 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; + + if (xdr_to_dict(&args.xdata, &state->xdata)) { + SERVER_REQ_SET_ERROR(req, ret); + goto out; + } + + ret = 0; + resolve_and_resume(frame, server4_symlink_resume); + +out: + free(args.bname); + free(args.linkname); + + 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; + + if (!req) + return ret; + + 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); + + if (xdr_to_dict(&args.xdata, &state->xdata)) { + SERVER_REQ_SET_ERROR(req, ret); + goto out; + } + + ret = 0; + resolve_and_resume(frame, server4_link_resume); +out: + free(args.newbname); + + 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; + + if (!req) + return ret; + + 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); + + if (xdr_to_dict(&args.xdata, &state->xdata)) { + SERVER_REQ_SET_ERROR(req, ret); + goto out; + } + + ret = 0; + resolve_and_resume(frame, server4_rename_resume); +out: + free(args.oldbname); + free(args.newbname); + + 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; + + 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); + + if (xdr_to_dict(&args.xdata, &state->xdata)) { + SERVER_REQ_SET_ERROR(req, ret); + goto out; + } + + ret = 0; + resolve_and_resume(frame, server4_lease_resume); +out: + + 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; + + 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_smsg(frame->root->client->bound_xl->name, GF_LOG_ERROR, 0, + PS_MSG_LOCK_ERROR, "fd=%" PRId64, state->resolve.fd_no, + "uuid_utoa=%s", uuid_utoa(state->fd->inode->gfid), + "lock type=" PRId32, state->type, NULL); + break; + } + + if (xdr_to_dict(&args.xdata, &state->xdata)) { + SERVER_REQ_SET_ERROR(req, ret); + goto out; + } + + ret = 0; + resolve_and_resume(frame, server4_lk_resume); +out: + + free(args.flock.lk_owner.lk_owner_val); + + 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); + + 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); + } + + if (xdr_to_dict(&args.xdata, &state->xdata)) { + SERVER_REQ_SET_ERROR(req, ret); + goto err; + } + + ret = 0; + resolve_and_resume(frame, server4_lookup_resume); + +err: + free(args.bname); + + 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; + + 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); + + if (xdr_to_dict(&args.xdata, &state->xdata)) { + SERVER_REQ_SET_ERROR(req, ret); + goto out; + } + + ret = 0; + resolve_and_resume(frame, server4_statfs_resume); +out: + + 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; + + 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 */ + if (xdr_to_dict(&args.xdata, &state->xdata)) { + SERVER_REQ_SET_ERROR(req, ret); + goto out; + } + + ret = 0; + resolve_and_resume(frame, server4_getactivelk_resume); +out: + + 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; + + 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 */ + if (xdr_to_dict(&args.xdata, &state->xdata)) { + SERVER_REQ_SET_ERROR(req, ret); + goto out; + } + + ret = unserialize_req_locklist_v2(&args, &state->locklist); + if (ret) + goto out; + + ret = 0; + + resolve_and_resume(frame, server4_setactivelk_resume); +out: + return ret; +} + +int +server4_0_namelink(rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfx_namelink_req args = { + { + 0, + }, + }; + int ret = -1; + + 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; + + if (xdr_to_dict(&args.xdata, &state->xdata)) { + SERVER_REQ_SET_ERROR(req, ret); + goto out; + } + ret = 0; + resolve_and_resume(frame, server4_namelink_resume); + +out: + return ret; +} + +int +server4_0_icreate(rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfx_icreate_req args = { + { + 0, + }, + }; + int ret = -1; + 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 auxiliary inode number */ + memset(state->resolve.pargfid, 0, sizeof(uuid_t)); + state->resolve.pargfid[15] = GF_AUXILLARY_PARGFID; + + state->resolve.type = RESOLVE_NOT; + + if (xdr_to_dict(&args.xdata, &state->xdata)) { + SERVER_REQ_SET_ERROR(req, ret); + goto out; + } + ret = 0; + resolve_and_resume(frame, server4_icreate_resume); + +out: + 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; + + 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; + + if (xdr_to_dict(&args.xdata, &state->xdata)) { + SERVER_REQ_SET_ERROR(req, ret); + goto out; + } + ret = 0; + resolve_and_resume(frame, server4_fsetattr_resume); + +out: + 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; + + 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); + + if (xdr_to_dict(&args.xdata, &state->xdata)) { + SERVER_REQ_SET_ERROR(req, ret); + goto out; + } + ret = 0; + resolve_and_resume(frame, server4_rchecksum_resume); +out: + return ret; +} + +int +server4_0_put(rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfx_put_req args = { + { + 0, + }, + }; + int ret = -1; + ssize_t len = 0; + int i = 0; + + if (!req) + return ret; + + ret = rpc_receive_common(req, &frame, &state, &len, &args, xdr_gfx_put_req, + GF_FOP_PUT); + 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.flag); + state->offset = args.offset; + state->size = args.size; + 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]; + } + + len = iov_length(state->payload_vector, state->payload_count); + + GF_ASSERT(state->size == len); + + 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; + } + + if (xdr_to_dict(&args.xattr, &state->dict)) { + SERVER_REQ_SET_ERROR(req, ret); + goto out; + } + if (xdr_to_dict(&args.xdata, &state->xdata)) { + SERVER_REQ_SET_ERROR(req, ret); + goto out; + } + + ret = 0; + resolve_and_resume(frame, server4_put_resume); + +out: + free(args.bname); + + return ret; +} + +int +server4_0_compound(rpcsvc_request_t *req) +{ + int ret = -1; + SERVER_REQ_SET_ERROR(req, ret); + return ret; +} + +int +server4_0_copy_file_range(rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfx_copy_file_range_req args = { + { + 0, + }, + }; + ssize_t len = 0; + int ret = -1; + + if (!req) + return ret; + + ret = rpc_receive_common(req, &frame, &state, &len, &args, + xdr_gfx_copy_file_range_req, + GF_FOP_COPY_FILE_RANGE); + if (ret != 0) { + goto out; + } + + state->resolve.type = RESOLVE_MUST; + state->resolve.fd_no = args.fd_in; + state->resolve2.type = RESOLVE_MUST; /*making this resolve must */ + state->resolve2.fd_no = args.fd_out; + state->off_in = args.off_in; + state->off_out = args.off_out; + state->size = args.size; + state->flags = args.flag; + memcpy(state->resolve.gfid, args.gfid1, 16); + memcpy(state->resolve2.gfid, args.gfid2, 16); + + if (xdr_to_dict(&args.xdata, &state->xdata)) { + SERVER_REQ_SET_ERROR(req, ret); + goto out; + } + + ret = 0; + resolve_and_resume(frame, server4_copy_file_range_resume); +out: + + return ret; +} + +static rpcsvc_actor_t glusterfs4_0_fop_actors[] = { + [GFS3_OP_NULL] = {"NULL", server_null, NULL, GFS3_OP_NULL, 0}, + [GFS3_OP_STAT] = {"STAT", server4_0_stat, NULL, GFS3_OP_STAT, 0}, + [GFS3_OP_READLINK] = {"READLINK", server4_0_readlink, NULL, + GFS3_OP_READLINK, 0}, + [GFS3_OP_MKNOD] = {"MKNOD", server4_0_mknod, NULL, GFS3_OP_MKNOD, 0}, + [GFS3_OP_MKDIR] = {"MKDIR", server4_0_mkdir, NULL, GFS3_OP_MKDIR, 0}, + [GFS3_OP_UNLINK] = {"UNLINK", server4_0_unlink, NULL, GFS3_OP_UNLINK, 0}, + [GFS3_OP_RMDIR] = {"RMDIR", server4_0_rmdir, NULL, GFS3_OP_RMDIR, 0}, + [GFS3_OP_SYMLINK] = {"SYMLINK", server4_0_symlink, NULL, GFS3_OP_SYMLINK, + 0}, + [GFS3_OP_RENAME] = {"RENAME", server4_0_rename, NULL, GFS3_OP_RENAME, 0}, + [GFS3_OP_LINK] = {"LINK", server4_0_link, NULL, GFS3_OP_LINK, 0}, + [GFS3_OP_TRUNCATE] = {"TRUNCATE", server4_0_truncate, NULL, + GFS3_OP_TRUNCATE, 0}, + [GFS3_OP_OPEN] = {"OPEN", server4_0_open, NULL, GFS3_OP_OPEN, 0}, + [GFS3_OP_READ] = {"READ", server4_0_readv, NULL, GFS3_OP_READ, 0}, + [GFS3_OP_WRITE] = {"WRITE", server4_0_writev, server4_0_writev_vecsizer, + GFS3_OP_WRITE, 0}, + [GFS3_OP_STATFS] = {"STATFS", server4_0_statfs, NULL, GFS3_OP_STATFS, 0}, + [GFS3_OP_FLUSH] = {"FLUSH", server4_0_flush, NULL, GFS3_OP_FLUSH, 0}, + [GFS3_OP_FSYNC] = {"FSYNC", server4_0_fsync, NULL, GFS3_OP_FSYNC, 0}, + [GFS3_OP_GETXATTR] = {"GETXATTR", server4_0_getxattr, NULL, + GFS3_OP_GETXATTR, 0}, + [GFS3_OP_SETXATTR] = {"SETXATTR", server4_0_setxattr, NULL, + GFS3_OP_SETXATTR, 0}, + [GFS3_OP_REMOVEXATTR] = {"REMOVEXATTR", server4_0_removexattr, NULL, + GFS3_OP_REMOVEXATTR, 0}, + [GFS3_OP_OPENDIR] = {"OPENDIR", server4_0_opendir, NULL, GFS3_OP_OPENDIR, + 0}, + [GFS3_OP_FSYNCDIR] = {"FSYNCDIR", server4_0_fsyncdir, NULL, + GFS3_OP_FSYNCDIR, 0}, + [GFS3_OP_ACCESS] = {"ACCESS", server4_0_access, NULL, GFS3_OP_ACCESS, 0}, + [GFS3_OP_CREATE] = {"CREATE", server4_0_create, NULL, GFS3_OP_CREATE, 0}, + [GFS3_OP_FTRUNCATE] = {"FTRUNCATE", server4_0_ftruncate, NULL, + GFS3_OP_FTRUNCATE, 0}, + [GFS3_OP_FSTAT] = {"FSTAT", server4_0_fstat, NULL, GFS3_OP_FSTAT, 0}, + [GFS3_OP_LK] = {"LK", server4_0_lk, NULL, GFS3_OP_LK, 0}, + [GFS3_OP_LOOKUP] = {"LOOKUP", server4_0_lookup, NULL, GFS3_OP_LOOKUP, 0}, + [GFS3_OP_READDIR] = {"READDIR", server4_0_readdir, NULL, GFS3_OP_READDIR, + 0}, + [GFS3_OP_INODELK] = {"INODELK", server4_0_inodelk, NULL, GFS3_OP_INODELK, + 0}, + [GFS3_OP_FINODELK] = {"FINODELK", server4_0_finodelk, NULL, + GFS3_OP_FINODELK, 0}, + [GFS3_OP_ENTRYLK] = {"ENTRYLK", server4_0_entrylk, NULL, GFS3_OP_ENTRYLK, + 0}, + [GFS3_OP_FENTRYLK] = {"FENTRYLK", server4_0_fentrylk, NULL, + GFS3_OP_FENTRYLK, 0}, + [GFS3_OP_XATTROP] = {"XATTROP", server4_0_xattrop, NULL, GFS3_OP_XATTROP, + 0}, + [GFS3_OP_FXATTROP] = {"FXATTROP", server4_0_fxattrop, NULL, + GFS3_OP_FXATTROP, 0}, + [GFS3_OP_FGETXATTR] = {"FGETXATTR", server4_0_fgetxattr, NULL, + GFS3_OP_FGETXATTR, 0}, + [GFS3_OP_FSETXATTR] = {"FSETXATTR", server4_0_fsetxattr, NULL, + GFS3_OP_FSETXATTR, 0}, + [GFS3_OP_RCHECKSUM] = {"RCHECKSUM", server4_0_rchecksum, NULL, + GFS3_OP_RCHECKSUM, 0}, + [GFS3_OP_SETATTR] = {"SETATTR", server4_0_setattr, NULL, GFS3_OP_SETATTR, + 0}, + [GFS3_OP_FSETATTR] = {"FSETATTR", server4_0_fsetattr, NULL, + GFS3_OP_FSETATTR, 0}, + [GFS3_OP_READDIRP] = {"READDIRP", server4_0_readdirp, NULL, + GFS3_OP_READDIRP, 0}, + [GFS3_OP_RELEASE] = {"RELEASE", server4_0_release, NULL, GFS3_OP_RELEASE, + 0}, + [GFS3_OP_RELEASEDIR] = {"RELEASEDIR", server4_0_releasedir, NULL, + GFS3_OP_RELEASEDIR, 0}, + [GFS3_OP_FREMOVEXATTR] = {"FREMOVEXATTR", server4_0_fremovexattr, NULL, + GFS3_OP_FREMOVEXATTR, 0}, + [GFS3_OP_FALLOCATE] = {"FALLOCATE", server4_0_fallocate, NULL, DRC_NA, + GFS3_OP_FALLOCATE, 0}, + [GFS3_OP_DISCARD] = {"DISCARD", server4_0_discard, NULL, DRC_NA, + GFS3_OP_DISCARD, 0}, + [GFS3_OP_ZEROFILL] = {"ZEROFILL", server4_0_zerofill, NULL, DRC_NA, + GFS3_OP_ZEROFILL, 0}, + [GFS3_OP_IPC] = {"IPC", server4_0_ipc, NULL, DRC_NA, GFS3_OP_IPC, 0}, + [GFS3_OP_SEEK] = {"SEEK", server4_0_seek, NULL, DRC_NA, GFS3_OP_SEEK, 0}, + [GFS3_OP_LEASE] = {"LEASE", server4_0_lease, NULL, DRC_NA, GFS3_OP_LEASE, + 0}, + [GFS3_OP_GETACTIVELK] = {"GETACTIVELK", server4_0_getactivelk, NULL, DRC_NA, + GFS3_OP_GETACTIVELK, 0}, + [GFS3_OP_SETACTIVELK] = {"SETACTIVELK", server4_0_setactivelk, NULL, DRC_NA, + GFS3_OP_SETACTIVELK, 0}, + [GFS3_OP_COMPOUND] = {"COMPOUND", server4_0_compound, NULL, DRC_NA, + GFS3_OP_COMPOUND, 0}, + [GFS3_OP_ICREATE] = {"ICREATE", server4_0_icreate, NULL, DRC_NA, + GFS3_OP_ICREATE, 0}, + [GFS3_OP_NAMELINK] = {"NAMELINK", server4_0_namelink, NULL, DRC_NA, + GFS3_OP_NAMELINK, 0}, + [GFS3_OP_COPY_FILE_RANGE] = {"COPY-FILE-RANGE", server4_0_copy_file_range, + NULL, DRC_NA, GFS3_OP_COPY_FILE_RANGE, 0}, +}; + +struct rpcsvc_program glusterfs4_0_fop_prog = { + .progname = "GlusterFS 4.x v1", + .prognum = GLUSTER_FOP_PROGRAM, + .progver = GLUSTER_FOP_VERSION_v2, + .numactors = GLUSTER_FOP_PROCCNT, + .actors = glusterfs4_0_fop_actors, + .ownthread = _gf_true, +}; diff --git a/xlators/protocol/server/src/server.c b/xlators/protocol/server/src/server.c index 5d1f3aabea8..721968004a0 100644 --- a/xlators/protocol/server/src/server.c +++ b/xlators/protocol/server/src/server.c @@ -1,609 +1,1285 @@ /* - Copyright (c) 2010 Gluster, Inc. <http://www.gluster.com> + Copyright (c) 2010-2013 Red Hat, Inc. <http://www.redhat.com> This file is part of GlusterFS. - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. + 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. */ - -#ifndef _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif - #include <sys/time.h> #include <sys/resource.h> #include "server.h" #include "server-helpers.h" #include "glusterfs3-xdr.h" -#include "call-stub.h" -#include "statedump.h" -#include "defaults.h" +#include <glusterfs/call-stub.h> +#include <glusterfs/statedump.h> +#include <glusterfs/defaults.h> #include "authenticate.h" -#include "rpcsvc.h" +#include <glusterfs/gf-event.h> +#include <glusterfs/events.h> +#include "server-messages.h" +#include "rpc-clnt.h" + +rpcsvc_cbk_program_t server_cbk_prog = { + .progname = "Gluster Callback", + .prognum = GLUSTER_CBK_PROGRAM, + .progver = GLUSTER_CBK_VERSION, +}; struct iobuf * -gfs_serialize_reply (rpcsvc_request_t *req, void *arg, gfs_serialize_t sfunc, - struct iovec *outmsg) +gfs_serialize_reply(rpcsvc_request_t *req, void *arg, struct iovec *outmsg, + xdrproc_t xdrproc) { - struct iobuf *iob = NULL; - ssize_t retlen = -1; - - /* First, get the io buffer into which the reply in arg will - * be serialized. - */ - iob = iobuf_get (req->svc->ctx->iobuf_pool); + struct iobuf *iob = NULL; + ssize_t retlen = 0; + ssize_t xdr_size = 0; + + GF_VALIDATE_OR_GOTO("server", req, ret); + + /* First, get the io buffer into which the reply in arg will + * be serialized. + */ + if (arg && xdrproc) { + xdr_size = xdr_sizeof(xdrproc, arg); + iob = iobuf_get2(req->svc->ctx->iobuf_pool, xdr_size); if (!iob) { - gf_log ("", GF_LOG_ERROR, "Failed to get iobuf"); - goto ret; - } + gf_msg_callingfn(THIS->name, GF_LOG_ERROR, ENOMEM, PS_MSG_NO_MEMORY, + "Failed to get iobuf"); + goto ret; + }; - iobuf_to_iovec (iob, outmsg); + iobuf_to_iovec(iob, outmsg); /* Use the given serializer to translate the give C structure in arg * to XDR format which will be written into the buffer in outmsg. */ /* retlen is used to received the error since size_t is unsigned and we * need -1 for error notification during encoding. */ - retlen = sfunc (*outmsg, arg); - if (retlen == -1) { - /* Failed to Encode 'GlusterFS' msg in RPC is not exactly - failure of RPC return values.. client should get - notified about this, so there are no missing frames */ - gf_log ("", GF_LOG_ERROR, "Failed to encode message"); - req->rpc_err = GARBAGE_ARGS; - retlen = 0; - } - outmsg->iov_len = retlen; -ret: + retlen = xdr_serialize_generic(*outmsg, arg, xdrproc); if (retlen == -1) { - iobuf_unref (iob); - iob = NULL; + /* Failed to Encode 'GlusterFS' msg in RPC is not exactly + failure of RPC return values.. client should get + notified about this, so there are no missing frames */ + gf_msg_callingfn("", GF_LOG_ERROR, 0, PS_MSG_ENCODE_MSG_FAILED, + "Failed to encode message"); + req->rpc_err = GARBAGE_ARGS; + retlen = 0; } - - return iob; + } + outmsg->iov_len = retlen; +ret: + return iob; } - - -/* Generic reply function for NFSv3 specific replies. */ int -server_submit_reply (call_frame_t *frame, rpcsvc_request_t *req, void *arg, - struct iovec *payload, int payloadcount, - struct iobref *iobref, gfs_serialize_t sfunc) +server_submit_reply(call_frame_t *frame, rpcsvc_request_t *req, void *arg, + struct iovec *payload, int payloadcount, + struct iobref *iobref, xdrproc_t xdrproc) { - struct iobuf *iob = NULL; - int ret = -1; - struct iovec rsp = {0,}; - server_state_t *state = NULL; - char new_iobref = 0; - - if (!req) { - goto ret; + struct iobuf *iob = NULL; + int ret = -1; + struct iovec rsp = { + 0, + }; + server_state_t *state = NULL; + char new_iobref = 0; + client_t *client = NULL; + + GF_VALIDATE_OR_GOTO("server", req, ret); + + if (frame) { + state = CALL_STATE(frame); + frame->local = NULL; + client = frame->root->client; + } + + if (!iobref) { + iobref = iobref_new(); + if (!iobref) { + goto ret; } - if (frame) { - state = CALL_STATE (frame); - frame->local = NULL; + new_iobref = 1; + } + + iob = gfs_serialize_reply(req, arg, &rsp, xdrproc); + if (!iob) { + gf_smsg("", GF_LOG_ERROR, 0, PS_MSG_SERIALIZE_REPLY_FAILED, NULL); + goto ret; + } + + iobref_add(iobref, iob); + + /* Then, submit the message for transmission. */ + ret = rpcsvc_submit_generic(req, &rsp, 1, payload, payloadcount, iobref); + + /* TODO: this is demo purpose only */ + /* ret = rpcsvc_callback_submit (req->svc, req->trans, req->prog, + GF_CBK_NULL, &rsp, 1); + */ + /* Now that we've done our job of handing the message to the RPC layer + * we can safely unref the iob in the hope that RPC layer must have + * ref'ed the iob on receiving into the txlist. + */ + iobuf_unref(iob); + if (ret == -1) { + gf_msg_callingfn("", GF_LOG_ERROR, 0, PS_MSG_REPLY_SUBMIT_FAILED, + "Reply submission failed"); + if (frame && client) { + server_connection_cleanup(frame->this, client, + INTERNAL_LOCKS | POSIX_LOCKS, NULL); + } else { + gf_msg_callingfn("", GF_LOG_ERROR, 0, PS_MSG_REPLY_SUBMIT_FAILED, + "Reply submission failed"); + /* TODO: Failure of open(dir), create, inodelk, entrylk + or lk fops send failure must be handled specially. */ } + goto ret; + } - if (!iobref) { - iobref = iobref_new (); - if (!iobref) { - gf_log ("", GF_LOG_ERROR, "out of memory"); - goto ret; - } - - new_iobref = 1; - } + ret = 0; +ret: + if (client) + gf_client_unref(client); - iob = gfs_serialize_reply (req, arg, sfunc, &rsp); - if (!iob) { - gf_log ("", GF_LOG_ERROR, "Failed to serialize reply"); - goto ret; - } + if (frame) + STACK_DESTROY(frame->root); - iobref_add (iobref, iob); + if (new_iobref) + iobref_unref(iobref); - /* Then, submit the message for transmission. */ - ret = rpcsvc_submit_generic (req, &rsp, 1, payload, payloadcount, - iobref); + if (state) + free_state(state); - /* TODO: this is demo purpose only */ - /* ret = rpcsvc_callback_submit (req->svc, req->trans, req->prog, - GF_CBK_NULL, &rsp, 1); - */ - /* Now that we've done our job of handing the message to the RPC layer - * we can safely unref the iob in the hope that RPC layer must have - * ref'ed the iob on receiving into the txlist. - */ - iobuf_unref (iob); - if (ret == -1) { - gf_log ("", GF_LOG_ERROR, "Reply submission failed"); - goto ret; - } + return ret; +} - ret = 0; -ret: - if (state) { - free_state (state); - } +int +server_priv_to_dict(xlator_t *this, dict_t *dict, char *brickname) +{ + server_conf_t *conf = NULL; + rpc_transport_t *xprt = NULL; + peer_info_t *peerinfo = NULL; + char key[32] = { + 0, + }; + int keylen; + int count = 0; + int ret = -1; + + GF_VALIDATE_OR_GOTO(THIS->name, this, out); + GF_VALIDATE_OR_GOTO(THIS->name, dict, out); + + conf = this->private; + if (!conf) + return 0; + // TODO: Dump only specific info to dict - if (frame) { - STACK_DESTROY (frame->root); + pthread_mutex_lock(&conf->mutex); + { + list_for_each_entry(xprt, &conf->xprt_list, list) + { + if ((xprt->xl_private) && (xprt->xl_private->bound_xl) && + (xprt->xl_private->bound_xl->name) && (brickname) && + (!strcmp(brickname, xprt->xl_private->bound_xl->name))) { + peerinfo = &xprt->peerinfo; + keylen = snprintf(key, sizeof(key), "client%d.hostname", count); + ret = dict_set_strn(dict, key, keylen, peerinfo->identifier); + if (ret) + goto unlock; + + snprintf(key, sizeof(key), "client%d.bytesread", count); + ret = dict_set_uint64(dict, key, xprt->total_bytes_read); + if (ret) + goto unlock; + + snprintf(key, sizeof(key), "client%d.byteswrite", count); + ret = dict_set_uint64(dict, key, xprt->total_bytes_write); + if (ret) + goto unlock; + + snprintf(key, sizeof(key), "client%d.opversion", count); + ret = dict_set_uint32(dict, key, peerinfo->max_op_version); + if (ret) + goto unlock; + + keylen = snprintf(key, sizeof(key), "client%d.name", count); + ret = dict_set_strn(dict, key, keylen, + xprt->xl_private->client_name); + if (ret) + goto unlock; + + count++; + } } + } +unlock: + pthread_mutex_unlock(&conf->mutex); + if (ret) + goto out; - if (new_iobref) { - iobref_unref (iobref); - } + ret = dict_set_int32_sizen(dict, "clientcount", count); - return ret; +out: + return ret; } -/* */ int -xdr_to_glusterfs_req (rpcsvc_request_t *req, void *arg, gfs_serialize_t sfunc) +server_priv(xlator_t *this) { - int ret = -1; + server_conf_t *conf = NULL; + rpc_transport_t *xprt = NULL; + char key[GF_DUMP_MAX_BUF_LEN] = { + 0, + }; + uint64_t total_read = 0; + uint64_t total_write = 0; + int32_t ret = -1; + + GF_VALIDATE_OR_GOTO("server", this, out); + + conf = this->private; + if (!conf) + return 0; - if (!req) - return -1; + gf_proc_dump_build_key(key, "xlator.protocol.server", "priv"); + gf_proc_dump_add_section("%s", key); - ret = sfunc (req->msg[0], arg); + ret = pthread_mutex_trylock(&conf->mutex); + if (ret != 0) + goto out; + { + list_for_each_entry(xprt, &conf->xprt_list, list) + { + total_read += xprt->total_bytes_read; + total_write += xprt->total_bytes_write; + } + } + pthread_mutex_unlock(&conf->mutex); - if (ret > 0) - ret = 0; + gf_proc_dump_build_key(key, "server", "total-bytes-read"); + gf_proc_dump_write(key, "%" PRIu64, total_read); - return ret; + gf_proc_dump_build_key(key, "server", "total-bytes-write"); + gf_proc_dump_write(key, "%" PRIu64, total_write); + + rpcsvc_statedump(conf->rpc); + + ret = 0; +out: + if (ret) + gf_proc_dump_write("Unable to print priv", + "(Lock acquisition failed) %s", + this ? this->name : "server"); + + return ret; } -int -server_fd (xlator_t *this) +static int +get_auth_types(dict_t *this, char *key, data_t *value, void *data) { - server_conf_t *conf = NULL; - server_connection_t *trav = NULL; - char key[GF_DUMP_MAX_BUF_LEN]; - int i = 1; - int ret = -1; - - if (!this) - return -1; - - conf = this->private; - if (!conf) { - gf_log (this->name, GF_LOG_WARNING, - "conf null in xlator"); - return -1; - } - - gf_proc_dump_add_section("xlator.protocol.server.conn"); - - ret = pthread_mutex_trylock (&conf->mutex); - if (ret) { - gf_log("", GF_LOG_WARNING, "Unable to dump fdtable" - " errno: %d", errno); - return -1; + dict_t *auth_dict = NULL; + char *saveptr = NULL; + char *tmp = NULL; + char *key_cpy = NULL; + int32_t ret = -1; + + GF_VALIDATE_OR_GOTO("server", this, out); + GF_VALIDATE_OR_GOTO("server", key, out); + GF_VALIDATE_OR_GOTO("server", data, out); + + auth_dict = data; + key_cpy = gf_strdup(key); + GF_VALIDATE_OR_GOTO("server", key_cpy, out); + + tmp = strtok_r(key_cpy, ".", &saveptr); + ret = strcmp(tmp, "auth"); + if (ret == 0) { + tmp = strtok_r(NULL, ".", &saveptr); + if (strcmp(tmp, "ip") == 0) { + /* TODO: backward compatibility, remove when + newer versions are available */ + tmp = "addr"; + gf_smsg("server", GF_LOG_WARNING, 0, PS_MSG_AUTH_IP_ERROR, NULL); } + ret = dict_set_dynptr(auth_dict, tmp, NULL, 0); + if (ret < 0) { + gf_msg_debug("server", 0, + "failed to " + "dict_set_dynptr"); + } + } - list_for_each_entry (trav, &conf->conns, list) { - if (trav->id) { - gf_proc_dump_build_key(key, - "xlator.protocol.server.conn", - "%d.id", i); - gf_proc_dump_write(key, "%s", trav->id); - } - - gf_proc_dump_build_key(key,"xlator.protocol.server.conn", - "%d.ref",i) - gf_proc_dump_write(key, "%d", trav->ref); - if (trav->bound_xl) { - gf_proc_dump_build_key(key, - "xlator.protocol.server.conn", - "%d.bound_xl", i); - gf_proc_dump_write(key, "%s", trav->bound_xl->name); - } - - gf_proc_dump_build_key(key, - "xlator.protocol.server.conn", - "%d.id", i); - fdtable_dump(trav->fdtable,key); - i++; - } - pthread_mutex_unlock (&conf->mutex); - + GF_FREE(key_cpy); +out: + return 0; +} - return 0; - } +int +_check_for_auth_option(dict_t *d, char *k, data_t *v, void *tmp) +{ + int ret = 0; + xlator_t *xl = NULL; + char *tail = NULL; + + xl = tmp; + + tail = strtail(k, "auth."); + if (!tail) + goto out; + + if (strncmp(tail, "addr.", 5) != 0) { + gf_smsg(xl->name, GF_LOG_TRACE, 0, PS_MSG_SKIP_FORMAT_CHK, "option=%s", + k, NULL); + goto out; + } + + /* fast fwd through module type */ + tail = strchr(tail, '.'); + if (!tail) + goto out; + tail++; + + tail = strtail(tail, xl->name); + if (!tail) + goto out; + + if (*tail == '.') { + /* when we are here, the key is checked for + * valid auth.allow.<xlator> + * Now we verify the ip address + */ + ret = xlator_option_validate_addr_list(xl, "auth-*", v->data, NULL, + NULL); + if (ret) + gf_smsg(xl->name, GF_LOG_ERROR, 0, PS_MSG_INTERNET_ADDR_ERROR, + "data=%s", v->data, NULL); + } +out: + return ret; +} int -server_priv (xlator_t *this) +validate_auth_options(xlator_t *this, dict_t *dict) { - server_conf_t *conf = NULL; - rpc_transport_t *xprt = NULL; - char key[GF_DUMP_MAX_BUF_LEN] = {0,}; - uint64_t total_read = 0; - uint64_t total_write = 0; + int error = -1; + xlator_list_t *trav = NULL; - conf = this->private; - if (!conf) - return 0; + GF_VALIDATE_OR_GOTO("server", this, out); + GF_VALIDATE_OR_GOTO("server", dict, out); - list_for_each_entry (xprt, &conf->xprt_list, list) { - total_read += xprt->total_bytes_read; - total_write += xprt->total_bytes_write; + trav = this->children; + while (trav) { + error = dict_foreach(dict, _check_for_auth_option, trav->xlator); + + if (-1 == error) { + gf_smsg(this->name, GF_LOG_ERROR, 0, PS_MSG_AUTHENTICATE_ERROR, + "name=%s", trav->xlator->name, NULL); + break; } + trav = trav->next; + } + +out: + return error; +} + +void +server_call_xlator_mem_cleanup(xlator_t *this, char *victim_name) +{ + pthread_t th_id = { + 0, + }; + int th_ret = -1; + server_cleanup_xprt_arg_t *arg = NULL; - gf_proc_dump_build_key(key, "server", "total-bytes-read"); - gf_proc_dump_write(key, "%"PRIu64, total_read); + if (!victim_name) + return; - gf_proc_dump_build_key(key, "server", "total-bytes-write"); - gf_proc_dump_write(key, "%"PRIu64, total_write); + gf_log(this->name, GF_LOG_INFO, "Create graph janitor thread for brick %s", + victim_name); - return 0; + arg = calloc(1, sizeof(*arg)); + arg->this = this; + arg->victim_name = strdup(victim_name); + if (!arg->victim_name) { + gf_smsg(this->name, GF_LOG_CRITICAL, ENOMEM, LG_MSG_NO_MEMORY, + "Memory allocation is failed"); + free(arg); + return; + } + + th_ret = gf_thread_create_detached(&th_id, server_graph_janitor_threads, + arg, "graphjanitor"); + if (th_ret) { + gf_log(this->name, GF_LOG_ERROR, + "graph janitor Thread" + " creation is failed for brick %s", + victim_name); + free(arg->victim_name); + free(arg); + } } int -server_inode (xlator_t *this) +server_rpc_notify(rpcsvc_t *rpc, void *xl, rpcsvc_event_t event, void *data) { - server_conf_t *conf = NULL; - server_connection_t *trav = NULL; - char key[GF_DUMP_MAX_BUF_LEN]; - int i = 1; - int ret = -1; - - if (!this) - return -1; - - conf = this->private; - if (!conf) { - gf_log (this->name, GF_LOG_WARNING, - "conf null in xlator"); - return -1; - } - - ret = pthread_mutex_trylock (&conf->mutex); - if (ret) { - gf_log("", GF_LOG_WARNING, "Unable to dump itable" - " errno: %d", errno); - return -1; + gf_boolean_t detached = _gf_false; + xlator_t *this = NULL; + rpc_transport_t *trans = NULL; + server_conf_t *conf = NULL; + client_t *client = NULL; + char *auth_path = NULL; + int ret = -1; + char *xlator_name = NULL; + uint64_t xprtrefcount = 0; + gf_boolean_t fd_exist = _gf_false; + + this = xl; + trans = data; + + if (!this || !data || !this->ctx || !this->ctx->active) { + gf_msg_callingfn("server", GF_LOG_WARNING, 0, PS_MSG_RPC_NOTIFY_ERROR, + "Calling rpc_notify without initializing"); + goto out; + } + + conf = this->private; + + switch (event) { + case RPCSVC_EVENT_ACCEPT: { + /* Have a structure per new connection */ + /* TODO: Should we create anything here at all ? * / + client->conn = create_server_conn_state (this, trans); + if (!client->conn) + goto out; + + trans->protocol_private = client->conn; + */ + + pthread_mutex_lock(&conf->mutex); + rpc_transport_ref(trans); + list_add_tail(&trans->list, &conf->xprt_list); + pthread_mutex_unlock(&conf->mutex); + + break; } + case RPCSVC_EVENT_DISCONNECT: - list_for_each_entry (trav, &conf->conns, list) { - if (trav->bound_xl && trav->bound_xl->itable) { - gf_proc_dump_build_key(key, - "xlator.protocol.server.conn", - "%d.bound_xl.%s", - i, trav->bound_xl->name); - inode_table_dump(trav->bound_xl->itable,key); - i++; - } - } - pthread_mutex_unlock (&conf->mutex); + /* A DISCONNECT event could come without an ACCEPT event + * happening for this transport. This happens when the server is + * expecting encrypted connections by the client tries to + * connect unecnrypted + */ + if (list_empty(&trans->list)) { + break; + } + + /* Set the disconnect_progress flag to 1 to avoid races + during brick detach while brick mux is enabled + */ + GF_ATOMIC_INIT(trans->disconnect_progress, 1); + /* transport has to be removed from the list upon disconnect + * irrespective of whether lock self heal is off or on, since + * new transport will be created upon reconnect. + */ + pthread_mutex_lock(&conf->mutex); + client = trans->xl_private; + if (!client) + list_del_init(&trans->list); + pthread_mutex_unlock(&conf->mutex); + + if (!client) + goto unref_transport; + + gf_smsg(this->name, GF_LOG_INFO, 0, PS_MSG_CLIENT_DISCONNECTING, + "client-uid=%s", client->client_uid, NULL); + + ret = dict_get_str_sizen(this->options, "auth-path", &auth_path); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PS_MSG_DICT_GET_FAILED, + "type=auth-path", NULL); + auth_path = NULL; + } + + gf_client_ref(client); + gf_client_put(client, &detached); + if (detached) { + server_connection_cleanup( + this, client, INTERNAL_LOCKS | POSIX_LOCKS, &fd_exist); + gf_event(EVENT_CLIENT_DISCONNECT, + "client_uid=%s;" + "client_identifier=%s;server_identifier=%s;" + "brick_path=%s", + client->client_uid, trans->peerinfo.identifier, + trans->myinfo.identifier, auth_path); + } + + /* + * gf_client_unref will be done while handling + * RPC_EVENT_TRANSPORT_DESTROY + */ + + unref_transport: + /* rpc_transport_unref() causes a RPCSVC_EVENT_TRANSPORT_DESTROY + * to be called in blocking manner + * So no code should ideally be after this unref, Call + * rpc_transport_unref only while cleanup_starting flag is not set + * otherwise transport_unref will be call by either + * server_connection_cleanup_flush_cbk or server_submit_reply at the + * time of freeing state + */ + if (!client || !detached || !fd_exist) + rpc_transport_unref(trans); + break; + case RPCSVC_EVENT_TRANSPORT_DESTROY: + pthread_mutex_lock(&conf->mutex); + client = trans->xl_private; + list_del_init(&trans->list); + pthread_mutex_unlock(&conf->mutex); + if (!client) + break; + if (client->bound_xl && client->bound_xl->cleanup_starting) { + xprtrefcount = GF_ATOMIC_GET(client->bound_xl->xprtrefcnt); + if (xprtrefcount > 0) { + xprtrefcount = GF_ATOMIC_DEC(client->bound_xl->xprtrefcnt); + if (xprtrefcount == 0) + xlator_name = gf_strdup(client->bound_xl->name); + } + } - return 0; -} + gf_client_unref(client); + if (xlator_name) { + server_call_xlator_mem_cleanup(this, xlator_name); + GF_FREE(xlator_name); + } -static void -get_auth_types (dict_t *this, char *key, data_t *value, void *data) -{ - dict_t *auth_dict = NULL; - char *saveptr = NULL; - char *tmp = NULL; - char *key_cpy = NULL; - int32_t ret = -1; - - auth_dict = data; - key_cpy = gf_strdup (key); - GF_VALIDATE_OR_GOTO("server", key_cpy, out); - - tmp = strtok_r (key_cpy, ".", &saveptr); - ret = strcmp (tmp, "auth"); - if (ret == 0) { - tmp = strtok_r (NULL, ".", &saveptr); - if (strcmp (tmp, "ip") == 0) { - /* TODO: backward compatibility, remove when - newer versions are available */ - tmp = "addr"; - gf_log ("server", GF_LOG_WARNING, - "assuming 'auth.ip' to be 'auth.addr'"); - } - ret = dict_set_dynptr (auth_dict, tmp, NULL, 0); - if (ret < 0) { - gf_log ("server", GF_LOG_DEBUG, - "failed to dict_set_dynptr"); - } - } + trans->xl_private = NULL; + break; + default: + break; + } - GF_FREE (key_cpy); out: - return; + return 0; } - -int -validate_auth_options (xlator_t *this, dict_t *dict) +void * +server_graph_janitor_threads(void *data) { - int ret = -1; - int error = 0; - xlator_list_t *trav = NULL; - data_pair_t *pair = NULL; - char *saveptr = NULL; - char *tmp = NULL; - char *key_cpy = NULL; - - trav = this->children; - while (trav) { - error = -1; - for (pair = dict->members_list; pair; pair = pair->next) { - key_cpy = gf_strdup (pair->key); - tmp = strtok_r (key_cpy, ".", &saveptr); - ret = strcmp (tmp, "auth"); - if (ret == 0) { - /* for module type */ - tmp = strtok_r (NULL, ".", &saveptr); - if (!tmp) - break; - /* for volume name */ - tmp = strtok_r (NULL, ".", &saveptr); - } - - if (strcmp (tmp, trav->xlator->name) == 0) { - error = 0; - GF_FREE (key_cpy); - break; - } - GF_FREE (key_cpy); - } - if (-1 == error) { - gf_log (this->name, GF_LOG_ERROR, - "volume '%s' defined as subvolume, but no " - "authentication defined for the same", - trav->xlator->name); - break; - } - trav = trav->next; + xlator_t *victim = NULL; + xlator_t *this = NULL; + server_conf_t *conf = NULL; + glusterfs_ctx_t *ctx = NULL; + char *victim_name = NULL; + server_cleanup_xprt_arg_t *arg = NULL; + gf_boolean_t victim_found = _gf_false; + xlator_list_t **trav_p = NULL; + xlator_t *top = NULL; + uint32_t parent_down = 0; + + GF_ASSERT(data); + + arg = data; + this = arg->this; + victim_name = arg->victim_name; + THIS = arg->this; + conf = this->private; + + ctx = THIS->ctx; + GF_VALIDATE_OR_GOTO(this->name, ctx, out); + + top = this->ctx->active->first; + LOCK(&ctx->volfile_lock); + for (trav_p = &top->children; *trav_p; trav_p = &(*trav_p)->next) { + victim = (*trav_p)->xlator; + if (victim->cleanup_starting && + strcmp(victim->name, victim_name) == 0) { + parent_down = victim->parent_down; + victim->parent_down = 1; + if (!parent_down) + victim_found = _gf_true; + break; } + } + if (victim_found) + glusterfs_delete_volfile_checksum(ctx, victim->volfile_id); + UNLOCK(&ctx->volfile_lock); + if (!victim_found) { + gf_log(this->name, GF_LOG_ERROR, + "victim brick %s is not" + " found in graph", + victim_name); + goto out; + } + + default_notify(victim, GF_EVENT_PARENT_DOWN, victim); + if (victim->notify_down) { + gf_log(THIS->name, GF_LOG_INFO, + "Start call fini for brick" + " %s stack", + victim->name); + xlator_mem_cleanup(victim); + rpcsvc_autoscale_threads(ctx, conf->rpc, -1); + } - return error; +out: + free(arg->victim_name); + free(arg); + return NULL; } - -int -server_rpc_notify (rpcsvc_t *rpc, void *xl, rpcsvc_event_t event, - void *data) +int32_t +server_mem_acct_init(xlator_t *this) { - xlator_t *this = NULL; - rpc_transport_t *xprt = NULL; - server_connection_t *conn = NULL; - server_conf_t *conf = NULL; + int ret = -1; + GF_VALIDATE_OR_GOTO("server", this, out); - if (!xl || !data) { - gf_log ("server", GF_LOG_WARNING, - "Calling rpc_notify without initializing"); - goto out; - } + ret = xlator_mem_acct_init(this, gf_server_mt_end + 1); - this = xl; - xprt = data; - conf = this->private; - - switch (event) { - case RPCSVC_EVENT_ACCEPT: - { - /* Have a structure per new connection */ - /* TODO: Should we create anything here at all ? * / - conn = create_server_conn_state (this, xprt); - if (!conn) - goto out; - - xprt->protocol_private = conn; - */ - INIT_LIST_HEAD (&xprt->list); - - list_add_tail (&xprt->list, &conf->xprt_list); + if (ret != 0) { + gf_smsg(this->name, GF_LOG_ERROR, ENOMEM, PS_MSG_NO_MEMORY, NULL); + return ret; + } +out: + return ret; +} - break; +static int +_delete_auth_opt(dict_t *this, char *key, data_t *value, void *data) +{ + char *auth_option_pattern[] = { + "auth.addr.*.allow", "auth.addr.*.reject", "auth.login.*.allow", + "auth.login.*.password", "auth.login.*.ssl-allow", NULL}; + int i = 0; + + for (i = 0; auth_option_pattern[i]; i++) { + if (fnmatch(auth_option_pattern[i], key, 0) == 0) { + dict_del(this, key); + break; } - case RPCSVC_EVENT_DISCONNECT: - conn = get_server_conn_state (this, xprt); - if (conn) - server_connection_put (this, conn); + } - list_del (&xprt->list); + return 0; +} - break; - default: - break; +static int +_copy_auth_opt(dict_t *unused, char *key, data_t *value, void *xl_dict) +{ + char *auth_option_pattern[] = { + "auth.addr.*.allow", "auth.addr.*.reject", "auth.login.*.allow", + "auth.login.*.password", "auth.login.*.ssl-allow", NULL}; + int i = 0; + + for (i = 0; auth_option_pattern[i]; i++) { + if (fnmatch(auth_option_pattern[i], key, 0) == 0) { + dict_set((dict_t *)xl_dict, key, value); + break; } + } -out: - return 0; + return 0; } -int32_t -mem_acct_init (xlator_t *this) +int +server_check_event_threads(xlator_t *this, server_conf_t *conf, int32_t new) { - int ret = -1; + struct event_pool *pool = this->ctx->event_pool; + int target; + + target = new + pool->auto_thread_count; + conf->event_threads = new; - if (!this) - return ret; + if (target == pool->eventthreadcount) { + return 0; + } - ret = xlator_mem_acct_init (this, gf_server_mt_end + 1); + return gf_event_reconfigure_threads(pool, target); +} +int +server_reconfigure(xlator_t *this, dict_t *options) +{ + server_conf_t *conf = NULL; + rpcsvc_t *rpc_conf; + rpcsvc_listener_t *listeners; + rpc_transport_t *xprt = NULL; + rpc_transport_t *xp_next = NULL; + int inode_lru_limit; + gf_boolean_t trace; + data_t *data; + int ret = 0; + char *statedump_path = NULL; + int32_t new_nthread = 0; + char *auth_path = NULL; + char *xprt_path = NULL; + xlator_t *oldTHIS; + xlator_t *kid; + + /* + * Since we're not a fop, we can't really count on THIS being set + * correctly, and it needs to be or else GF_OPTION_RECONF won't work + * (because it won't find our options list). This is another thing + * that "just happened" to work before multiplexing, but now we need to + * handle it more explicitly. + */ + oldTHIS = THIS; + THIS = this; + + conf = this->private; + + if (!conf) { + gf_msg_callingfn(this->name, GF_LOG_DEBUG, EINVAL, PS_MSG_INVALID_ENTRY, + "conf == null!!!"); + goto out; + } + + /* + * For some of the auth/rpc stuff, we need to operate on the correct + * child, but for other stuff we need to operate on the server + * translator itself. + */ + kid = NULL; + if (dict_get_str_sizen(options, "auth-path", &auth_path) == 0) { + kid = get_xlator_by_name(this, auth_path); + } + if (!kid) { + kid = this; + } + + if (dict_get_int32_sizen(options, "inode-lru-limit", &inode_lru_limit) == + 0) { + conf->inode_lru_limit = inode_lru_limit; + gf_msg_trace(this->name, 0, + "Reconfigured inode-lru-limit to " + "%d", + conf->inode_lru_limit); + + /* traverse through the xlator graph. For each xlator in the + graph check whether it is a bound_xl or not (bound_xl means + the xlator will have its itable pointer set). If so, then + set the lru limit for the itable. + */ + xlator_foreach(this, xlator_set_inode_lru_limit, &inode_lru_limit); + } + + data = dict_get_sizen(options, "trace"); + if (data) { + ret = gf_string2boolean(data->data, &trace); if (ret != 0) { - gf_log (this->name, GF_LOG_ERROR, "Memory accounting init" - "failed"); - return ret; + gf_smsg(this->name, GF_LOG_WARNING, EINVAL, PS_MSG_INVALID_ENTRY, + NULL); + ret = -1; + goto out; + } + conf->trace = trace; + gf_msg_trace(this->name, 0, "Reconfigured trace to %d", conf->trace); + } + + GF_OPTION_RECONF("statedump-path", statedump_path, options, path, do_auth); + if (!statedump_path) { + gf_smsg(this->name, GF_LOG_ERROR, 0, PS_MSG_STATEDUMP_PATH_ERROR, NULL); + goto do_auth; + } + gf_path_strip_trailing_slashes(statedump_path); + GF_FREE(this->ctx->statedump_path); + this->ctx->statedump_path = gf_strdup(statedump_path); + +do_auth: + if (!conf->auth_modules) + conf->auth_modules = dict_new(); + + dict_foreach(options, get_auth_types, conf->auth_modules); + ret = validate_auth_options(kid, options); + if (ret == -1) { + /* logging already done in validate_auth_options function. */ + goto out; + } + + dict_foreach(kid->options, _delete_auth_opt, NULL); + dict_foreach(options, _copy_auth_opt, kid->options); + + ret = gf_auth_init(kid, conf->auth_modules); + if (ret) { + dict_unref(conf->auth_modules); + goto out; + } + + GF_OPTION_RECONF("manage-gids", conf->server_manage_gids, options, bool, + do_rpc); + + GF_OPTION_RECONF("gid-timeout", conf->gid_cache_timeout, options, int32, + do_rpc); + if (gid_cache_reconf(&conf->gid_cache, conf->gid_cache_timeout) < 0) { + gf_smsg(this->name, GF_LOG_ERROR, 0, PS_MSG_GRP_CACHE_ERROR, NULL); + goto do_rpc; + } + +do_rpc: + rpc_conf = conf->rpc; + if (!rpc_conf) { + gf_smsg(this->name, GF_LOG_ERROR, 0, PS_MSG_RPC_CONF_ERROR, NULL); + goto out; + } + + ret = rpcsvc_auth_reconf(rpc_conf, options); + if (ret == -1) { + gf_log(GF_RPCSVC, GF_LOG_ERROR, "Failed to reconfigure authentication"); + goto out; + } + + GF_OPTION_RECONF("strict-auth-accept", conf->strict_auth_enabled, options, + bool, out); + + GF_OPTION_RECONF("dynamic-auth", conf->dync_auth, options, bool, out); + + if (conf->dync_auth) { + pthread_mutex_lock(&conf->mutex); + { + /* + * Disconnecting will (usually) drop the last ref, + * which will cause the transport to be unlinked and + * freed while we're still traversing, which will cause + * us to crash unless we use list_for_each_entry_safe. + */ + list_for_each_entry_safe(xprt, xp_next, &conf->xprt_list, list) + { + /* check for client authorization */ + if (!xprt->clnt_options) { + /* If clnt_options dictionary is null, + * which means for this transport + * server_setvolume was not called. + * + * So here we can skip authentication + * because server_setvolume will do + * gf_authenticate. + * + */ + continue; + } + /* + * Make sure we're only operating on + * connections that are relevant to the brick + * we're reconfiguring. + */ + if (dict_get_str_sizen(xprt->clnt_options, "remote-subvolume", + &xprt_path) != 0) { + continue; + } + if (strcmp(xprt_path, auth_path) != 0) { + continue; + } + ret = gf_authenticate(xprt->clnt_options, options, + conf->auth_modules); + if (ret == AUTH_ACCEPT) { + gf_smsg(kid->name, GF_LOG_TRACE, 0, PS_MSG_CLIENT_ACCEPTED, + NULL); + } else { + gf_event(EVENT_CLIENT_AUTH_REJECT, + "client_uid=%s;" + "client_identifier=%s;" + "server_identifier=%s;" + "brick_path=%s", + xprt->xl_private->client_uid, + xprt->peerinfo.identifier, xprt->myinfo.identifier, + auth_path); + gf_smsg(this->name, GF_LOG_INFO, EACCES, + PS_MSG_UNAUTHORIZED_CLIENT, + "peerinfo-identifier=%s", xprt->peerinfo.identifier, + NULL); + rpc_transport_disconnect(xprt, _gf_false); + } + } + } + pthread_mutex_unlock(&conf->mutex); + } + + ret = rpcsvc_set_outstanding_rpc_limit( + rpc_conf, options, RPCSVC_DEFAULT_OUTSTANDING_RPC_LIMIT); + if (ret < 0) { + gf_smsg(this->name, GF_LOG_ERROR, 0, PS_MSG_RECONFIGURE_FAILED, NULL); + goto out; + } + + list_for_each_entry(listeners, &(rpc_conf->listeners), list) + { + if (listeners->trans != NULL) { + if (listeners->trans->reconfigure) + listeners->trans->reconfigure(listeners->trans, options); + else + gf_smsg(this->name, GF_LOG_ERROR, 0, PS_MSG_TRANSPORT_ERROR, + NULL); } + } - return ret; + /* + * Update: + * We don't need to reset auto_thread_count since it has been derived + * out of the total bricks attached. We can reconfigure event threads + * but not auto threads. + */ + + GF_OPTION_RECONF("event-threads", new_nthread, options, int32, out); + ret = server_check_event_threads(this, conf, new_nthread); + if (ret) + goto out; + +out: + THIS = oldTHIS; + gf_msg_debug("", 0, "returning %d", ret); + return ret; } -int -init (xlator_t *this) +static int32_t +client_destroy_cbk(xlator_t *this, client_t *client) { - int32_t ret = -1; - server_conf_t *conf = NULL; - rpcsvc_listener_t *listener = NULL; + void *tmp = NULL; + server_ctx_t *ctx = NULL; - if (!this) - goto out; + client_ctx_del(client, this, &tmp); - if (this->children == NULL) { - gf_log (this->name, GF_LOG_ERROR, - "protocol/server should have subvolume"); - goto out; - } + ctx = tmp; - if (this->parents != NULL) { - gf_log (this->name, GF_LOG_ERROR, - "protocol/server should not have parent volumes"); - goto out; - } + if (ctx == NULL) + return 0; - conf = GF_CALLOC (1, sizeof (server_conf_t), gf_server_mt_server_conf_t); - GF_VALIDATE_OR_GOTO(this->name, conf, out); + gf_fd_fdtable_destroy(ctx->fdtable); + LOCK_DESTROY(&ctx->fdtable_lock); + GF_FREE(ctx); - INIT_LIST_HEAD (&conf->conns); - INIT_LIST_HEAD (&conf->xprt_list); - pthread_mutex_init (&conf->mutex, NULL); + return 0; +} - this->private = conf; +int32_t +server_dump_metrics(xlator_t *this, int fd) +{ + rpc_transport_t *xprt = NULL; + server_conf_t *conf = NULL; + client_t *client = NULL; - ret = server_build_config (this, conf); - if (ret) - goto out; + conf = this->private; - ret = dict_get_str (this->options, "config-directory", &conf->conf_dir); - if (ret) - conf->conf_dir = CONFDIR; + pthread_mutex_lock(&conf->mutex); - /* Authentication modules */ - conf->auth_modules = dict_new (); - GF_VALIDATE_OR_GOTO(this->name, conf->auth_modules, out); + list_for_each_entry(xprt, &conf->xprt_list, list) + { + client = xprt->xl_private; - dict_foreach (this->options, get_auth_types, conf->auth_modules); - ret = validate_auth_options (this, this->options); - if (ret == -1) { - /* logging already done in validate_auth_options function. */ - goto out; - } + if (!client) + continue; - ret = gf_auth_init (this, conf->auth_modules); - if (ret) { - dict_unref (conf->auth_modules); - goto out; - } + dprintf(fd, "%s.total.rpc.%s.bytes_read %" PRIu64 "\n", this->name, + client->client_uid, xprt->total_bytes_read); + dprintf(fd, "%s.total.rpc.%s.bytes_write %" PRIu64 "\n", this->name, + client->client_uid, xprt->total_bytes_write); + dprintf(fd, "%s.total.rpc.%s.outstanding %d\n", this->name, + client->client_uid, xprt->outstanding_rpc_count); + } - /* RPC related */ - //conf->rpc = rpc_svc_init (&conf->rpc_conf); - conf->rpc = rpcsvc_init (this->ctx, this->options); - if (conf->rpc == NULL) { - ret = -1; - goto out; - } + pthread_mutex_unlock(&conf->mutex); - ret = rpcsvc_create_listeners (conf->rpc, this->options, - this->name); - if (ret < 1) { - gf_log (this->name, GF_LOG_DEBUG, - "creation of listener failed"); - ret = -1; - goto out; - } + return 0; +} - ret = rpcsvc_register_notify (conf->rpc, server_rpc_notify, this); - if (ret) { - gf_log (this->name, GF_LOG_DEBUG, - "registration of notify with rpcsvc failed"); - goto out; - } +void +server_cleanup(xlator_t *this, server_conf_t *conf) +{ + if (!this || !conf) + return; - glusterfs3_1_fop_prog.options = this->options; - ret = rpcsvc_program_register (conf->rpc, &glusterfs3_1_fop_prog); - if (ret) { - gf_log (this->name, GF_LOG_DEBUG, - "registration of program (name:%s, prognum:%d, " - "progver:%d) failed", glusterfs3_1_fop_prog.progname, - glusterfs3_1_fop_prog.prognum, - glusterfs3_1_fop_prog.progver); - goto out; - } + LOCK_DESTROY(&conf->itable_lock); + pthread_mutex_destroy(&conf->mutex); + + if (this->ctx->event_pool) { + /* Free the event pool */ + (void)gf_event_pool_destroy(this->ctx->event_pool); + } + + if (dict_get_sizen(this->options, "config-directory")) { + GF_FREE(conf->conf_dir); + conf->conf_dir = NULL; + } + + if (conf->child_status) { + GF_FREE(conf->child_status); + conf->child_status = NULL; + } + + if (this->ctx->statedump_path) { + GF_FREE(this->ctx->statedump_path); + this->ctx->statedump_path = NULL; + } + + if (conf->auth_modules) { + gf_auth_fini(conf->auth_modules); + dict_unref(conf->auth_modules); + } + + if (conf->rpc) { + (void)rpcsvc_destroy(conf->rpc); + conf->rpc = NULL; + } + + GF_FREE(conf); + this->private = NULL; +} - gluster_handshake_prog.options = this->options; - ret = rpcsvc_program_register (conf->rpc, &gluster_handshake_prog); - if (ret) { - gf_log (this->name, GF_LOG_DEBUG, - "registration of program (name:%s, prognum:%d, " - "progver:%d) failed", gluster_handshake_prog.progname, - gluster_handshake_prog.prognum, - gluster_handshake_prog.progver); - rpcsvc_program_unregister (conf->rpc, &glusterfs3_1_fop_prog); - goto out; - } +int +server_init(xlator_t *this) +{ + int32_t ret = -1; + server_conf_t *conf = NULL; + char *transport_type = NULL; + char *statedump_path = NULL; + int total_transport = 0; + + GF_VALIDATE_OR_GOTO("init", this, out); + + if (this->children == NULL) { + gf_smsg(this->name, GF_LOG_ERROR, 0, PS_MSG_SUBVOL_NULL, NULL); + goto out; + } + + if (this->parents != NULL) { + gf_smsg(this->name, GF_LOG_ERROR, 0, PS_MSG_PARENT_VOL_ERROR, NULL); + goto out; + } + + conf = GF_CALLOC(1, sizeof(server_conf_t), gf_server_mt_server_conf_t); + + GF_VALIDATE_OR_GOTO(this->name, conf, out); + + INIT_LIST_HEAD(&conf->xprt_list); + pthread_mutex_init(&conf->mutex, NULL); + + LOCK_INIT(&conf->itable_lock); + + /* Set event threads to the configured default */ + GF_OPTION_INIT("event-threads", conf->event_threads, int32, out); + ret = server_check_event_threads(this, conf, conf->event_threads); + if (ret) + goto out; + + ret = server_build_config(this, conf); + if (ret) + goto out; + + ret = dict_get_str_sizen(this->options, "config-directory", + &conf->conf_dir); + if (ret) + conf->conf_dir = CONFDIR; + + conf->child_status = GF_CALLOC(1, sizeof(struct _child_status), + gf_server_mt_child_status); + INIT_LIST_HEAD(&conf->child_status->status_list); + + GF_OPTION_INIT("statedump-path", statedump_path, path, out); + if (statedump_path) { + gf_path_strip_trailing_slashes(statedump_path); + this->ctx->statedump_path = gf_strdup(statedump_path); + } else { + gf_smsg(this->name, GF_LOG_ERROR, 0, PS_MSG_SET_STATEDUMP_PATH_ERROR, + NULL); + ret = -1; + goto out; + } + + /* Authentication modules */ + conf->auth_modules = dict_new(); + GF_VALIDATE_OR_GOTO(this->name, conf->auth_modules, out); + + dict_foreach(this->options, get_auth_types, conf->auth_modules); + ret = validate_auth_options(this, this->options); + if (ret == -1) { + /* logging already done in validate_auth_options function. */ + goto out; + } + + ret = gf_auth_init(this, conf->auth_modules); + if (ret) { + dict_unref(conf->auth_modules); + conf->auth_modules = NULL; + goto out; + } + + ret = dict_get_str_boolean(this->options, "manage-gids", _gf_false); + if (ret == -1) + conf->server_manage_gids = _gf_false; + else + conf->server_manage_gids = ret; + + GF_OPTION_INIT("gid-timeout", conf->gid_cache_timeout, int32, out); + if (gid_cache_init(&conf->gid_cache, conf->gid_cache_timeout) < 0) { + gf_smsg(this->name, GF_LOG_ERROR, 0, PS_MSG_INIT_GRP_CACHE_ERROR, NULL); + goto out; + } + + ret = dict_get_str_boolean(this->options, "strict-auth-accept", _gf_false); + if (ret == -1) + conf->strict_auth_enabled = _gf_false; + else + conf->strict_auth_enabled = ret; + + ret = dict_get_str_boolean(this->options, "dynamic-auth", _gf_true); + if (ret == -1) + conf->dync_auth = _gf_true; + else + conf->dync_auth = ret; + + /* RPC related */ + conf->rpc = rpcsvc_init(this, this->ctx, this->options, 0); + if (conf->rpc == NULL) { + gf_smsg(this->name, GF_LOG_ERROR, 0, PS_MSG_RPCSVC_CREATE_FAILED, NULL); + ret = -1; + goto out; + } + + ret = rpcsvc_set_outstanding_rpc_limit( + conf->rpc, this->options, RPCSVC_DEFAULT_OUTSTANDING_RPC_LIMIT); + if (ret < 0) { + gf_smsg(this->name, GF_LOG_ERROR, 0, PS_MSG_RPC_CONFIGURE_FAILED, NULL); + goto out; + } + + /* + * This is the only place where we want secure_srvr to reflect + * the data-plane setting. + */ + this->ctx->secure_srvr = MGMT_SSL_COPY_IO; + + ret = dict_get_str_sizen(this->options, "transport-type", &transport_type); + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, 0, PS_MSG_TRANSPORT_TYPE_NOT_SET, + NULL); + ret = -1; + goto out; + } + total_transport = rpc_transport_count(transport_type); + if (total_transport <= 0) { + gf_smsg(this->name, GF_LOG_ERROR, 0, + PS_MSG_GET_TOTAL_AVAIL_TRANSPORT_FAILED, NULL); + ret = -1; + goto out; + } + + ret = dict_set_int32_sizen(this->options, "notify-poller-death", 1); + + ret = rpcsvc_create_listeners(conf->rpc, this->options, this->name); + if (ret < 1) { + gf_smsg(this->name, GF_LOG_WARNING, 0, + PS_MSG_RPCSVC_LISTENER_CREATE_FAILED, NULL); + if (ret != -EADDRINUSE) + ret = -1; + goto out; + } else if (ret < total_transport) { + gf_smsg(this->name, GF_LOG_ERROR, 0, + PS_MSG_RPCSVC_LISTENER_CREATE_FAILED, "number=%d", + "continuing with succeeded transport", (total_transport - ret), + NULL); + } + + ret = rpcsvc_register_notify(conf->rpc, server_rpc_notify, this); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PS_MSG_RPCSVC_NOTIFY, NULL); + goto out; + } + + glusterfs3_3_fop_prog.options = this->options; + /* make sure we register the fop program at the head to optimize + * lookup + */ + ret = rpcsvc_program_register(conf->rpc, &glusterfs3_3_fop_prog, _gf_true); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PS_MSG_PGM_REG_FAILED, "name=%s", + glusterfs3_3_fop_prog.progname, "prognum=%d", + glusterfs3_3_fop_prog.prognum, "progver=%d", + glusterfs3_3_fop_prog.progver, NULL); + goto out; + } + + glusterfs4_0_fop_prog.options = this->options; + ret = rpcsvc_program_register(conf->rpc, &glusterfs4_0_fop_prog, _gf_true); + if (ret) { + gf_log(this->name, GF_LOG_WARNING, + "registration of program (name:%s, prognum:%d, " + "progver:%d) failed", + glusterfs4_0_fop_prog.progname, glusterfs4_0_fop_prog.prognum, + glusterfs4_0_fop_prog.progver); + rpcsvc_program_unregister(conf->rpc, &glusterfs3_3_fop_prog); + goto out; + } + + gluster_handshake_prog.options = this->options; + ret = rpcsvc_program_register(conf->rpc, &gluster_handshake_prog, + _gf_false); + if (ret) { + gf_smsg(this->name, GF_LOG_WARNING, 0, PS_MSG_PGM_REG_FAILED, "name=%s", + gluster_handshake_prog.progname, "prognum=%d", + gluster_handshake_prog.prognum, "progver=%d", + gluster_handshake_prog.progver, NULL); + rpcsvc_program_unregister(conf->rpc, &glusterfs3_3_fop_prog); + rpcsvc_program_unregister(conf->rpc, &glusterfs4_0_fop_prog); + goto out; + } #ifndef GF_DARWIN_HOST_OS - { - struct rlimit lim; - - lim.rlim_cur = 1048576; - lim.rlim_max = 1048576; - - if (setrlimit (RLIMIT_NOFILE, &lim) == -1) { - gf_log (this->name, GF_LOG_WARNING, - "WARNING: Failed to set 'ulimit -n 1M': %s", - strerror(errno)); - lim.rlim_cur = 65536; - lim.rlim_max = 65536; - - if (setrlimit (RLIMIT_NOFILE, &lim) == -1) { - gf_log (this->name, GF_LOG_WARNING, - "Failed to set max open fd to 64k: %s", - strerror(errno)); - } else { - gf_log (this->name, GF_LOG_TRACE, - "max open fd set to 64k"); - } - } + { + struct rlimit lim; + + lim.rlim_cur = 1048576; + lim.rlim_max = 1048576; + + if (setrlimit(RLIMIT_NOFILE, &lim) == -1) { + gf_smsg(this->name, GF_LOG_WARNING, errno, PS_MSG_ULIMIT_SET_FAILED, + "errno=%s", strerror(errno), NULL); + lim.rlim_cur = 65536; + lim.rlim_max = 65536; + + if (setrlimit(RLIMIT_NOFILE, &lim) == -1) { + gf_smsg(this->name, GF_LOG_WARNING, errno, PS_MSG_FD_NOT_FOUND, + "errno=%s", strerror(errno), NULL); + } else { + gf_msg_trace(this->name, 0, + "max open fd set " + "to 64k"); + } } + } #endif + if (!this->ctx->cmd_args.volfile_id) { + /* In some use cases this is a valid case, but + document this to be annoying log in that case */ + gf_smsg(this->name, GF_LOG_WARNING, EINVAL, PS_MSG_VOL_FILE_OPEN_FAILED, + NULL); + this->ctx->cmd_args.volfile_id = gf_strdup("gluster"); + } + FIRST_CHILD(this)->volfile_id = gf_strdup(this->ctx->cmd_args.volfile_id); + + this->private = conf; + ret = 0; - ret = 0; out: - if (ret) { - if (this != NULL) { - this->fini (this); - } - - if (listener != NULL) { - rpcsvc_listener_destroy (listener); - } + if (ret) { + if (this != NULL) { + this->fini(this); } + server_cleanup(this, conf); + } - return ret; + return ret; } - void -fini (xlator_t *this) +server_fini(xlator_t *this) { +#if 0 server_conf_t *conf = NULL; conf = this->private; @@ -612,10 +1288,10 @@ fini (xlator_t *this) if (conf->rpc) { /* TODO: memory leak here, have to free RPC */ /* - if (conf->rpc->conn) { - rpcsvc_conn_destroy (conf->rpc->conn); - } - rpcsvc_fini (conf->rpc); + if (conf->rpc->conn) { + rpcsvc_conn_destroy (conf->rpc->conn); + } + rpcsvc_fini (conf->rpc); */ ; } @@ -627,69 +1303,585 @@ fini (xlator_t *this) } this->private = NULL; - - return; +#endif + return; } int -notify (xlator_t *this, int32_t event, void *data, ...) +server_process_event_upcall(xlator_t *this, void *data) { - int ret = 0; - switch (event) { + int ret = -1; + server_conf_t *conf = NULL; + client_t *client = NULL; + char *client_uid = NULL; + struct gf_upcall *upcall_data = NULL; + void *up_req = NULL; + rpc_transport_t *xprt = NULL; + enum gf_cbk_procnum cbk_procnum = GF_CBK_NULL; + gfs3_cbk_cache_invalidation_req gf_c_req = { + 0, + }; + gfs3_recall_lease_req gf_recall_lease = { + { + 0, + }, + }; + gfs4_inodelk_contention_req gf_inodelk_contention = { + {0}, + }; + gfs4_entrylk_contention_req gf_entrylk_contention = { + {0}, + }; + xdrproc_t xdrproc; + + GF_VALIDATE_OR_GOTO(this->name, data, out); + + conf = this->private; + GF_VALIDATE_OR_GOTO(this->name, conf, out); + + upcall_data = (struct gf_upcall *)data; + client_uid = upcall_data->client_uid; + /* client_uid could be NULL if the upcall was intended for a server's + * child xlator (so no client_uid available) but it hasn't handled + * the notification. For this reason we silently ignore any upcall + * request with a NULL client_uid, but -1 will be returned. + */ + if (client_uid == NULL) { + gf_msg_debug(this->name, 0, "NULL client_uid for an upcall request"); + goto out; + } + + switch (upcall_data->event_type) { + case GF_UPCALL_CACHE_INVALIDATION: + ret = gf_proto_cache_invalidation_from_upcall(this, &gf_c_req, + upcall_data); + if (ret < 0) + goto out; + + up_req = &gf_c_req; + cbk_procnum = GF_CBK_CACHE_INVALIDATION; + xdrproc = (xdrproc_t)xdr_gfs3_cbk_cache_invalidation_req; + break; + case GF_UPCALL_RECALL_LEASE: + ret = gf_proto_recall_lease_from_upcall(this, &gf_recall_lease, + upcall_data); + if (ret < 0) + goto out; + + up_req = &gf_recall_lease; + cbk_procnum = GF_CBK_RECALL_LEASE; + xdrproc = (xdrproc_t)xdr_gfs3_recall_lease_req; + break; + case GF_UPCALL_INODELK_CONTENTION: + ret = gf_proto_inodelk_contention_from_upcall( + this, &gf_inodelk_contention, upcall_data); + if (ret < 0) + goto out; + + up_req = &gf_inodelk_contention; + cbk_procnum = GF_CBK_INODELK_CONTENTION; + xdrproc = (xdrproc_t)xdr_gfs4_inodelk_contention_req; + break; + case GF_UPCALL_ENTRYLK_CONTENTION: + ret = gf_proto_entrylk_contention_from_upcall( + this, &gf_entrylk_contention, upcall_data); + if (ret < 0) + goto out; + + up_req = &gf_entrylk_contention; + cbk_procnum = GF_CBK_ENTRYLK_CONTENTION; + xdrproc = (xdrproc_t)xdr_gfs4_entrylk_contention_req; + break; default: - default_notify (this, event, data); - break; + gf_smsg(this->name, GF_LOG_WARNING, EINVAL, + PS_MSG_INVLAID_UPCALL_EVENT, "event-type=%d", + upcall_data->event_type, NULL); + goto out; + } + + pthread_mutex_lock(&conf->mutex); + { + list_for_each_entry(xprt, &conf->xprt_list, list) + { + client = xprt->xl_private; + + /* 'client' is not atomically added during xprt entry + * addition to the list. */ + if (!client || strcmp(client->client_uid, client_uid)) + continue; + + ret = rpcsvc_request_submit(conf->rpc, xprt, &server_cbk_prog, + cbk_procnum, up_req, this->ctx, + xdrproc); + if (ret < 0) { + gf_msg_debug(this->name, 0, + "Failed to send " + "upcall to client:%s upcall " + "event:%d", + client_uid, upcall_data->event_type); + } + break; } + } + pthread_mutex_unlock(&conf->mutex); + ret = 0; +out: + GF_FREE((gf_c_req.xdata).xdata_val); + GF_FREE((gf_recall_lease.xdata).xdata_val); + GF_FREE((gf_inodelk_contention.xdata).xdata_val); + GF_FREE((gf_entrylk_contention.xdata).xdata_val); - return ret; + return ret; } +int +server_process_child_event(xlator_t *this, int32_t event, void *data, + enum gf_cbk_procnum cbk_procnum) +{ + int ret = -1; + server_conf_t *conf = NULL; + rpc_transport_t *xprt = NULL; + xlator_t *victim = NULL; + struct _child_status *tmp = NULL; + + GF_VALIDATE_OR_GOTO(this->name, data, out); + + conf = this->private; + GF_VALIDATE_OR_GOTO(this->name, conf, out); + + victim = data; + pthread_mutex_lock(&conf->mutex); + { + if (cbk_procnum == GF_CBK_CHILD_UP) { + list_for_each_entry(tmp, &conf->child_status->status_list, + status_list) + { + if (tmp->name == NULL) + break; + if (strcmp(tmp->name, victim->name) == 0) + break; + } + if (tmp->name) { + tmp->child_up = _gf_true; + } else { + tmp = GF_CALLOC(1, sizeof(struct _child_status), + gf_server_mt_child_status); + INIT_LIST_HEAD(&tmp->status_list); + tmp->name = gf_strdup(victim->name); + tmp->child_up = _gf_true; + memcpy(tmp->volume_id, victim->graph->volume_id, + GF_UUID_BUF_SIZE); + list_add_tail(&tmp->status_list, + &conf->child_status->status_list); + } + } -struct xlator_fops fops = { -}; + if (cbk_procnum == GF_CBK_CHILD_DOWN) { + list_for_each_entry(tmp, &conf->child_status->status_list, + status_list) + { + if (strcmp(tmp->name, victim->name) == 0) { + tmp->child_up = _gf_false; + break; + } + } -struct xlator_cbks cbks = { -}; + if (!tmp->name) + gf_smsg(this->name, GF_LOG_ERROR, 0, PS_MSG_CHILD_STATUS_FAILED, + "name=%s", victim->name, NULL); + } + list_for_each_entry(xprt, &conf->xprt_list, list) + { + if (!xprt->xl_private) { + continue; + } + if (xprt->xl_private->bound_xl == data) { + rpcsvc_callback_submit(conf->rpc, xprt, &server_cbk_prog, + cbk_procnum, NULL, 0, NULL); + } + } + } + pthread_mutex_unlock(&conf->mutex); + ret = 0; +out: + return ret; +} + +int +server_notify(xlator_t *this, int32_t event, void *data, ...) +{ + int ret = -1; + server_conf_t *conf = NULL; + rpc_transport_t *xprt = NULL; + rpc_transport_t *xp_next = NULL; + xlator_t *victim = NULL; + xlator_t *top = NULL; + xlator_t *travxl = NULL; + xlator_list_t **trav_p = NULL; + struct _child_status *tmp = NULL; + gf_boolean_t victim_found = _gf_false; + glusterfs_ctx_t *ctx = NULL; + gf_boolean_t xprt_found = _gf_false; + uint64_t totxprt = 0; + uint64_t totdisconnect = 0; + + GF_VALIDATE_OR_GOTO(THIS->name, this, out); + conf = this->private; + GF_VALIDATE_OR_GOTO(this->name, conf, out); + victim = data; + ctx = THIS->ctx; + + switch (event) { + case GF_EVENT_UPCALL: { + GF_VALIDATE_OR_GOTO(this->name, data, out); + + ret = server_process_event_upcall(this, data); + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, 0, + PS_MSG_SERVER_EVENT_UPCALL_FAILED, NULL); + goto out; + } + break; + } + + case GF_EVENT_PARENT_UP: { + conf = this->private; + + conf->parent_up = _gf_true; + + default_notify(this, event, data); + break; + } + + case GF_EVENT_CHILD_UP: { + ret = server_process_child_event(this, event, data, + GF_CBK_CHILD_UP); + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, 0, + PS_MSG_SERVER_CHILD_EVENT_FAILED, NULL); + goto out; + } + default_notify(this, event, data); + break; + } + + case GF_EVENT_CHILD_DOWN: { + if (victim->cleanup_starting) { + victim->notify_down = 1; + gf_log(this->name, GF_LOG_INFO, + "Getting CHILD_DOWN event for brick %s", victim->name); + } + + ret = server_process_child_event(this, event, data, + GF_CBK_CHILD_DOWN); + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, 0, + PS_MSG_SERVER_CHILD_EVENT_FAILED, NULL); + goto out; + } + default_notify(this, event, data); + break; + } -struct xlator_dumpops dumpops = { - .priv = server_priv, - .fd = server_fd, - .inode = server_inode, + case GF_EVENT_CLEANUP: + conf = this->private; + pthread_mutex_lock(&conf->mutex); + /* Calculate total no. of xprt available in list for this + brick xlator + */ + list_for_each_entry_safe(xprt, xp_next, &conf->xprt_list, list) + { + if (!xprt->xl_private) { + continue; + } + + if (GF_ATOMIC_GET(xprt->disconnect_progress)) + continue; + + if (xprt->xl_private->bound_xl == data) { + totxprt++; + } + } + + list_for_each_entry(tmp, &conf->child_status->status_list, + status_list) + { + if (strcmp(tmp->name, victim->name) == 0) { + tmp->child_up = _gf_false; + GF_ATOMIC_INIT(victim->xprtrefcnt, totxprt); + break; + } + } + + /* + * Disconnecting will (usually) drop the last ref, which will + * cause the transport to be unlinked and freed while we're + * still traversing, which will cause us to crash unless we use + * list_for_each_entry_safe. + */ + list_for_each_entry_safe(xprt, xp_next, &conf->xprt_list, list) + { + if (!xprt->xl_private) { + continue; + } + + if (GF_ATOMIC_GET(xprt->disconnect_progress)) + continue; + + if (xprt->xl_private->bound_xl == data) { + gf_log(this->name, GF_LOG_INFO, "disconnecting %s", + xprt->peerinfo.identifier); + xprt_found = _gf_true; + totdisconnect++; + rpc_transport_disconnect(xprt, _gf_false); + } + } + + if (totxprt > totdisconnect) + GF_ATOMIC_SUB(victim->xprtrefcnt, (totxprt - totdisconnect)); + + pthread_mutex_unlock(&conf->mutex); + if (this->ctx->active) { + top = this->ctx->active->first; + LOCK(&ctx->volfile_lock); + for (trav_p = &top->children; *trav_p; + trav_p = &(*trav_p)->next) { + travxl = (*trav_p)->xlator; + if (!travxl->call_cleanup && + strcmp(travxl->name, victim->name) == 0) { + victim_found = _gf_true; + break; + } + } + if (victim_found) + glusterfs_delete_volfile_checksum(ctx, victim->volfile_id); + UNLOCK(&ctx->volfile_lock); + + rpc_clnt_mgmt_pmap_signout(ctx, victim->name); + + if (!xprt_found && victim_found) { + server_call_xlator_mem_cleanup(this, victim->name); + } + } + break; + + default: + default_notify(this, event, data); + break; + } + ret = 0; +out: + return ret; +} + +struct xlator_fops server_fops; + +struct xlator_cbks server_cbks = { + .client_destroy = client_destroy_cbk, }; +struct xlator_dumpops server_dumpops = { + .priv = server_priv, + .fd = gf_client_dump_fdtables, + .inode = gf_client_dump_inodes, + .priv_to_dict = server_priv_to_dict, + .fd_to_dict = gf_client_dump_fdtables_to_dict, + .inode_to_dict = gf_client_dump_inodes_to_dict, +}; -struct volume_options options[] = { - { .key = {"transport-type"}, - .value = {"rpc", "rpc-over-rdma", "tcp", "socket", "ib-verbs", - "unix", "ib-sdp", "tcp/server", "ib-verbs/server", "rdma", - "rdma*([ \t]),*([ \t])socket", - "socket*([ \t]),*([ \t])rdma"}, - .type = GF_OPTION_TYPE_STR - }, - { .key = {"volume-filename.*"}, - .type = GF_OPTION_TYPE_PATH, - }, - { .key = {"transport.*"}, - .type = GF_OPTION_TYPE_ANY, - }, - { .key = {"rpc*"}, - .type = GF_OPTION_TYPE_ANY, - }, - { .key = {"inode-lru-limit"}, - .type = GF_OPTION_TYPE_INT, - .min = 0, - .max = (1 * GF_UNIT_MB) - }, - { .key = {"verify-volfile-checksum"}, - .type = GF_OPTION_TYPE_BOOL - }, - { .key = {"trace"}, - .type = GF_OPTION_TYPE_BOOL - }, - { .key = {"config-directory", - "conf-dir"}, - .type = GF_OPTION_TYPE_PATH, - }, +struct volume_options server_options[] = { + {.key = {"transport-type"}, + .value = {"rpc", "rpc-over-rdma", "tcp", "socket", "ib-verbs", "unix", + "ib-sdp", "tcp/server", "ib-verbs/server", "rdma", + "rdma*([ \t]),*([ \t])socket", "rdma*([ \t]),*([ \t])tcp", + "tcp*([ \t]),*([ \t])rdma", "socket*([ \t]),*([ \t])rdma"}, + .type = GF_OPTION_TYPE_STR, + .default_value = "{{ volume.transport }}"}, + { + .key = {"transport.listen-backlog"}, + .type = GF_OPTION_TYPE_INT, + .default_value = "10", + }, + { + .key = {"volume-filename.*"}, + .type = GF_OPTION_TYPE_PATH, + }, + { + .key = {"transport.tcp-user-timeout"}, + .type = GF_OPTION_TYPE_TIME, + .min = 0, + .max = 1013, + .default_value = TOSTRING(GF_NETWORK_TIMEOUT), + }, + { + .key = {"transport.*"}, + .type = GF_OPTION_TYPE_ANY, + }, + {.key = {"inode-lru-limit"}, + .type = GF_OPTION_TYPE_INT, + .min = 0, + .max = 1048576, + .default_value = "16384", + .description = "Specifies the limit on the number of inodes " + "in the lru list of the inode cache.", + .op_version = {1}, + .flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC}, + {.key = {"trace"}, .type = GF_OPTION_TYPE_BOOL}, + { + .key = {"config-directory", "conf-dir"}, + .type = GF_OPTION_TYPE_PATH, + }, + {.key = {"rpc-auth-allow-insecure", "allow-insecure"}, + .type = GF_OPTION_TYPE_BOOL, + .default_value = "on", + .op_version = {1}, + .flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC}, + {.key = {"root-squash"}, + .type = GF_OPTION_TYPE_BOOL, + .default_value = "off", + .description = "Map requests from uid/gid 0 to the anonymous " + "uid/gid. Note that this does not apply to any other " + "uids or gids that might be equally sensitive, such " + "as user bin or group staff.", + .op_version = {2}, + .flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC}, + {.key = {"all-squash"}, + .type = GF_OPTION_TYPE_BOOL, + .default_value = "off", + .description = "Map requests from any uid/gid to the anonymous " + "uid/gid. Note that this does not apply to any other " + "uids or gids that might be equally sensitive, such " + "as user bin or group staff.", + .op_version = {GD_OP_VERSION_6_0}, + .flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC}, + {.key = {"anonuid"}, + .type = GF_OPTION_TYPE_INT, + .default_value = "65534", /* RPC_NOBODY_UID */ + .min = 0, + .max = (uint32_t)-1, + .description = "value of the uid used for the anonymous " + "user/nfsnobody when root-squash/all-squash is enabled.", + .op_version = {3}, + .flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC}, + {.key = {"anongid"}, + .type = GF_OPTION_TYPE_INT, + .default_value = "65534", /* RPC_NOBODY_GID */ + .min = 0, + .max = (uint32_t)-1, + .description = "value of the gid used for the anonymous " + "user/nfsnobody when root-squash/all-squash is enabled.", + .op_version = {3}, + .flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC}, + {.key = {"statedump-path"}, + .type = GF_OPTION_TYPE_PATH, + .default_value = DEFAULT_VAR_RUN_DIRECTORY, + .description = "Specifies directory in which gluster should save its" + " statedumps.", + .op_version = {1}, + .flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC}, + {.key = {"tcp-window-size"}, + .type = GF_OPTION_TYPE_SIZET, + .min = GF_MIN_SOCKET_WINDOW_SIZE, + .max = GF_MAX_SOCKET_WINDOW_SIZE, + .description = "Specifies the window size for tcp socket.", + .op_version = {1}, + .flags = OPT_FLAG_SETTABLE}, + + /* The following two options are defined in addr.c, redifined here * + * for the sake of validation during volume set from cli */ + + {.key = {"auth.addr.*.allow", "auth.allow"}, + .setkey = "auth.addr.{{ brick.path }}.allow", + .default_value = "*", + .type = GF_OPTION_TYPE_INTERNET_ADDRESS_LIST, + .flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC, + .description = "Allow a comma separated list of addresses and/or " + "hostnames to connect to the server. Option " + "auth.reject overrides this option. By default, all " + "connections are allowed."}, + {.key = {"auth.addr.*.reject", "auth.reject"}, + .setkey = "auth.addr.{{ brick.path }}.reject", + .type = GF_OPTION_TYPE_INTERNET_ADDRESS_LIST, + .flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC, + .description = "Reject a comma separated list of addresses and/or " + "hostnames to connect to the server. This option " + "overrides the auth.allow option. By default, all" + " connections are allowed."}, + {.key = {"ssl-allow"}, + .setkey = "auth.login.{{ brick.path }}.ssl-allow", + .default_value = "*", + .type = GF_OPTION_TYPE_INTERNET_ADDRESS_LIST, + .flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC, + .description = "Allow a comma separated list of common names (CN) of" + "the clients that are allowed to access the server." + "By default, all TLS authenticated clients are" + "allowed to access the server."}, + /* This is not a valid path w.r.t daemons, hence it's string */ + {.key = {"auth-path"}, + .type = GF_OPTION_TYPE_STR, + .default_value = "{{ brick.path }}"}, + {.key = {"rpc.outstanding-rpc-limit"}, + .type = GF_OPTION_TYPE_INT, + .min = RPCSVC_MIN_OUTSTANDING_RPC_LIMIT, + .max = RPCSVC_MAX_OUTSTANDING_RPC_LIMIT, + .default_value = TOSTRING(RPCSVC_DEFAULT_OUTSTANDING_RPC_LIMIT), + .description = "Parameter to throttle the number of incoming RPC " + "requests from a client. 0 means no limit (can " + "potentially run out of memory)", + .op_version = {1}, + .flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC | OPT_FLAG_GLOBAL}, + {.key = {"manage-gids"}, + .type = GF_OPTION_TYPE_BOOL, + .default_value = "off", + .description = "Resolve groups on the server-side.", + .op_version = {GD_OP_VERSION_3_6_0}, + .flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC}, + {.key = {"gid-timeout"}, + .type = GF_OPTION_TYPE_INT, + .default_value = "300", + .description = "Timeout in seconds for the cached groups to expire.", + .op_version = {GD_OP_VERSION_3_6_0}, + .flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC}, + {.key = {"event-threads"}, + .type = GF_OPTION_TYPE_INT, + .min = 1, + .max = 1024, + .default_value = "2", + .description = "Specifies the number of event threads to execute " + "in parallel. Larger values would help process" + " responses faster, depending on available processing" + " power.", + .op_version = {GD_OP_VERSION_3_7_0}, + .flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC}, + {.key = {"dynamic-auth"}, + .type = GF_OPTION_TYPE_BOOL, + .default_value = "on", + .description = "When 'on' perform dynamic authentication of volume " + "options in order to allow/terminate client " + "transport connection immediately in response to " + "*.allow | *.reject volume set options.", + .op_version = {GD_OP_VERSION_3_7_5}, + .flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC}, + {.key = {"strict-auth-accept"}, + .type = GF_OPTION_TYPE_BOOL, + .default_value = "off", + .description = "strict-auth-accept reject connection with out" + "a valid username and password."}, + {.key = {NULL}}, +}; - { .key = {NULL} }, +xlator_api_t xlator_api = { + .init = server_init, + .fini = server_fini, + .notify = server_notify, + .reconfigure = server_reconfigure, + .mem_acct_init = server_mem_acct_init, + .dump_metrics = server_dump_metrics, + .op_version = {1}, /* Present from the initial version */ + .dumpops = &server_dumpops, + .fops = &server_fops, + .cbks = &server_cbks, + .options = server_options, + .identifier = "server", + .category = GF_MAINTAINED, }; diff --git a/xlators/protocol/server/src/server.h b/xlators/protocol/server/src/server.h index a86c6b31824..821290b62d8 100644 --- a/xlators/protocol/server/src/server.h +++ b/xlators/protocol/server/src/server.h @@ -1,20 +1,11 @@ /* - Copyright (c) 2010 Gluster, Inc. <http://www.gluster.com> + Copyright (c) 2010-2013 Red Hat, Inc. <http://www.redhat.com> This file is part of GlusterFS. - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. + 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. */ #ifndef _SERVER_H @@ -22,186 +13,210 @@ #include <pthread.h> +#include <glusterfs/fd.h> #include "rpcsvc.h" -#include "fd.h" +#include <glusterfs/fd.h> #include "protocol-common.h" #include "server-mem-types.h" -#include "glusterfs3-xdr.h" +#include "glusterfs3.h" +#include <glusterfs/timer.h> +#include <glusterfs/client_t.h> +#include <glusterfs/gidcache.h> +#include <glusterfs/defaults.h> +#include "authenticate.h" + +#define DEFAULT_BLOCK_SIZE 4194304 /* 4MB */ +#define DEFAULT_VOLUME_FILE_PATH CONFDIR "/glusterfs.vol" +#define GF_MAX_SOCKET_WINDOW_SIZE (1 * GF_UNIT_MB) +#define GF_MIN_SOCKET_WINDOW_SIZE (0) -#define DEFAULT_BLOCK_SIZE 4194304 /* 4MB */ -#define DEFAULT_VOLUME_FILE_PATH CONFDIR "/glusterfs.vol" +typedef enum { + INTERNAL_LOCKS = 1, + POSIX_LOCKS = 2, +} server_lock_flags_t; typedef struct _server_state server_state_t; -struct _locker { - struct list_head lockers; - char *volume; - loc_t loc; - fd_t *fd; - uint64_t owner; - pid_t pid; -}; - -struct _lock_table { - struct list_head file_lockers; - struct list_head dir_lockers; - gf_lock_t lock; - size_t count; -}; - - -/* private structure per connection (transport object) - * used as transport_t->xl_private - */ -struct _server_connection { - struct list_head list; - char *id; - int ref; - int active_transports; - pthread_mutex_t lock; - char disconnected; - fdtable_t *fdtable; - struct _lock_table *ltable; - xlator_t *bound_xl; - xlator_t *this; -}; - -typedef struct _server_connection server_connection_t; - - -server_connection_t * -server_connection_get (xlator_t *this, const char *id); - -void -server_connection_put (xlator_t *this, server_connection_t *conn); - int -server_connection_cleanup (xlator_t *this, server_connection_t *conn); - -int server_null (rpcsvc_request_t *req); +server_null(rpcsvc_request_t *req); struct _volfile_ctx { - struct _volfile_ctx *next; - char *key; - uint32_t checksum; + struct _volfile_ctx *next; + char *key; + uint32_t checksum; }; +struct _child_status { + struct list_head status_list; + char *name; + char volume_id[GF_UUID_BUF_SIZE]; + gf_boolean_t child_up; +}; struct server_conf { - rpcsvc_t *rpc; - struct rpcsvc_config rpc_conf; - int inode_lru_limit; - gf_boolean_t verify_volfile; - gf_boolean_t trace; - char *conf_dir; - struct _volfile_ctx *volfile; - - dict_t *auth_modules; - pthread_mutex_t mutex; - struct list_head conns; - struct list_head xprt_list; + rpcsvc_t *rpc; + struct rpcsvc_config rpc_conf; + int inode_lru_limit; + gf_boolean_t verify_volfile; + gf_boolean_t trace; + char *conf_dir; + struct _volfile_ctx *volfile; + dict_t *auth_modules; + pthread_mutex_t mutex; + struct list_head xprt_list; + pthread_t barrier_th; + + gf_boolean_t server_manage_gids; /* resolve gids on brick */ + gid_cache_t gid_cache; + int32_t gid_cache_timeout; + + int event_threads; /* # of event threads + * configured */ + + gf_boolean_t parent_up; + gf_boolean_t dync_auth; /* if set authenticate dynamically, + * in case if volume set options + * (say *.allow | *.reject) are + * tweeked */ + struct _child_status *child_status; + gf_lock_t itable_lock; + gf_boolean_t strict_auth_enabled; }; typedef struct server_conf server_conf_t; - typedef enum { - RESOLVE_MUST = 1, - RESOLVE_NOT, - RESOLVE_MAY, - RESOLVE_DONTCARE, - RESOLVE_EXACT + RESOLVE_MUST = 1, + RESOLVE_NOT, + RESOLVE_MAY, + RESOLVE_DONTCARE, + RESOLVE_EXACT } server_resolve_type_t; - struct resolve_comp { - char *basename; - ino_t ino; - uint64_t gen; - inode_t *inode; + char *basename; + inode_t *inode; }; typedef struct { - server_resolve_type_t type; - uint64_t fd_no; - ino_t ino; - uint64_t gen; - ino_t par; - u_char gfid[16]; - u_char pargfid[16]; - char *path; - char *bname; - char *resolved; - int op_ret; - int op_errno; - loc_t deep_loc; - struct resolve_comp *components; - int comp_count; + server_resolve_type_t type; + int64_t fd_no; + u_char gfid[16]; + u_char pargfid[16]; + char *path; + char *bname; + int op_ret; + int op_errno; + loc_t resolve_loc; } server_resolve_t; - -typedef int (*server_resume_fn_t) (call_frame_t *frame, xlator_t *bound_xl); +typedef int (*server_resume_fn_t)(call_frame_t *frame, xlator_t *bound_xl); int -resolve_and_resume (call_frame_t *frame, server_resume_fn_t fn); +resolve_and_resume(call_frame_t *frame, server_resume_fn_t fn); struct _server_state { - server_connection_t *conn; - rpc_transport_t *xprt; - inode_table_t *itable; - - server_resume_fn_t resume_fn; - - loc_t loc; - loc_t loc2; - server_resolve_t resolve; - server_resolve_t resolve2; - - /* used within resolve_and_resume */ - loc_t *loc_now; - server_resolve_t *resolve_now; - - struct iatt stbuf; - int valid; - - fd_t *fd; - dict_t *params; - int flags; - int wbflags; - struct iovec payload_vector[MAX_IOVEC]; - int payload_count; - struct iobuf *iobuf; - struct iobref *iobref; - - size_t size; - off_t offset; - mode_t mode; - dev_t dev; - size_t nr_count; - int cmd; - int type; - char *name; - int name_len; - - int mask; - char is_revalidate; - dict_t *dict; - struct flock flock; - const char *volume; - dir_entry_t *entry; + rpc_transport_t *xprt; + inode_table_t *itable; + + server_resume_fn_t resume_fn; + + loc_t loc; + loc_t loc2; + server_resolve_t resolve; + server_resolve_t resolve2; + + /* used within resolve_and_resume */ + loc_t *loc_now; + server_resolve_t *resolve_now; + + struct iatt stbuf; + int valid; + + /* + * this fd is used in all the fd based operations PLUS + * as a source fd in copy_file_range + */ + fd_t *fd; + fd_t *fd_out; /* destination fd in copy_file_range */ + dict_t *params; + int32_t flags; + int wbflags; + struct iovec payload_vector[MAX_IOVEC]; + int payload_count; + struct iobuf *iobuf; + struct iobref *iobref; + + size_t size; + off_t offset; + /* + * According to the man page of copy_file_range, + * the offsets for source and destination file + * are of type loff_t. But the type loff_t is + * linux specific and is actual a typedef of + * off64_t. + */ + off64_t off_in; /* source offset in copy_file_range */ + off64_t off_out; /* destination offset in copy_file_range */ + mode_t mode; + dev_t dev; + size_t nr_count; + int cmd; + int type; + char *name; + int name_len; + + int mask; + char is_revalidate; + dict_t *dict; + struct gf_flock flock; + const char *volume; + dir_entry_t *entry; + gf_seek_what_t what; + + dict_t *xdata; + mode_t umask; + struct gf_lease lease; + lock_migration_info_t locklist; + + struct iovec rsp_vector[MAX_IOVEC]; + int rsp_count; + struct iobuf *rsp_iobuf; + struct iobref *rsp_iobref; + + /* subdir mount */ + client_t *client; }; extern struct rpcsvc_program gluster_handshake_prog; -extern struct rpcsvc_program glusterfs3_1_fop_prog; -extern struct rpcsvc_program gluster_ping_prog; +extern struct rpcsvc_program glusterfs3_3_fop_prog; +extern struct rpcsvc_program glusterfs4_0_fop_prog; -typedef ssize_t (*gfs_serialize_t) (struct iovec outmsg, void *args); +typedef struct _server_ctx { + gf_lock_t fdtable_lock; + fdtable_t *fdtable; +} server_ctx_t; + +typedef struct server_cleanup_xprt_arg { + xlator_t *this; + char *victim_name; +} server_cleanup_xprt_arg_t; + +int +server_submit_reply(call_frame_t *frame, rpcsvc_request_t *req, void *arg, + struct iovec *payload, int payloadcount, + struct iobref *iobref, xdrproc_t xdrproc); int -server_submit_reply (call_frame_t *frame, rpcsvc_request_t *req, void *arg, - struct iovec *payload, int payloadcount, - struct iobref *iobref, gfs_serialize_t sfunc); +gf_server_check_setxattr_cmd(call_frame_t *frame, dict_t *dict); +int +gf_server_check_getxattr_cmd(call_frame_t *frame, const char *name); + +void +forget_inode_if_no_dentry(inode_t *inode); -int xdr_to_glusterfs_req (rpcsvc_request_t *req, void *arg, - gfs_serialize_t sfunc); +void * +server_graph_janitor_threads(void *); +server_ctx_t * +server_ctx_get(client_t *client, xlator_t *xlator); #endif /* !_SERVER_H */ diff --git a/xlators/protocol/server/src/server3_1-fops.c b/xlators/protocol/server/src/server3_1-fops.c deleted file mode 100644 index 1ced00a4bc2..00000000000 --- a/xlators/protocol/server/src/server3_1-fops.c +++ /dev/null @@ -1,5130 +0,0 @@ -/* - Copyright (c) 2010 Gluster, Inc. <http://www.gluster.com> - This file is part of GlusterFS. - - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. -*/ - - -#ifndef _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif - -#include "server.h" -#include "server-helpers.h" -#include "glusterfs3-xdr.h" -#include "glusterfs3.h" -#include "compat-errno.h" - -#include "md5.h" - -#define SERVER_PATH_MAX (16 * 1024) - -/* Callback function section */ -int -server_statfs_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct statvfs *buf) -{ - gfs3_statfs_rsp rsp = {0,}; - rpcsvc_request_t *req = NULL; - - req = frame->local; - - rsp.gfs_id = req->gfs_id; - rsp.op_ret = op_ret; - rsp.op_errno = gf_errno_to_error (op_errno); - - if (op_ret >= 0) { - gf_statfs_from_statfs (&rsp.statfs, buf); - } - - server_submit_reply (frame, req, &rsp, NULL, 0, NULL, - xdr_serialize_statfs_rsp); - - return 0; -} - -int -server_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 *dict, - struct iatt *postparent) -{ - rpcsvc_request_t *req = NULL; - server_state_t *state = NULL; - inode_t *root_inode = NULL; - inode_t *link_inode = NULL; - loc_t fresh_loc = {0,}; - gfs3_lookup_rsp rsp = {0, }; - int32_t ret = -1; - - state = CALL_STATE(frame); - - req = frame->local; - - 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 = inode_new (state->itable); - - STACK_WIND (frame, server_lookup_cbk, BOUND_XL (frame), - BOUND_XL (frame)->fops->lookup, - &fresh_loc, state->dict); - - loc_wipe (&fresh_loc); - return 0; - } - - if (dict) { - rsp.dict.dict_len = dict_serialized_length (dict); - if (rsp.dict.dict_len < 0) { - gf_log (this->name, GF_LOG_ERROR, - "%s (%"PRId64"): failed to get serialized " - "length of reply dict", - state->loc.path, state->loc.inode->ino); - op_ret = -1; - op_errno = EINVAL; - rsp.dict.dict_len = 0; - } - } - - if ((op_ret >= 0) && dict) { - rsp.dict.dict_val = GF_CALLOC (1, rsp.dict.dict_len, - gf_server_mt_rsp_buf_t); - if (!rsp.dict.dict_val) { - op_ret = -1; - op_errno = ENOMEM; - rsp.dict.dict_len = 0; - goto out; - } - ret = dict_serialize (dict, rsp.dict.dict_val); - if (ret < 0) { - gf_log (this->name, GF_LOG_ERROR, - "%s (%"PRId64"): failed to serialize reply dict", - state->loc.path, state->loc.inode->ino); - op_ret = -1; - op_errno = -ret; - rsp.dict.dict_len = 0; - } - } - - gf_stat_from_iatt (&rsp.postparent, postparent); - - if (op_ret == 0) { - root_inode = BOUND_XL(frame)->itable->root; - if (inode == root_inode) { - /* we just looked up root ("/") */ - stbuf->ia_ino = 1; - if (inode->ia_type == 0) - inode->ia_type = stbuf->ia_type; - } - - gf_stat_from_iatt (&rsp.stat, stbuf); - - if (inode->ino != 1) { - link_inode = inode_link (inode, state->loc.parent, - state->loc.name, stbuf); - inode_lookup (link_inode); - inode_unref (link_inode); - } - } else { - if (state->is_revalidate && op_errno == ENOENT) { - if (state->loc.inode->ino != 1) { - inode_unlink (state->loc.inode, - state->loc.parent, - state->loc.name); - } - } - - gf_log (this->name, - (op_errno == ENOENT ? GF_LOG_TRACE : GF_LOG_DEBUG), - "%"PRId64": LOOKUP %s (%"PRId64") ==> %"PRId32" (%s)", - frame->root->unique, state->loc.path, - state->loc.inode ? state->loc.inode->ino : 0, - op_ret, strerror (op_errno)); - } -out: - rsp.gfs_id = req->gfs_id; - rsp.op_ret = op_ret; - rsp.op_errno = gf_errno_to_error (op_errno); - - server_submit_reply (frame, req, &rsp, NULL, 0, NULL, - (gfs_serialize_t)xdr_serialize_lookup_rsp); - - if (rsp.dict.dict_val) - GF_FREE (rsp.dict.dict_val); - - return 0; -} - - -int -server_lk_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct flock *lock) -{ - gfs3_lk_rsp rsp = {0,}; - rpcsvc_request_t *req = NULL; - server_state_t *state = NULL; - - req = frame->local; - - rsp.gfs_id = req->gfs_id; - rsp.op_ret = op_ret; - rsp.op_errno = gf_errno_to_error (op_errno); - - state = CALL_STATE(frame); - - if (op_ret == 0) { - 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_log (this->name, GF_LOG_ERROR, - "Unknown lock type: %"PRId32"!", lock->l_type); - break; - } - - gf_flock_from_flock (&rsp.flock, lock); - } else if (op_errno != ENOSYS) { - gf_log (this->name, GF_LOG_TRACE, - "%"PRId64": LK %"PRId64" (%"PRId64") ==> %"PRId32" (%s)", - frame->root->unique, state->resolve.fd_no, - state->fd ? state->fd->inode->ino : 0, op_ret, - strerror (op_errno)); - } - - server_submit_reply (frame, req, &rsp, NULL, 0, NULL, - xdr_serialize_lk_rsp); - - return 0; -} - - -int -server_inodelk_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno) -{ - gf_common_rsp rsp = {0,}; - server_connection_t *conn = NULL; - server_state_t *state = NULL; - rpcsvc_request_t *req = NULL; - - req = frame->local; - - rsp.gfs_id = req->gfs_id; - rsp.op_ret = op_ret; - rsp.op_errno = gf_errno_to_error (op_errno); - - conn = SERVER_CONNECTION(frame); - state = CALL_STATE(frame); - - if (op_ret >= 0) { - if (state->flock.l_type == F_UNLCK) - gf_del_locker (conn->ltable, state->volume, - &state->loc, NULL, frame->root->lk_owner); - else - gf_add_locker (conn->ltable, state->volume, - &state->loc, NULL, frame->root->pid, - frame->root->lk_owner); - } else if (op_errno != ENOSYS) { - gf_log (this->name, GF_LOG_TRACE, - "%"PRId64": INODELK %s (%"PRId64") ==> %"PRId32" (%s)", - frame->root->unique, state->loc.path, - state->loc.inode ? state->loc.inode->ino : 0, op_ret, - strerror (op_errno)); - } - - server_submit_reply (frame, req, &rsp, NULL, 0, NULL, - xdr_serialize_common_rsp); - - return 0; -} - - -int -server_finodelk_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno) -{ - gf_common_rsp rsp = {0,}; - server_state_t *state = NULL; - server_connection_t *conn = NULL; - rpcsvc_request_t *req = NULL; - - req = frame->local; - - rsp.gfs_id = req->gfs_id; - rsp.op_ret = op_ret; - rsp.op_errno = gf_errno_to_error (op_errno); - - conn = SERVER_CONNECTION(frame); - state = CALL_STATE(frame); - - if (op_ret >= 0) { - if (state->flock.l_type == F_UNLCK) - gf_del_locker (conn->ltable, state->volume, - NULL, state->fd, - frame->root->lk_owner); - else - gf_add_locker (conn->ltable, state->volume, - NULL, state->fd, - frame->root->pid, - frame->root->lk_owner); - } else if (op_errno != ENOSYS) { - gf_log (this->name, GF_LOG_TRACE, - "%"PRId64": FINODELK %"PRId64" (%"PRId64") ==> %"PRId32" (%s)", - frame->root->unique, state->resolve.fd_no, - state->fd ? state->fd->inode->ino : 0, op_ret, - strerror (op_errno)); - } - - server_submit_reply (frame, req, &rsp, NULL, 0, NULL, - xdr_serialize_common_rsp); - - return 0; -} - -int -server_entrylk_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno) -{ - server_connection_t *conn = NULL; - server_state_t *state = NULL; - rpcsvc_request_t *req = NULL; - gf_common_rsp rsp = {0,}; - - req = frame->local; - - rsp.gfs_id = req->gfs_id; - rsp.op_ret = op_ret; - rsp.op_errno = gf_errno_to_error (op_errno); - - conn = SERVER_CONNECTION(frame); - state = CALL_STATE(frame); - - if (op_ret >= 0) { - if (state->cmd == ENTRYLK_UNLOCK) - gf_del_locker (conn->ltable, state->volume, - &state->loc, NULL, frame->root->lk_owner); - else - gf_add_locker (conn->ltable, state->volume, - &state->loc, NULL, frame->root->pid, - frame->root->lk_owner); - } else if (op_errno != ENOSYS) { - gf_log (this->name, GF_LOG_TRACE, - "%"PRId64": INODELK %s (%"PRId64") ==> %"PRId32" (%s)", - frame->root->unique, state->loc.path, - state->loc.inode ? state->loc.inode->ino : 0, op_ret, - strerror (op_errno)); - } - - server_submit_reply (frame, req, &rsp, NULL, 0, NULL, - xdr_serialize_common_rsp); - return 0; -} - - -int -server_fentrylk_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno) -{ - gf_common_rsp rsp = {0,}; - server_connection_t *conn = NULL; - server_state_t *state = NULL; - rpcsvc_request_t *req = NULL; - - req = frame->local; - - rsp.gfs_id = req->gfs_id; - rsp.op_ret = op_ret; - rsp.op_errno = gf_errno_to_error (op_errno); - - conn = SERVER_CONNECTION(frame); - state = CALL_STATE(frame); - if (op_ret >= 0) { - if (state->cmd == ENTRYLK_UNLOCK) - gf_del_locker (conn->ltable, state->volume, - NULL, state->fd, frame->root->lk_owner); - else - gf_add_locker (conn->ltable, state->volume, - NULL, state->fd, frame->root->pid, - frame->root->lk_owner); - } else if (op_errno != ENOSYS) { - gf_log (this->name, GF_LOG_TRACE, - "%"PRId64": FENTRYLK %"PRId64" (%"PRId64") " - " ==> %"PRId32" (%s)", - frame->root->unique, state->resolve.fd_no, - state->fd ? state->fd->inode->ino : 0, op_ret, - strerror (op_errno)); - } - - server_submit_reply (frame, req, &rsp, NULL, 0, NULL, - xdr_serialize_common_rsp); - - return 0; -} - - -int -server_access_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno) -{ - gf_common_rsp rsp = {0,}; - rpcsvc_request_t *req = NULL; - - req = frame->local; - - rsp.gfs_id = req->gfs_id; - rsp.op_ret = op_ret; - rsp.op_errno = gf_errno_to_error (op_errno); - - server_submit_reply (frame, req, &rsp, NULL, 0, NULL, - xdr_serialize_common_rsp); - - return 0; -} - -int -server_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) -{ - gfs3_rmdir_rsp rsp = {0,}; - server_state_t *state = NULL; - inode_t *parent = NULL; - rpcsvc_request_t *req = NULL; - - req = frame->local; - - rsp.gfs_id = req->gfs_id; - rsp.op_ret = op_ret; - rsp.op_errno = gf_errno_to_error (op_errno); - - state = CALL_STATE(frame); - - if (op_ret == 0) { - inode_unlink (state->loc.inode, state->loc.parent, - state->loc.name); - parent = inode_parent (state->loc.inode, 0, NULL); - if (parent) - inode_unref (parent); - else - inode_forget (state->loc.inode, 0); - - gf_stat_from_iatt (&rsp.preparent, preparent); - gf_stat_from_iatt (&rsp.postparent, postparent); - } else { - gf_log (this->name, GF_LOG_TRACE, - "%"PRId64": RMDIR %s (%"PRId64") ==> %"PRId32" (%s)", - frame->root->unique, state->loc.path, - state->loc.inode ? state->loc.inode->ino : 0, - op_ret, strerror (op_errno)); - } - - server_submit_reply (frame, req, &rsp, NULL, 0, NULL, - xdr_serialize_rmdir_rsp); - - return 0; -} - -int -server_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) -{ - gfs3_mkdir_rsp rsp = {0,}; - server_state_t *state = NULL; - inode_t *link_inode = NULL; - rpcsvc_request_t *req = NULL; - - req = frame->local; - - rsp.gfs_id = req->gfs_id; - rsp.op_ret = op_ret; - rsp.op_errno = gf_errno_to_error (op_errno); - - state = CALL_STATE(frame); - if (op_ret >= 0) { - gf_stat_from_iatt (&rsp.stat, stbuf); - gf_stat_from_iatt (&rsp.preparent, preparent); - gf_stat_from_iatt (&rsp.postparent, postparent); - - link_inode = inode_link (inode, state->loc.parent, - state->loc.name, stbuf); - inode_lookup (link_inode); - inode_unref (link_inode); - } else { - gf_log (this->name, GF_LOG_TRACE, - "%"PRId64": MKDIR %s ==> %"PRId32" (%s)", - frame->root->unique, state->loc.path, - op_ret, strerror (op_errno)); - } - - server_submit_reply (frame, req, &rsp, NULL, 0, NULL, - xdr_serialize_mkdir_rsp); - - return 0; -} - -int -server_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) -{ - gfs3_mknod_rsp rsp = {0,}; - server_state_t *state = NULL; - inode_t *link_inode = NULL; - rpcsvc_request_t *req = NULL; - - req = frame->local; - - rsp.gfs_id = req->gfs_id; - rsp.op_ret = op_ret; - rsp.op_errno = gf_errno_to_error (op_errno); - - state = CALL_STATE(frame); - if (op_ret >= 0) { - gf_stat_from_iatt (&rsp.stat, stbuf); - gf_stat_from_iatt (&rsp.preparent, preparent); - gf_stat_from_iatt (&rsp.postparent, postparent); - - link_inode = inode_link (inode, state->loc.parent, - state->loc.name, stbuf); - inode_lookup (link_inode); - inode_unref (link_inode); - } else { - gf_log (this->name, GF_LOG_TRACE, - "%"PRId64": MKNOD %s ==> %"PRId32" (%s)", - frame->root->unique, state->loc.path, - op_ret, strerror (op_errno)); - } - - server_submit_reply (frame, req, &rsp, NULL, 0, NULL, - xdr_serialize_mknod_rsp); - - - return 0; -} - -int -server_fsyncdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno) -{ - gf_common_rsp rsp = {0,}; - server_state_t *state = NULL; - rpcsvc_request_t *req = NULL; - - req = frame->local; - - rsp.gfs_id = req->gfs_id; - rsp.op_ret = op_ret; - rsp.op_errno = gf_errno_to_error (op_errno); - - state = CALL_STATE(frame); - - if (op_ret < 0) { - gf_log (this->name, GF_LOG_TRACE, - "%"PRId64": FSYNCDIR %"PRId64" (%"PRId64") ==> %"PRId32" (%s)", - frame->root->unique, state->resolve.fd_no, - state->fd ? state->fd->inode->ino : 0, op_ret, - strerror (op_errno)); - } - - server_submit_reply (frame, req, &rsp, NULL, 0, NULL, - xdr_serialize_common_rsp); - - return 0; -} - -int -server_readdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, gf_dirent_t *entries) -{ - gfs3_readdir_rsp rsp = {0,}; - server_state_t *state = NULL; - rpcsvc_request_t *req = NULL; - int ret = 0; - - req = frame->local; - - state = CALL_STATE(frame); - if (op_ret > 0) { - ret = serialize_rsp_dirent (entries, &rsp); - if (ret == -1) { - op_ret = -1; - op_errno = ENOMEM; - goto unwind; - } - } else { - gf_log (this->name, GF_LOG_TRACE, - "%"PRId64": READDIR %"PRId64" (%"PRId64") ==> %"PRId32" (%s)", - frame->root->unique, state->resolve.fd_no, - state->fd ? state->fd->inode->ino : 0, op_ret, - strerror (op_errno)); - } -unwind: - rsp.gfs_id = req->gfs_id; - rsp.op_ret = op_ret; - rsp.op_errno = gf_errno_to_error (op_errno); - - server_submit_reply (frame, req, &rsp, NULL, 0, NULL, - xdr_serialize_readdir_rsp); - - readdir_rsp_cleanup (&rsp); - - return 0; -} - - -int -server_releasedir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno) -{ - gf_common_rsp rsp = {0,}; - rpcsvc_request_t *req = NULL; - - req = frame->local; - - rsp.gfs_id = req->gfs_id; - rsp.op_ret = op_ret; - rsp.op_errno = gf_errno_to_error (op_errno); - - server_submit_reply (frame, req, &rsp, NULL, 0, NULL, - xdr_serialize_common_rsp); - - return 0; -} - -int -server_opendir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, fd_t *fd) -{ - server_connection_t *conn = NULL; - server_state_t *state = NULL; - rpcsvc_request_t *req = NULL; - gfs3_opendir_rsp rsp = {0,}; - uint64_t fd_no = 0; - - conn = SERVER_CONNECTION (frame); - state = CALL_STATE (frame); - - if (op_ret >= 0) { - fd_bind (fd); - - fd_no = gf_fd_unused_get (conn->fdtable, fd); - fd_ref (fd); // on behalf of the client - } else { - gf_log (this->name, GF_LOG_TRACE, - "%"PRId64": OPENDIR %s (%"PRId64") ==> %"PRId32" (%s)", - frame->root->unique, state->loc.path, - state->loc.inode ? state->loc.inode->ino : 0, - op_ret, strerror (op_errno)); - } - - req = frame->local; - - rsp.fd = fd_no; - rsp.gfs_id = req->gfs_id; - rsp.op_ret = op_ret; - rsp.op_errno = gf_errno_to_error (op_errno); - - server_submit_reply (frame, req, &rsp, NULL, 0, NULL, - xdr_serialize_opendir_rsp); - - return 0; -} - -int -server_removexattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno) -{ - gf_common_rsp rsp = {0,}; - rpcsvc_request_t *req = NULL; - - req = frame->local; - - rsp.gfs_id = req->gfs_id; - rsp.op_ret = op_ret; - rsp.op_errno = gf_errno_to_error (op_errno); - - server_submit_reply (frame, req, &rsp, NULL, 0, NULL, - xdr_serialize_common_rsp); - - return 0; -} - -int -server_getxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, dict_t *dict) -{ - gfs3_getxattr_rsp rsp = {0,}; - int32_t len = 0; - int32_t ret = -1; - rpcsvc_request_t *req = NULL; - server_state_t *state = NULL; - - state = CALL_STATE (frame); - - if (op_ret >= 0) { - len = dict_serialized_length (dict); - if (len < 0) { - gf_log (this->name, GF_LOG_ERROR, - "%s (%"PRId64"): failed to get serialized length of " - "reply dict", - state->loc.path, state->resolve.ino); - op_ret = -1; - op_errno = EINVAL; - len = 0; - goto out; - } - - rsp.dict.dict_val = GF_CALLOC (len, sizeof (char), - gf_server_mt_rsp_buf_t); - if (!rsp.dict.dict_val) { - op_ret = -1; - op_errno = ENOMEM; - len = 0; - goto out; - } - ret = dict_serialize (dict, rsp.dict.dict_val); - if (ret < 0) { - gf_log (this->name, GF_LOG_ERROR, - "%s (%"PRId64"): failed to serialize reply dict", - state->loc.path, state->resolve.ino); - op_ret = -1; - op_errno = EINVAL; - len = 0; - } - } -out: - req = frame->local; - - rsp.gfs_id = req->gfs_id; - rsp.op_ret = op_ret; - rsp.op_errno = gf_errno_to_error (op_errno); - rsp.dict.dict_len = len; - - server_submit_reply (frame, req, &rsp, NULL, 0, NULL, - xdr_serialize_getxattr_rsp); - - if (rsp.dict.dict_val) - GF_FREE (rsp.dict.dict_val); - - return 0; -} - - -int -server_fgetxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, dict_t *dict) -{ - gfs3_fgetxattr_rsp rsp = {0,}; - int32_t len = 0; - int32_t ret = -1; - server_state_t *state = NULL; - rpcsvc_request_t *req = NULL; - - state = CALL_STATE (frame); - - if (op_ret >= 0) { - len = dict_serialized_length (dict); - if (len < 0) { - gf_log (this->name, GF_LOG_ERROR, - "%s (%"PRId64"): failed to get serialized " - "length of reply dict", - state->loc.path, state->resolve.ino); - op_ret = -1; - op_errno = EINVAL; - len = 0; - goto out; - } - rsp.dict.dict_val = GF_CALLOC (1, len, gf_server_mt_rsp_buf_t); - if (!rsp.dict.dict_val) { - op_ret = -1; - op_errno = ENOMEM; - len = 0; - goto out; - } - ret = dict_serialize (dict, rsp.dict.dict_val); - if (ret < 0) { - gf_log (this->name, GF_LOG_ERROR, - "%s (%"PRId64"): failed to serialize reply dict", - state->loc.path, state->resolve.ino); - op_ret = -1; - op_errno = -ret; - len = 0; - } - } - -out: - req = frame->local; - - rsp.gfs_id = req->gfs_id; - rsp.op_ret = op_ret; - rsp.op_errno = gf_errno_to_error (op_errno); - rsp.dict.dict_len = len; - server_submit_reply (frame, req, &rsp, NULL, 0, NULL, - xdr_serialize_fgetxattr_rsp); - - if (rsp.dict.dict_val) - GF_FREE (rsp.dict.dict_val); - - return 0; -} - -int -server_setxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno) -{ - gf_common_rsp rsp = {0,}; - rpcsvc_request_t *req = NULL; - - req = frame->local; - - rsp.gfs_id = req->gfs_id; - rsp.op_ret = op_ret; - rsp.op_errno = gf_errno_to_error (op_errno); - - server_submit_reply (frame, req, &rsp, NULL, 0, NULL, - xdr_serialize_common_rsp); - - return 0; -} - - -int -server_fsetxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno) -{ - gf_common_rsp rsp = {0,}; - rpcsvc_request_t *req = NULL; - - req = frame->local; - - rsp.gfs_id = req->gfs_id; - rsp.op_ret = op_ret; - rsp.op_errno = gf_errno_to_error (op_errno); - - server_submit_reply (frame, req, &rsp, NULL, 0, NULL, - xdr_serialize_common_rsp); - - return 0; -} - -int -server_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) -{ - gfs3_rename_rsp rsp = {0,}; - server_state_t *state = NULL; - rpcsvc_request_t *req = NULL; - - req = frame->local; - - rsp.gfs_id = req->gfs_id; - rsp.op_ret = op_ret; - rsp.op_errno = gf_errno_to_error (op_errno); - - state = CALL_STATE(frame); - - if (op_ret == 0) { - stbuf->ia_ino = state->loc.inode->ino; - stbuf->ia_type = state->loc.inode->ia_type; - - gf_log (state->conn->bound_xl->name, GF_LOG_TRACE, - "%"PRId64": RENAME_CBK (%"PRId64") %"PRId64"/%s " - "==> %"PRId64"/%s", - frame->root->unique, state->loc.inode->ino, - state->loc.parent->ino, state->loc.name, - state->loc2.parent->ino, state->loc2.name); - - inode_rename (state->itable, - state->loc.parent, state->loc.name, - state->loc2.parent, state->loc2.name, - state->loc.inode, stbuf); - gf_stat_from_iatt (&rsp.stat, stbuf); - - gf_stat_from_iatt (&rsp.preoldparent, preoldparent); - gf_stat_from_iatt (&rsp.postoldparent, postoldparent); - - gf_stat_from_iatt (&rsp.prenewparent, prenewparent); - gf_stat_from_iatt (&rsp.postnewparent, postnewparent); - } - - server_submit_reply (frame, req, &rsp, NULL, 0, NULL, - xdr_serialize_rename_rsp); - - return 0; -} - -int -server_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) -{ - gfs3_unlink_rsp rsp = {0,}; - server_state_t *state = NULL; - inode_t *parent = NULL; - rpcsvc_request_t *req = NULL; - - req = frame->local; - - rsp.gfs_id = req->gfs_id; - rsp.op_ret = op_ret; - rsp.op_errno = gf_errno_to_error (op_errno); - - state = CALL_STATE(frame); - - if (op_ret == 0) { - gf_log (state->conn->bound_xl->name, GF_LOG_TRACE, - "%"PRId64": UNLINK_CBK %"PRId64"/%s (%"PRId64")", - frame->root->unique, state->loc.parent->ino, - state->loc.name, state->loc.inode->ino); - - inode_unlink (state->loc.inode, state->loc.parent, - state->loc.name); - - parent = inode_parent (state->loc.inode, 0, NULL); - if (parent) - inode_unref (parent); - else - inode_forget (state->loc.inode, 0); - - gf_stat_from_iatt (&rsp.preparent, preparent); - gf_stat_from_iatt (&rsp.postparent, postparent); - - } else { - gf_log (this->name, GF_LOG_DEBUG, - "%"PRId64": UNLINK %s (%"PRId64") ==> %"PRId32" (%s)", - frame->root->unique, state->loc.path, - state->loc.inode ? state->loc.inode->ino : 0, - op_ret, strerror (op_errno)); - } - - server_submit_reply (frame, req, &rsp, NULL, 0, NULL, - xdr_serialize_unlink_rsp); - - return 0; -} - -int -server_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) -{ - gfs3_symlink_rsp rsp = {0,}; - server_state_t *state = NULL; - inode_t *link_inode = NULL; - rpcsvc_request_t *req = NULL; - - req = frame->local; - - rsp.gfs_id = req->gfs_id; - rsp.op_ret = op_ret; - rsp.op_errno = gf_errno_to_error (op_errno); - - state = CALL_STATE(frame); - if (op_ret >= 0) { - gf_stat_from_iatt (&rsp.stat, stbuf); - gf_stat_from_iatt (&rsp.preparent, preparent); - gf_stat_from_iatt (&rsp.postparent, postparent); - - link_inode = inode_link (inode, state->loc.parent, - state->loc.name, stbuf); - inode_lookup (link_inode); - inode_unref (link_inode); - } else { - gf_log (this->name, GF_LOG_DEBUG, - "%"PRId64": SYMLINK %s (%"PRId64") ==> %"PRId32" (%s)", - frame->root->unique, state->loc.path, - state->loc.inode ? state->loc.inode->ino : 0, - op_ret, strerror (op_errno)); - } - - server_submit_reply (frame, req, &rsp, NULL, 0, NULL, - xdr_serialize_symlink_rsp); - - return 0; -} - - -int -server_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) -{ - gfs3_link_rsp rsp = {0,}; - server_state_t *state = NULL; - inode_t *link_inode = NULL; - rpcsvc_request_t *req = NULL; - - req = frame->local; - - rsp.gfs_id = req->gfs_id; - rsp.op_ret = op_ret; - rsp.op_errno = gf_errno_to_error (op_errno); - - state = CALL_STATE(frame); - - if (op_ret == 0) { - stbuf->ia_ino = state->loc.inode->ino; - - gf_stat_from_iatt (&rsp.stat, stbuf); - gf_stat_from_iatt (&rsp.preparent, preparent); - gf_stat_from_iatt (&rsp.postparent, postparent); - - gf_log (state->conn->bound_xl->name, GF_LOG_TRACE, - "%"PRId64": LINK (%"PRId64") %"PRId64"/%s ==> %"PRId64"/%s", - frame->root->unique, inode->ino, - state->loc2.parent->ino, - state->loc2.name, state->loc.parent->ino, - state->loc.name); - - link_inode = inode_link (inode, state->loc2.parent, - state->loc2.name, stbuf); - inode_unref (link_inode); - } else { - gf_log (state->conn->bound_xl->name, GF_LOG_DEBUG, - "%"PRId64": LINK (%"PRId64") %"PRId64"/%s ==> %"PRId64"/%s " - " ==> %"PRId32" (%s)", - frame->root->unique, state->resolve2.ino, - state->resolve2.par, - state->resolve2.bname, state->resolve.par, - state->resolve.bname, - op_ret, strerror (op_errno)); - } - - server_submit_reply (frame, req, &rsp, NULL, 0, NULL, - xdr_serialize_link_rsp); - - return 0; -} - -int -server_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) -{ - gfs3_truncate_rsp rsp = {0,}; - server_state_t *state = NULL; - rpcsvc_request_t *req = NULL; - - req = frame->local; - - rsp.gfs_id = req->gfs_id; - rsp.op_ret = op_ret; - rsp.op_errno = gf_errno_to_error (op_errno); - - state = CALL_STATE (frame); - - if (op_ret == 0) { - gf_stat_from_iatt (&rsp.prestat, prebuf); - gf_stat_from_iatt (&rsp.poststat, postbuf); - } else { - gf_log (this->name, GF_LOG_DEBUG, - "%"PRId64": TRUNCATE %s (%"PRId64") ==> %"PRId32" (%s)", - frame->root->unique, state->loc.path, - state->loc.inode ? state->loc.inode->ino : 0, - op_ret, strerror (op_errno)); - } - - server_submit_reply (frame, req, &rsp, NULL, 0, NULL, - xdr_serialize_truncate_rsp); - - return 0; -} - -int -server_fstat_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct iatt *stbuf) -{ - gfs3_fstat_rsp rsp = {0,}; - server_state_t *state = NULL; - rpcsvc_request_t *req = NULL; - - req = frame->local; - - rsp.gfs_id = req->gfs_id; - rsp.op_ret = op_ret; - rsp.op_errno = gf_errno_to_error (op_errno); - - state = CALL_STATE(frame); - - if (op_ret == 0) { - gf_stat_from_iatt (&rsp.stat, stbuf); - } else { - gf_log (this->name, GF_LOG_DEBUG, - "%"PRId64": FSTAT %"PRId64" (%"PRId64") ==> %"PRId32" (%s)", - frame->root->unique, state->resolve.fd_no, - state->fd ? state->fd->inode->ino : 0, op_ret, - strerror (op_errno)); - } - - server_submit_reply (frame, req, &rsp, NULL, 0, NULL, - xdr_serialize_fstat_rsp); - - return 0; -} - -int -server_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) -{ - gfs3_ftruncate_rsp rsp = {0}; - server_state_t *state = NULL; - rpcsvc_request_t *req = NULL; - - req = frame->local; - - rsp.gfs_id = req->gfs_id; - rsp.op_ret = op_ret; - rsp.op_errno = gf_errno_to_error (op_errno); - - state = CALL_STATE (frame); - - if (op_ret == 0) { - gf_stat_from_iatt (&rsp.prestat, prebuf); - gf_stat_from_iatt (&rsp.poststat, postbuf); - } else { - gf_log (this->name, GF_LOG_DEBUG, - "%"PRId64": FTRUNCATE %"PRId64" (%"PRId64") ==> %"PRId32" (%s)", - frame->root->unique, state->resolve.fd_no, - state->fd ? state->fd->inode->ino : 0, op_ret, - strerror (op_errno)); - } - - server_submit_reply (frame, req, &rsp, NULL, 0, NULL, - xdr_serialize_ftruncate_rsp); - - return 0; -} - -int -server_flush_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno) -{ - gf_common_rsp rsp = {0,}; - server_state_t *state = NULL; - rpcsvc_request_t *req = NULL; - - req = frame->local; - - rsp.gfs_id = req->gfs_id; - rsp.op_ret = op_ret; - rsp.op_errno = gf_errno_to_error (op_errno); - - state = CALL_STATE(frame); - if (op_ret < 0) { - gf_log (this->name, GF_LOG_DEBUG, - "%"PRId64": FLUSH %"PRId64" (%"PRId64") ==> %"PRId32" (%s)", - frame->root->unique, state->resolve.fd_no, - state->fd ? state->fd->inode->ino : 0, op_ret, - strerror (op_errno)); - } - - server_submit_reply (frame, req, &rsp, NULL, 0, NULL, - xdr_serialize_common_rsp); - - - return 0; -} - -int -server_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) -{ - gfs3_fsync_rsp rsp = {0,}; - server_state_t *state = NULL; - rpcsvc_request_t *req = NULL; - - req = frame->local; - - rsp.gfs_id = req->gfs_id; - rsp.op_ret = op_ret; - rsp.op_errno = gf_errno_to_error (op_errno); - - state = CALL_STATE(frame); - - if (op_ret < 0) { - gf_log (this->name, GF_LOG_DEBUG, - "%"PRId64": FSYNC %"PRId64" (%"PRId64") ==> %"PRId32" (%s)", - frame->root->unique, state->resolve.fd_no, - state->fd ? state->fd->inode->ino : 0, op_ret, - strerror (op_errno)); - } else { - gf_stat_from_iatt (&(rsp.prestat), prebuf); - gf_stat_from_iatt (&(rsp.poststat), postbuf); - } - - server_submit_reply (frame, req, &rsp, NULL, 0, NULL, - xdr_serialize_fsync_rsp); - - return 0; -} - -int -server_release_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno) -{ - gf_common_rsp rsp = {0,}; - rpcsvc_request_t *req = NULL; - - req = frame->local; - - rsp.gfs_id = req->gfs_id; - rsp.op_ret = op_ret; - rsp.op_errno = gf_errno_to_error (op_errno); - - server_submit_reply (frame, req, &rsp, NULL, 0, NULL, - xdr_serialize_common_rsp); - return 0; -} - - -int -server_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) -{ - gfs3_write_rsp rsp = {0,}; - server_state_t *state = NULL; - rpcsvc_request_t *req = NULL; - - req = frame->local; - - rsp.gfs_id = req->gfs_id; - rsp.op_ret = op_ret; - rsp.op_errno = gf_errno_to_error (op_errno); - - state = CALL_STATE(frame); - if (op_ret >= 0) { - gf_stat_from_iatt (&rsp.prestat, prebuf); - gf_stat_from_iatt (&rsp.poststat, postbuf); - } else { - gf_log (this->name, GF_LOG_DEBUG, - "%"PRId64": WRITEV %"PRId64" (%"PRId64") ==> %"PRId32" (%s)", - frame->root->unique, state->resolve.fd_no, - state->fd ? state->fd->inode->ino : 0, op_ret, - strerror (op_errno)); - } - - server_submit_reply (frame, req, &rsp, NULL, 0, NULL, - xdr_serialize_writev_rsp); - - return 0; -} - - -int -server_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) -{ - gfs3_read_rsp rsp = {0,}; - server_state_t *state = NULL; - rpcsvc_request_t *req = NULL; - - req = frame->local; - - rsp.gfs_id = req->gfs_id; - rsp.op_ret = op_ret; - rsp.op_errno = gf_errno_to_error (op_errno); - - state = CALL_STATE(frame); - if (op_ret >= 0) { - gf_stat_from_iatt (&rsp.stat, stbuf); - rsp.size = op_ret; - } else { - gf_log (this->name, GF_LOG_DEBUG, - "%"PRId64": READV %"PRId64" (%"PRId64") ==> %"PRId32" (%s)", - frame->root->unique, state->resolve.fd_no, - state->fd ? state->fd->inode->ino : 0, op_ret, - strerror (op_errno)); - } - - server_submit_reply (frame, req, &rsp, vector, count, iobref, - xdr_serialize_readv_rsp); - - return 0; -} - -int -server_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) -{ - gfs3_rchecksum_rsp rsp = {0,}; - rpcsvc_request_t *req = NULL; - - req = frame->local; - - rsp.gfs_id = req->gfs_id; - rsp.op_ret = op_ret; - rsp.op_errno = gf_errno_to_error (op_errno); - - if (op_ret >= 0) { - rsp.weak_checksum = weak_checksum; - - rsp.strong_checksum.strong_checksum_val = (char *)strong_checksum; - rsp.strong_checksum.strong_checksum_len = MD5_DIGEST_LEN; - } - - server_submit_reply (frame, req, &rsp, NULL, 0, NULL, - xdr_serialize_rchecksum_rsp); - - return 0; -} - - -int -server_open_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, fd_t *fd) -{ - server_connection_t *conn = NULL; - server_state_t *state = NULL; - rpcsvc_request_t *req = NULL; - uint64_t fd_no = 0; - gfs3_open_rsp rsp = {0,}; - - conn = SERVER_CONNECTION (frame); - state = CALL_STATE (frame); - - if (op_ret >= 0) { - fd_bind (fd); - fd_no = gf_fd_unused_get (conn->fdtable, fd); - fd_ref (fd); - } else { - gf_log (this->name, GF_LOG_DEBUG, - "%"PRId64": OPEN %s (%"PRId64") ==> %"PRId32" (%s)", - frame->root->unique, state->loc.path, - state->loc.inode ? state->loc.inode->ino : 0, - op_ret, strerror (op_errno)); - } - - req = frame->local; - - rsp.fd = fd_no; - rsp.gfs_id = req->gfs_id; - rsp.op_ret = op_ret; - rsp.op_errno = gf_errno_to_error (op_errno); - - server_submit_reply (frame, req, &rsp, NULL, 0, NULL, - xdr_serialize_open_rsp); - return 0; -} - - -int -server_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) -{ - server_connection_t *conn = NULL; - server_state_t *state = NULL; - inode_t *link_inode = NULL; - rpcsvc_request_t *req = NULL; - uint64_t fd_no = 0; - gfs3_create_rsp rsp = {0,}; - - conn = SERVER_CONNECTION (frame); - state = CALL_STATE (frame); - - if (op_ret >= 0) { - gf_log (state->conn->bound_xl->name, GF_LOG_TRACE, - "%"PRId64": CREATE %"PRId64"/%s (%"PRId64")", - frame->root->unique, state->loc.parent->ino, - state->loc.name, stbuf->ia_ino); - - link_inode = inode_link (inode, state->loc.parent, - state->loc.name, stbuf); - - if (link_inode != inode) { - /* - VERY racy code (if used anywhere else) - -- don't do this without understanding - */ - - inode_unref (fd->inode); - fd->inode = inode_ref (link_inode); - } - - inode_lookup (link_inode); - inode_unref (link_inode); - - fd_bind (fd); - - fd_no = gf_fd_unused_get (conn->fdtable, fd); - fd_ref (fd); - - if ((fd_no < 0) || (fd == 0)) { - op_ret = fd_no; - op_errno = errno; - } - - gf_stat_from_iatt (&rsp.stat, stbuf); - gf_stat_from_iatt (&rsp.preparent, preparent); - gf_stat_from_iatt (&rsp.postparent, postparent); - } else { - gf_log (this->name, GF_LOG_DEBUG, - "%"PRId64": CREATE %s (%"PRId64") ==> %"PRId32" (%s)", - frame->root->unique, state->loc.path, - state->loc.inode ? state->loc.inode->ino : 0, - op_ret, strerror (op_errno)); - } - - req = frame->local; - - rsp.fd = fd_no; - rsp.gfs_id = req->gfs_id; - rsp.op_ret = op_ret; - rsp.op_errno = gf_errno_to_error (op_errno); - - server_submit_reply (frame, req, &rsp, NULL, 0, NULL, - xdr_serialize_create_rsp); - - return 0; -} - -int -server_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) -{ - gfs3_readlink_rsp rsp = {0,}; - server_state_t *state = NULL; - rpcsvc_request_t *req = NULL; - - req = frame->local; - - rsp.gfs_id = req->gfs_id; - rsp.op_ret = op_ret; - rsp.op_errno = gf_errno_to_error (op_errno); - - - state = CALL_STATE(frame); - - if (op_ret >= 0) { - gf_stat_from_iatt (&rsp.buf, stbuf); - rsp.path = (char *)buf; - } else { - gf_log (this->name, GF_LOG_DEBUG, - "%"PRId64": READLINK %s (%"PRId64") ==> %"PRId32" (%s)", - frame->root->unique, state->loc.path, - state->loc.inode ? state->loc.inode->ino : 0, - op_ret, strerror (op_errno)); - } - - if (!rsp.path) - rsp.path = ""; - - server_submit_reply (frame, req, &rsp, NULL, 0, NULL, - xdr_serialize_readlink_rsp); - - return 0; -} - -int -server_stat_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct iatt *stbuf) -{ - gfs3_stat_rsp rsp = {0,}; - server_state_t *state = NULL; - rpcsvc_request_t *req = NULL; - - req = frame->local; - - rsp.gfs_id = req->gfs_id; - rsp.op_ret = op_ret; - rsp.op_errno = gf_errno_to_error (op_errno); - - state = CALL_STATE (frame); - - if (op_ret == 0) { - gf_stat_from_iatt (&rsp.stat, stbuf); - } else { - gf_log (this->name, GF_LOG_DEBUG, - "%"PRId64": STAT %s (%"PRId64") ==> %"PRId32" (%s)", - frame->root->unique, state->loc.path, - state->loc.inode ? state->loc.inode->ino : 0, - op_ret, strerror (op_errno)); - } - - server_submit_reply (frame, req, &rsp, NULL, 0, NULL, - xdr_serialize_stat_rsp); - - return 0; -} - - -int -server_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) -{ - gfs3_setattr_rsp rsp = {0,}; - server_state_t *state = NULL; - rpcsvc_request_t *req = NULL; - - req = frame->local; - - rsp.gfs_id = req->gfs_id; - rsp.op_ret = op_ret; - rsp.op_errno = gf_errno_to_error (op_errno); - - state = CALL_STATE (frame); - - if (op_ret == 0) { - gf_stat_from_iatt (&rsp.statpre, statpre); - gf_stat_from_iatt (&rsp.statpost, statpost); - } else { - gf_log (this->name, GF_LOG_DEBUG, - "%"PRId64": SETATTR %s (%"PRId64") ==> %"PRId32" (%s)", - frame->root->unique, state->loc.path, - state->loc.inode ? state->loc.inode->ino : 0, - op_ret, strerror (op_errno)); - } - - server_submit_reply (frame, req, &rsp, NULL, 0, NULL, - xdr_serialize_setattr_rsp); - - return 0; -} - -int -server_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) -{ - gfs3_fsetattr_rsp rsp = {0,}; - server_state_t *state = NULL; - rpcsvc_request_t *req = NULL; - - state = CALL_STATE (frame); - - if (op_ret == 0) { - gf_stat_from_iatt (&rsp.statpre, statpre); - gf_stat_from_iatt (&rsp.statpost, statpost); - } else { - gf_log (this->name, GF_LOG_DEBUG, - "%"PRId64": FSETATTR %"PRId64" (%"PRId64") ==> " - "%"PRId32" (%s)", - frame->root->unique, state->resolve.fd_no, - state->fd ? state->fd->inode->ino : 0, - op_ret, strerror (op_errno)); - } - - req = frame->local; - - rsp.gfs_id = req->gfs_id; - rsp.op_ret = op_ret; - rsp.op_errno = gf_errno_to_error (op_errno); - - server_submit_reply (frame, req, &rsp, NULL, 0, NULL, - xdr_serialize_fsetattr_rsp); - - return 0; -} - - -int -server_xattrop_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, dict_t *dict) -{ - gfs3_xattrop_rsp rsp = {0,}; - int32_t len = 0; - int32_t ret = -1; - server_state_t *state = NULL; - rpcsvc_request_t *req = NULL; - - state = CALL_STATE (frame); - - if (op_ret < 0) { - gf_log (this->name, GF_LOG_DEBUG, - "%"PRId64": XATTROP %s (%"PRId64") ==> %"PRId32" (%s)", - frame->root->unique, state->loc.path, - state->loc.inode ? state->loc.inode->ino : 0, - op_ret, strerror (op_errno)); - goto out; - } - - if ((op_ret >= 0) && dict) { - len = dict_serialized_length (dict); - if (len < 0) { - gf_log (this->name, GF_LOG_ERROR, - "%s (%"PRId64"): failed to get serialized length" - " for reply dict", - state->loc.path, state->loc.inode->ino); - op_ret = -1; - op_errno = EINVAL; - len = 0; - goto out; - } - rsp.dict.dict_val = GF_CALLOC (1, len, gf_server_mt_rsp_buf_t); - if (!rsp.dict.dict_val) { - op_ret = -1; - op_errno = ENOMEM; - len = 0; - goto out; - } - ret = dict_serialize (dict, rsp.dict.dict_val); - if (ret < 0) { - gf_log (this->name, GF_LOG_ERROR, - "%s (%"PRId64"): failed to serialize reply dict", - state->loc.path, state->loc.inode->ino); - op_ret = -1; - op_errno = -ret; - len = 0; - } - } -out: - req = frame->local; - - rsp.gfs_id = req->gfs_id; - rsp.op_ret = op_ret; - rsp.op_errno = gf_errno_to_error (op_errno); - rsp.dict.dict_len = len; - - server_submit_reply (frame, req, &rsp, NULL, 0, NULL, - xdr_serialize_xattrop_rsp); - - if (rsp.dict.dict_val) - GF_FREE (rsp.dict.dict_val); - - return 0; -} - - -int -server_fxattrop_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, dict_t *dict) -{ - gfs3_xattrop_rsp rsp = {0,}; - int32_t len = 0; - int32_t ret = -1; - server_state_t *state = NULL; - rpcsvc_request_t *req = NULL; - - state = CALL_STATE(frame); - - if (op_ret < 0) { - gf_log (this->name, GF_LOG_DEBUG, - "%"PRId64": FXATTROP %"PRId64" (%"PRId64") ==> %"PRId32" (%s)", - frame->root->unique, state->resolve.fd_no, - state->fd ? state->fd->inode->ino : 0, op_ret, - strerror (op_errno)); - goto out; - } - - if ((op_ret >= 0) && dict) { - len = dict_serialized_length (dict); - if (len < 0) { - gf_log (this->name, GF_LOG_ERROR, - "fd - %"PRId64" (%"PRId64"): failed to get " - "serialized length for reply dict", - state->resolve.fd_no, state->fd->inode->ino); - op_ret = -1; - op_errno = EINVAL; - len = 0; - goto out; - } - rsp.dict.dict_val = GF_CALLOC (1, len, gf_server_mt_rsp_buf_t); - if (!rsp.dict.dict_val) { - op_ret = -1; - op_errno = ENOMEM; - len = 0; - goto out; - } - ret = dict_serialize (dict, rsp.dict.dict_val); - if (ret < 0) { - gf_log (this->name, GF_LOG_ERROR, - "fd - %"PRId64" (%"PRId64"): failed to " - "serialize reply dict", - state->resolve.fd_no, state->fd->inode->ino); - op_ret = -1; - op_errno = -ret; - len = 0; - } - } -out: - req = frame->local; - - rsp.gfs_id = req->gfs_id; - rsp.op_ret = op_ret; - rsp.op_errno = gf_errno_to_error (op_errno); - rsp.dict.dict_len = len; - - server_submit_reply (frame, req, &rsp, NULL, 0, NULL, - xdr_serialize_fxattrop_rsp); - - if (rsp.dict.dict_val) - GF_FREE (rsp.dict.dict_val); - - return 0; -} - - -int -server_readdirp_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, gf_dirent_t *entries) -{ - gfs3_readdirp_rsp rsp = {0,}; - server_state_t *state = NULL; - rpcsvc_request_t *req = NULL; - int ret = 0; - - req = frame->local; - - state = CALL_STATE(frame); - if (op_ret > 0) { - ret = serialize_rsp_direntp (entries, &rsp); - if (ret == -1) { - op_ret = -1; - op_errno = ENOMEM; - goto out; - } - } else { - gf_log (this->name, GF_LOG_TRACE, - "%"PRId64": READDIRP %"PRId64" (%"PRId64") ==>" - "%"PRId32" (%s)", - frame->root->unique, state->resolve.fd_no, - state->fd ? state->fd->inode->ino : 0, op_ret, - strerror (op_errno)); - } - -out: - rsp.gfs_id = req->gfs_id; - rsp.op_ret = op_ret; - rsp.op_errno = gf_errno_to_error (op_errno); - - server_submit_reply (frame, req, &rsp, NULL, 0, NULL, - xdr_serialize_readdirp_rsp); - - readdirp_rsp_cleanup (&rsp); - - return 0; -} - -/* Resume function section */ - -int -server_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, server_rchecksum_cbk, bound_xl, - bound_xl->fops->rchecksum, state->fd, - state->offset, state->size); - - return 0; -err: - server_rchecksum_cbk (frame, NULL, frame->this, op_ret, op_errno, 0, NULL); - - return 0; - -} - -int -server_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, server_lk_cbk, bound_xl, bound_xl->fops->lk, - state->fd, state->cmd, &state->flock); - - return 0; - -err: - server_lk_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno, NULL); - return 0; -} - -int -server_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, server_rename_cbk, - bound_xl, bound_xl->fops->rename, - &state->loc, &state->loc2); - return 0; -err: - server_rename_cbk (frame, NULL, frame->this, op_ret, op_errno, - NULL, NULL, NULL, NULL, NULL); - return 0; -} - - -int -server_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, server_link_cbk, bound_xl, bound_xl->fops->link, - &state->loc, &state->loc2); - - return 0; -err: - server_link_cbk (frame, NULL, frame->this, op_ret, op_errno, - NULL, NULL, NULL, NULL); - return 0; -} - -int -server_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, server_symlink_cbk, - bound_xl, bound_xl->fops->symlink, - state->name, &state->loc, state->params); - - return 0; -err: - server_symlink_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno, NULL, NULL, NULL, NULL); - return 0; -} - - -int -server_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, server_access_cbk, - bound_xl, bound_xl->fops->access, - &state->loc, state->mask); - return 0; -err: - server_access_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno); - return 0; -} - -int -server_fentrylk_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, server_fentrylk_cbk, bound_xl, - bound_xl->fops->fentrylk, - state->volume, state->fd, state->name, - state->cmd, state->type); - - return 0; -err: - server_fentrylk_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno); - return 0; -} - - -int -server_entrylk_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, server_entrylk_cbk, - bound_xl, bound_xl->fops->entrylk, - state->volume, &state->loc, state->name, - state->cmd, state->type); - return 0; -err: - server_entrylk_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno); - return 0; -} - - -int -server_finodelk_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, server_finodelk_cbk, bound_xl, - bound_xl->fops->finodelk, - state->volume, state->fd, state->cmd, &state->flock); - - return 0; -err: - server_finodelk_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno); - - return 0; -} - -int -server_inodelk_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, server_inodelk_cbk, - bound_xl, bound_xl->fops->inodelk, - state->volume, &state->loc, state->cmd, &state->flock); - return 0; -err: - server_inodelk_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno); - return 0; -} - -int -server_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, server_rmdir_cbk, - bound_xl, bound_xl->fops->rmdir, &state->loc); - return 0; -err: - server_rmdir_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno, NULL, NULL); - return 0; -} - -int -server_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, server_mkdir_cbk, - bound_xl, bound_xl->fops->mkdir, - &(state->loc), state->mode, state->params); - - return 0; -err: - server_mkdir_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno, NULL, NULL, NULL, NULL); - return 0; -} - - -int -server_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, server_mknod_cbk, - bound_xl, bound_xl->fops->mknod, - &(state->loc), state->mode, state->dev, - state->params); - - return 0; -err: - server_mknod_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno, NULL, NULL, NULL, NULL); - return 0; -} - - -int -server_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, server_fsyncdir_cbk, - bound_xl, - bound_xl->fops->fsyncdir, - state->fd, state->flags); - return 0; - -err: - server_fsyncdir_cbk (frame, NULL, frame->this, - state->resolve.op_ret, - state->resolve.op_errno); - return 0; -} - - -int - server_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; - - STACK_WIND (frame, server_readdir_cbk, - bound_xl, - bound_xl->fops->readdir, - state->fd, state->size, state->offset); - - return 0; -err: - server_readdir_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno, NULL); - return 0; -} - -int -server_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, server_readdirp_cbk, bound_xl, - bound_xl->fops->readdirp, state->fd, state->size, - state->offset); - - return 0; -err: - server_readdirp_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno, NULL); - return 0; -} - - -int -server_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); - - STACK_WIND (frame, server_opendir_cbk, - bound_xl, bound_xl->fops->opendir, - &state->loc, state->fd); - return 0; -err: - server_opendir_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno, NULL); - return 0; -} - - -int -server_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, server_statfs_cbk, - bound_xl, bound_xl->fops->statfs, - &state->loc); - return 0; - -err: - server_statfs_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno, NULL); - return 0; -} - - -int -server_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, server_removexattr_cbk, - bound_xl, bound_xl->fops->removexattr, - &state->loc, state->name); - return 0; -err: - server_removexattr_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno); - return 0; -} - -int -server_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, server_fgetxattr_cbk, - bound_xl, bound_xl->fops->fgetxattr, - state->fd, state->name); - return 0; -err: - server_fgetxattr_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno, NULL); - return 0; -} - - -int -server_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, server_xattrop_cbk, - bound_xl, bound_xl->fops->xattrop, - &state->loc, state->flags, state->dict); - return 0; -err: - server_xattrop_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno, NULL); - return 0; -} - -int -server_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, server_fxattrop_cbk, - bound_xl, bound_xl->fops->fxattrop, - state->fd, state->flags, state->dict); - return 0; -err: - server_fxattrop_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno, NULL); - return 0; -} - -int -server_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, server_setxattr_cbk, - bound_xl, bound_xl->fops->fsetxattr, - state->fd, state->dict, state->flags); - return 0; -err: - server_fsetxattr_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno); - - return 0; -} - -int -server_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, server_unlink_cbk, - bound_xl, bound_xl->fops->unlink, - &state->loc); - return 0; -err: - server_unlink_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno, NULL, NULL); - return 0; -} - -int -server_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, server_truncate_cbk, - bound_xl, bound_xl->fops->truncate, - &state->loc, state->offset); - return 0; -err: - server_truncate_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno, NULL, NULL); - return 0; -} - - - -int -server_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, server_fstat_cbk, - bound_xl, bound_xl->fops->fstat, - state->fd); - return 0; -err: - server_fstat_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno, NULL); - return 0; -} - - -int -server_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, server_setxattr_cbk, - bound_xl, bound_xl->fops->setxattr, - &state->loc, state->dict, state->flags); - return 0; -err: - server_setxattr_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno); - - return 0; -} - - -int -server_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, server_getxattr_cbk, - bound_xl, bound_xl->fops->getxattr, - &state->loc, state->name); - return 0; -err: - server_getxattr_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno, NULL); - return 0; -} - - -int -server_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, server_ftruncate_cbk, - bound_xl, bound_xl->fops->ftruncate, - state->fd, state->offset); - return 0; -err: - server_ftruncate_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno, NULL, NULL); - - return 0; -} - - -int -server_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, server_flush_cbk, - bound_xl, bound_xl->fops->flush, state->fd); - return 0; -err: - server_flush_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno); - - return 0; -} - - -int -server_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, server_fsync_cbk, - bound_xl, bound_xl->fops->fsync, - state->fd, state->flags); - return 0; -err: - server_fsync_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno, NULL, NULL); - - return 0; -} - -int -server_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, server_writev_cbk, - bound_xl, bound_xl->fops->writev, - state->fd, state->payload_vector, state->payload_count, - state->offset, state->iobref); - - return 0; -err: - server_writev_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno, NULL, NULL); - return 0; -} - - -int -server_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, server_readv_cbk, - bound_xl, bound_xl->fops->readv, - state->fd, state->size, state->offset); - - return 0; -err: - server_readv_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno, NULL, 0, NULL, NULL); - return 0; -} - - -int -server_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); - state->fd->flags = state->flags; - - STACK_WIND (frame, server_create_cbk, - bound_xl, bound_xl->fops->create, - &(state->loc), state->flags, state->mode, - state->fd, state->params); - - return 0; -err: - server_create_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno, NULL, NULL, NULL, - NULL, NULL); - return 0; -} - - -int -server_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, server_open_cbk, - bound_xl, bound_xl->fops->open, - &state->loc, state->flags, state->fd, 0); - - return 0; -err: - server_open_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno, NULL); - return 0; -} - - -int -server_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, server_readlink_cbk, - bound_xl, bound_xl->fops->readlink, - &state->loc, state->size); - return 0; -err: - server_readlink_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno, NULL, NULL); - return 0; -} - - -int -server_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, server_fsetattr_cbk, - bound_xl, bound_xl->fops->fsetattr, - state->fd, &state->stbuf, state->valid); - return 0; -err: - server_fsetattr_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno, NULL, NULL); - - return 0; -} - - -int -server_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, server_setattr_cbk, - bound_xl, bound_xl->fops->setattr, - &state->loc, &state->stbuf, state->valid); - return 0; -err: - server_setattr_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno, NULL, NULL); - - return 0; -} - - -int -server_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, server_stat_cbk, - bound_xl, bound_xl->fops->stat, &state->loc); - return 0; -err: - server_stat_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno, NULL); - return 0; -} - -int -server_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 = inode_new (state->itable); - else - state->is_revalidate = 1; - - STACK_WIND (frame, server_lookup_cbk, - bound_xl, bound_xl->fops->lookup, - &state->loc, state->dict); - - return 0; -err: - server_lookup_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno, NULL, NULL, NULL, NULL); - - return 0; -} - - - - -/* Fop section */ - -int -server_stat (rpcsvc_request_t *req) -{ - server_state_t *state = NULL; - call_frame_t *frame = NULL; - gfs3_stat_req args = {0,}; - char path[SERVER_PATH_MAX] = {0,}; - - if (!req) - return 0; - - /* Initialize args first, then decode */ - args.path = path; - - if (!xdr_to_stat_req (req->msg[0], &args)) { - //failed to decode msg; - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - frame = get_frame_from_request (req); - if (!frame) { - // something wrong, mostly insufficient memory - req->rpc_err = GARBAGE_ARGS; /* TODO */ - goto out; - } - frame->root->op = GF_FOP_STAT; - - state = CALL_STATE (frame); - if (!state->conn->bound_xl) { - /* auth failure, request on subvolume without setvolume */ - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - state->resolve.type = RESOLVE_MUST; - memcpy (state->resolve.gfid, args.gfid, 16); - state->resolve.path = gf_strdup (args.path); - - resolve_and_resume (frame, server_stat_resume); -out: - return 0; -} - - -int -server_setattr (rpcsvc_request_t *req) -{ - server_state_t *state = NULL; - call_frame_t *frame = NULL; - gfs3_setattr_req args = {0,}; - char path[SERVER_PATH_MAX] = {0,}; - - if (!req) - return 0; - - args.path = path; - - if (!xdr_to_setattr_req (req->msg[0], &args)) { - //failed to decode msg; - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - frame = get_frame_from_request (req); - if (!frame) { - // something wrong, mostly insufficient memory - req->rpc_err = GARBAGE_ARGS; /* TODO */ - goto out; - } - frame->root->op = GF_FOP_SETATTR; - - state = CALL_STATE (frame); - if (!state->conn->bound_xl) { - /* auth failure, request on subvolume without setvolume */ - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - state->resolve.type = RESOLVE_MUST; - memcpy (state->resolve.gfid, args.gfid, 16); - state->resolve.path = gf_strdup (args.path); - - gf_stat_to_iatt (&args.stbuf, &state->stbuf); - state->valid = args.valid; - - resolve_and_resume (frame, server_setattr_resume); -out: - return 0; -} - - -int -server_fsetattr (rpcsvc_request_t *req) -{ - server_state_t *state = NULL; - call_frame_t *frame = NULL; - gfs3_fsetattr_req args = {0,}; - - if (!req) - return 0; - - if (!xdr_to_fsetattr_req (req->msg[0], &args)) { - //failed to decode msg; - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - frame = get_frame_from_request (req); - if (!frame) { - // something wrong, mostly insufficient memory - req->rpc_err = GARBAGE_ARGS; /* TODO */ - goto out; - } - frame->root->op = GF_FOP_FSETATTR; - - state = CALL_STATE (frame); - if (!state->conn->bound_xl) { - /* auth failure, request on subvolume without setvolume */ - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - state->resolve.type = RESOLVE_MUST; - state->resolve.fd_no = args.fd; - - gf_stat_to_iatt (&args.stbuf, &state->stbuf); - state->valid = args.valid; - - resolve_and_resume (frame, server_fsetattr_resume); -out: - return 0; -} - - -int -server_readlink (rpcsvc_request_t *req) -{ - server_state_t *state = NULL; - call_frame_t *frame = NULL; - gfs3_readlink_req args = {0,}; - char path[SERVER_PATH_MAX] = {0,}; - - if (!req) - return 0; - - args.path = path; - - if (!xdr_to_readlink_req (req->msg[0], &args)) { - //failed to decode msg; - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - frame = get_frame_from_request (req); - if (!frame) { - // something wrong, mostly insufficient memory - req->rpc_err = GARBAGE_ARGS; /* TODO */ - goto out; - } - frame->root->op = GF_FOP_READLINK; - - state = CALL_STATE (frame); - if (!state->conn->bound_xl) { - /* auth failure, request on subvolume without setvolume */ - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - state->resolve.type = RESOLVE_MUST; - memcpy (state->resolve.gfid, args.gfid, 16); - state->resolve.path = gf_strdup (args.path); - - state->size = args.size; - - resolve_and_resume (frame, server_readlink_resume); -out: - return 0; -} - - -int -server_create (rpcsvc_request_t *req) -{ - server_state_t *state = NULL; - call_frame_t *frame = NULL; - dict_t *params = NULL; - char *buf = NULL; - gfs3_create_req args = {0,}; - char path[SERVER_PATH_MAX] = {0,}; - char bname[SERVER_PATH_MAX] = {0,}; - int ret = 0; - if (!req) - return 0; - - args.path = path; - args.bname = bname; - - if (!xdr_to_create_req (req->msg[0], &args)) { - //failed to decode msg; - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - frame = get_frame_from_request (req); - if (!frame) { - // something wrong, mostly insufficient memory - req->rpc_err = GARBAGE_ARGS; /* TODO */ - goto out; - } - frame->root->op = GF_FOP_CREATE; - - state = CALL_STATE (frame); - if (!state->conn->bound_xl) { - /* auth failure, request on subvolume without setvolume */ - req->rpc_err = GARBAGE_ARGS; - goto out; - } - if (args.dict.dict_len) { - /* Unserialize the dictionary */ - params = dict_new (); - - buf = memdup (args.dict.dict_val, args.dict.dict_len); - if (buf == NULL) { - gf_log (state->conn->bound_xl->name, GF_LOG_ERROR, - "out of memory"); - goto out; - } - - ret = dict_unserialize (buf, args.dict.dict_len, - ¶ms); - if (ret < 0) { - gf_log (state->conn->bound_xl->name, GF_LOG_ERROR, - "%"PRId64": %s (%"PRId64"): failed to " - "unserialize req-buffer to dictionary", - frame->root->unique, state->resolve.path, - state->resolve.ino); - goto out; - } - - state->params = params; - - params->extra_free = buf; - - buf = NULL; - } - - state->resolve.type = RESOLVE_NOT; - state->resolve.path = gf_strdup (args.path); - state->resolve.bname = gf_strdup (args.bname); - state->mode = args.mode; - state->flags = gf_flags_to_flags (args.flags); - memcpy (state->resolve.pargfid, args.pargfid, 16); - - resolve_and_resume (frame, server_create_resume); - - /* memory allocated by libc, don't use GF_FREE */ - if (args.dict.dict_val != NULL) { - free (args.dict.dict_val); - } - - return 0; -out: - if (params) - dict_unref (params); - - if (buf) { - GF_FREE (buf); - } - - /* memory allocated by libc, don't use GF_FREE */ - if (args.dict.dict_val != NULL) { - free (args.dict.dict_val); - } - - return 0; -} - - -int -server_open (rpcsvc_request_t *req) -{ - server_state_t *state = NULL; - call_frame_t *frame = NULL; - gfs3_open_req args = {0,}; - char path[SERVER_PATH_MAX] = {0,}; - - if (!req) - return 0; - - args.path = path; - - if (!xdr_to_open_req (req->msg[0], &args)) { - //failed to decode msg; - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - frame = get_frame_from_request (req); - if (!frame) { - // something wrong, mostly insufficient memory - req->rpc_err = GARBAGE_ARGS; /* TODO */ - goto out; - } - frame->root->op = GF_FOP_OPEN; - - state = CALL_STATE (frame); - if (!state->conn->bound_xl) { - /* auth failure, request on subvolume without setvolume */ - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - state->resolve.type = RESOLVE_MUST; - memcpy (state->resolve.gfid, args.gfid, 16); - state->resolve.path = gf_strdup (args.path); - - state->flags = gf_flags_to_flags (args.flags); - - resolve_and_resume (frame, server_open_resume); -out: - return 0; -} - - -int -server_readv (rpcsvc_request_t *req) -{ - server_state_t *state = NULL; - call_frame_t *frame = NULL; - gfs3_read_req args = {0,}; - - if (!req) - goto out; - - if (!xdr_to_readv_req (req->msg[0], &args)) { - //failed to decode msg; - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - frame = get_frame_from_request (req); - if (!frame) { - // something wrong, mostly insufficient memory - req->rpc_err = GARBAGE_ARGS; /* TODO */ - goto out; - } - frame->root->op = GF_FOP_READ; - - state = CALL_STATE (frame); - if (!state->conn->bound_xl) { - /* auth failure, request on subvolume without setvolume */ - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - state->resolve.type = RESOLVE_MUST; - state->resolve.fd_no = args.fd; - state->size = args.size; - state->offset = args.offset; - - resolve_and_resume (frame, server_readv_resume); -out: - return 0; -} - - -int -server_writev (rpcsvc_request_t *req) -{ - server_state_t *state = NULL; - call_frame_t *frame = NULL; - gfs3_write_req args = {0,}; - ssize_t len = 0; - int i = 0; - - if (!req) - return 0; - - len = xdr_to_writev_req (req->msg[0], &args); - if (len == 0) { - //failed to decode msg; - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - frame = get_frame_from_request (req); - if (!frame) { - // something wrong, mostly insufficient memory - req->rpc_err = GARBAGE_ARGS; /* TODO */ - goto out; - } - frame->root->op = GF_FOP_WRITE; - - state = CALL_STATE (frame); - if (!state->conn->bound_xl) { - /* auth failure, request on subvolume without setvolume */ - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - state->resolve.type = RESOLVE_MUST; - state->resolve.fd_no = args.fd; - state->offset = args.offset; - 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]; - } - - for (i = 0; i < state->payload_count; i++) { - state->size += state->payload_vector[i].iov_len; - } - - resolve_and_resume (frame, server_writev_resume); -out: - return 0; -} - - -int -server_writev_vec (rpcsvc_request_t *req, struct iovec *payload, - int payload_count, struct iobref *iobref) -{ - return server_writev (req); -} - - -int -server_release (rpcsvc_request_t *req) -{ - server_connection_t *conn = NULL; - gfs3_release_req args = {0,}; - gf_common_rsp rsp = {0,}; - - if (!xdr_to_release_req (req->msg[0], &args)) { - //failed to decode msg; - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - conn = req->trans->xl_private; - gf_fd_put (conn->fdtable, args.fd); - - server_submit_reply (NULL, req, &rsp, NULL, 0, NULL, - xdr_serialize_common_rsp); -out: - return 0; -} - -int -server_releasedir (rpcsvc_request_t *req) -{ - server_connection_t *conn = NULL; - gfs3_releasedir_req args = {0,}; - gf_common_rsp rsp = {0,}; - - if (!xdr_to_release_req (req->msg[0], &args)) { - //failed to decode msg; - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - conn = req->trans->xl_private; - gf_fd_put (conn->fdtable, args.fd); - - server_submit_reply (NULL, req, &rsp, NULL, 0, NULL, - xdr_serialize_common_rsp); -out: - return 0; -} - - -int -server_fsync (rpcsvc_request_t *req) -{ - server_state_t *state = NULL; - call_frame_t *frame = NULL; - gfs3_fsync_req args = {0,}; - - if (!req) - return 0; - - if (!xdr_to_fsync_req (req->msg[0], &args)) { - //failed to decode msg; - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - frame = get_frame_from_request (req); - if (!frame) { - // something wrong, mostly insufficient memory - req->rpc_err = GARBAGE_ARGS; /* TODO */ - goto out; - } - frame->root->op = GF_FOP_FSYNC; - - state = CALL_STATE (frame); - if (!state->conn->bound_xl) { - /* auth failure, request on subvolume without setvolume */ - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - state->resolve.type = RESOLVE_MUST; - state->resolve.fd_no = args.fd; - state->flags = args.data; - - resolve_and_resume (frame, server_fsync_resume); -out: - return 0; -} - - - -int -server_flush (rpcsvc_request_t *req) -{ - server_state_t *state = NULL; - call_frame_t *frame = NULL; - gfs3_flush_req args = {0,}; - - if (!req) - return 0; - - if (!xdr_to_flush_req (req->msg[0], &args)) { - //failed to decode msg; - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - frame = get_frame_from_request (req); - if (!frame) { - // something wrong, mostly insufficient memory - req->rpc_err = GARBAGE_ARGS; /* TODO */ - goto out; - } - frame->root->op = GF_FOP_FLUSH; - - state = CALL_STATE (frame); - if (!state->conn->bound_xl) { - /* auth failure, request on subvolume without setvolume */ - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - state->resolve.type = RESOLVE_MUST; - state->resolve.fd_no = args.fd; - - resolve_and_resume (frame, server_flush_resume); -out: - return 0; -} - - - -int -server_ftruncate (rpcsvc_request_t *req) -{ - server_state_t *state = NULL; - call_frame_t *frame = NULL; - gfs3_ftruncate_req args = {0,}; - - if (!req) - return 0; - - if (!xdr_to_ftruncate_req (req->msg[0], &args)) { - //failed to decode msg; - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - frame = get_frame_from_request (req); - if (!frame) { - // something wrong, mostly insufficient memory - req->rpc_err = GARBAGE_ARGS; /* TODO */ - goto out; - } - frame->root->op = GF_FOP_FTRUNCATE; - - state = CALL_STATE (frame); - if (!state->conn->bound_xl) { - /* auth failure, request on subvolume without setvolume */ - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - state->resolve.type = RESOLVE_MUST; - state->resolve.fd_no = args.fd; - state->offset = args.offset; - - resolve_and_resume (frame, server_ftruncate_resume); -out: - return 0; -} - - -int -server_fstat (rpcsvc_request_t *req) -{ - server_state_t *state = NULL; - call_frame_t *frame = NULL; - gfs3_write_req args = {0,}; - - if (!req) - return 0; - - if (!xdr_to_fstat_req (req->msg[0], &args)) { - //failed to decode msg; - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - frame = get_frame_from_request (req); - if (!frame) { - // something wrong, mostly insufficient memory - req->rpc_err = GARBAGE_ARGS; /* TODO */ - goto out; - } - frame->root->op = GF_FOP_FSTAT; - - state = CALL_STATE (frame); - if (!state->conn->bound_xl) { - /* auth failure, request on subvolume without setvolume */ - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - state->resolve.type = RESOLVE_MUST; - state->resolve.fd_no = args.fd; - - resolve_and_resume (frame, server_fstat_resume); -out: - return 0; -} - - -int -server_truncate (rpcsvc_request_t *req) -{ - server_state_t *state = NULL; - call_frame_t *frame = NULL; - gfs3_truncate_req args = {0,}; - char path[SERVER_PATH_MAX] = {0,}; - - if (!req) - return 0; - - args.path = path; - if (!xdr_to_truncate_req (req->msg[0], &args)) { - //failed to decode msg; - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - frame = get_frame_from_request (req); - if (!frame) { - // something wrong, mostly insufficient memory - req->rpc_err = GARBAGE_ARGS; /* TODO */ - goto out; - } - frame->root->op = GF_FOP_TRUNCATE; - - state = CALL_STATE (frame); - if (!state->conn->bound_xl) { - /* auth failure, request on subvolume without setvolume */ - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - state->resolve.type = RESOLVE_MUST; - state->resolve.path = gf_strdup (args.path); - memcpy (state->resolve.gfid, args.gfid, 16); - state->offset = args.offset; - - resolve_and_resume (frame, server_truncate_resume); -out: - return 0; -} - - - -int -server_unlink (rpcsvc_request_t *req) -{ - server_state_t *state = NULL; - call_frame_t *frame = NULL; - gfs3_unlink_req args = {0,}; - char path[SERVER_PATH_MAX] = {0,}; - char bname[SERVER_PATH_MAX] = {0,}; - - if (!req) - return 0; - - args.path = path; - args.bname = bname; - - if (!xdr_to_unlink_req (req->msg[0], &args)) { - //failed to decode msg; - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - frame = get_frame_from_request (req); - if (!frame) { - // something wrong, mostly insufficient memory - req->rpc_err = GARBAGE_ARGS; /* TODO */ - goto out; - } - frame->root->op = GF_FOP_UNLINK; - - state = CALL_STATE (frame); - if (!state->conn->bound_xl) { - /* auth failure, request on subvolume without setvolume */ - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - state->resolve.type = RESOLVE_MUST; - state->resolve.path = gf_strdup (args.path); - state->resolve.bname = gf_strdup (args.bname); - memcpy (state->resolve.pargfid, args.pargfid, 16); - - resolve_and_resume (frame, server_unlink_resume); -out: - return 0; -} - - -int -server_setxattr (rpcsvc_request_t *req) -{ - server_state_t *state = NULL; - dict_t *dict = NULL; - call_frame_t *frame = NULL; - server_connection_t *conn = NULL; - char *buf = NULL; - gfs3_setxattr_req args = {0,}; - char path[SERVER_PATH_MAX] = {0,}; - char dict_val[(16 * 1024)] = {0, }; - int32_t ret = -1; - - if (!req) - return 0; - - conn = req->trans->xl_private; - - args.path = path; - args.dict.dict_val = dict_val; - - if (!xdr_to_setxattr_req (req->msg[0], &args)) { - //failed to decode msg; - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - frame = get_frame_from_request (req); - if (!frame) { - // something wrong, mostly insufficient memory - req->rpc_err = GARBAGE_ARGS; /* TODO */ - goto out; - } - frame->root->op = GF_FOP_SETXATTR; - - state = CALL_STATE (frame); - if (!state->conn->bound_xl) { - /* auth failure, request on subvolume without setvolume */ - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - state->resolve.type = RESOLVE_MUST; - state->resolve.path = gf_strdup (args.path); - state->flags = args.flags; - memcpy (state->resolve.gfid, args.gfid, 16); - - if (args.dict.dict_len) { - dict = dict_new (); - buf = memdup (args.dict.dict_val, args.dict.dict_len); - GF_VALIDATE_OR_GOTO (conn->bound_xl->name, buf, out); - - ret = dict_unserialize (buf, args.dict.dict_len, &dict); - if (ret < 0) { - gf_log (conn->bound_xl->name, GF_LOG_ERROR, - "%"PRId64": %s (%"PRId64"): failed to " - "unserialize request buffer to dictionary", - frame->root->unique, state->loc.path, - state->resolve.ino); - goto err; - } - - dict->extra_free = buf; - buf = NULL; - - state->dict = dict; - } - - resolve_and_resume (frame, server_setxattr_resume); - - return 0; -err: - if (dict) - dict_unref (dict); - - server_setxattr_cbk (frame, NULL, frame->this, -1, EINVAL); -out: - if (buf) - GF_FREE (buf); - return 0; - -} - - - -int -server_fsetxattr (rpcsvc_request_t *req) -{ - server_state_t *state = NULL; - dict_t *dict = NULL; - server_connection_t *conn = NULL; - call_frame_t *frame = NULL; - char *buf = NULL; - gfs3_fsetxattr_req args = {0,}; - char dict_val[(16 *1024)] = {0,}; - int32_t ret = -1; - - if (!req) - return 0; - - conn = req->trans->xl_private; - - args.dict.dict_val = dict_val; - if (!xdr_to_fsetxattr_req (req->msg[0], &args)) { - //failed to decode msg; - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - frame = get_frame_from_request (req); - if (!frame) { - // something wrong, mostly insufficient memory - req->rpc_err = GARBAGE_ARGS; /* TODO */ - goto out; - } - frame->root->op = GF_FOP_FSETXATTR; - - state = CALL_STATE (frame); - if (!state->conn->bound_xl) { - /* auth failure, request on subvolume without setvolume */ - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - state->resolve.type = RESOLVE_MUST; - state->resolve.fd_no = args.fd; - state->flags = args.flags; - - if (args.dict.dict_len) { - dict = dict_new (); - buf = memdup (args.dict.dict_val, args.dict.dict_len); - GF_VALIDATE_OR_GOTO (conn->bound_xl->name, buf, out); - - ret = dict_unserialize (buf, args.dict.dict_len, &dict); - if (ret < 0) { - gf_log (conn->bound_xl->name, GF_LOG_ERROR, - "%"PRId64": %s (%"PRId64"): failed to " - "unserialize request buffer to dictionary", - frame->root->unique, state->loc.path, - state->resolve.ino); - goto err; - } - dict->extra_free = buf; - buf = NULL; - state->dict = dict; - } - - resolve_and_resume (frame, server_fsetxattr_resume); - - return 0; -err: - if (dict) - dict_unref (dict); - - server_setxattr_cbk (frame, NULL, frame->this, -1, EINVAL); -out: - if (buf) - GF_FREE (buf); - return 0; -} - - - -int -server_fxattrop (rpcsvc_request_t *req) -{ - dict_t *dict = NULL; - server_state_t *state = NULL; - server_connection_t *conn = NULL; - call_frame_t *frame = NULL; - char *buf = NULL; - gfs3_fxattrop_req args = {0,}; - char dict_val[(16 *1024)] = {0,}; - int32_t ret = -1; - - if (!req) - return 0; - - conn = req->trans->xl_private; - - args.dict.dict_val = dict_val; - if (!xdr_to_fxattrop_req (req->msg[0], &args)) { - //failed to decode msg; - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - frame = get_frame_from_request (req); - if (!frame) { - // something wrong, mostly insufficient memory - req->rpc_err = GARBAGE_ARGS; /* TODO */ - goto out; - } - frame->root->op = GF_FOP_FXATTROP; - - state = CALL_STATE(frame); - if (!state->conn->bound_xl) { - /* auth failure, request on subvolume without setvolume */ - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - state->resolve.type = RESOLVE_MUST; - state->resolve.fd_no = args.fd; - state->flags = args.flags; - memcpy (state->resolve.gfid, args.gfid, 16); - - if (args.dict.dict_len) { - /* Unserialize the dictionary */ - dict = dict_new (); - - buf = memdup (args.dict.dict_val, args.dict.dict_len); - GF_VALIDATE_OR_GOTO (conn->bound_xl->name, buf, out); - - ret = dict_unserialize (buf, args.dict.dict_len, &dict); - if (ret < 0) { - gf_log (conn->bound_xl->name, GF_LOG_ERROR, - "fd - %"PRId64" (%"PRId64"): failed to unserialize " - "request buffer to dictionary", - state->resolve.fd_no, state->fd->inode->ino); - goto fail; - } - dict->extra_free = buf; - buf = NULL; - - state->dict = dict; - } - - resolve_and_resume (frame, server_fxattrop_resume); - - return 0; - -fail: - if (dict) - dict_unref (dict); - - server_fxattrop_cbk (frame, NULL, frame->this, -1, EINVAL, NULL); -out: - return 0; -} - - - -int -server_xattrop (rpcsvc_request_t *req) -{ - dict_t *dict = NULL; - server_state_t *state = NULL; - server_connection_t *conn = NULL; - call_frame_t *frame = NULL; - char *buf = NULL; - gfs3_xattrop_req args = {0,}; - char dict_val[(16 *1024)] = {0,}; - char path[SERVER_PATH_MAX] = {0,}; - int32_t ret = -1; - - if (!req) - return 0; - - conn = req->trans->xl_private; - args.dict.dict_val = dict_val; - args.path = path; - - if (!xdr_to_xattrop_req (req->msg[0], &args)) { - //failed to decode msg; - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - frame = get_frame_from_request (req); - if (!frame) { - // something wrong, mostly insufficient memory - req->rpc_err = GARBAGE_ARGS; /* TODO */ - goto out; - } - frame->root->op = GF_FOP_XATTROP; - - state = CALL_STATE(frame); - if (!state->conn->bound_xl) { - /* auth failure, request on subvolume without setvolume */ - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - state->resolve.type = RESOLVE_MUST; - state->resolve.path = gf_strdup (args.path); - state->flags = args.flags; - memcpy (state->resolve.gfid, args.gfid, 16); - - if (args.dict.dict_len) { - /* Unserialize the dictionary */ - dict = dict_new (); - - buf = memdup (args.dict.dict_val, args.dict.dict_len); - GF_VALIDATE_OR_GOTO (conn->bound_xl->name, buf, out); - - ret = dict_unserialize (buf, args.dict.dict_len, &dict); - if (ret < 0) { - gf_log (conn->bound_xl->name, GF_LOG_ERROR, - "fd - %"PRId64" (%"PRId64"): failed to unserialize " - "request buffer to dictionary", - state->resolve.fd_no, state->fd->inode->ino); - goto fail; - } - dict->extra_free = buf; - buf = NULL; - - state->dict = dict; - } - - resolve_and_resume (frame, server_xattrop_resume); - - return 0; -fail: - if (dict) - dict_unref (dict); - - server_xattrop_cbk (frame, NULL, frame->this, -1, EINVAL, NULL); -out: - return 0; -} - - -int -server_getxattr (rpcsvc_request_t *req) -{ - server_state_t *state = NULL; - call_frame_t *frame = NULL; - gfs3_getxattr_req args = {0,}; - char path[SERVER_PATH_MAX] = {0,}; - char name[4096] = {0,}; - - if (!req) - return 0; - - args.path = path; - args.name = name; - - if (!xdr_to_getxattr_req (req->msg[0], &args)) { - //failed to decode msg; - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - frame = get_frame_from_request (req); - if (!frame) { - // something wrong, mostly insufficient memory - req->rpc_err = GARBAGE_ARGS; /* TODO */ - goto out; - } - frame->root->op = GF_FOP_GETXATTR; - - state = CALL_STATE (frame); - if (!state->conn->bound_xl) { - /* auth failure, request on subvolume without setvolume */ - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - state->resolve.type = RESOLVE_MUST; - state->resolve.path = gf_strdup (args.path); - memcpy (state->resolve.gfid, args.gfid, 16); - - if (args.namelen) - state->name = gf_strdup (args.name); - - resolve_and_resume (frame, server_getxattr_resume); -out: - return 0; -} - - -int -server_fgetxattr (rpcsvc_request_t *req) -{ - server_state_t *state = NULL; - call_frame_t *frame = NULL; - gfs3_fgetxattr_req args = {0,}; - char name[4096] = {0,}; - - if (!req) - return 0; - - args.name = name; - if (!xdr_to_fgetxattr_req (req->msg[0], &args)) { - //failed to decode msg; - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - frame = get_frame_from_request (req); - if (!frame) { - // something wrong, mostly insufficient memory - req->rpc_err = GARBAGE_ARGS; /* TODO */ - goto out; - } - frame->root->op = GF_FOP_FGETXATTR; - - state = CALL_STATE (frame); - if (!state->conn->bound_xl) { - /* auth failure, request on subvolume without setvolume */ - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - state->resolve.type = RESOLVE_MUST; - state->resolve.fd_no = args.fd; - - if (args.namelen) - state->name = gf_strdup (args.name); - - resolve_and_resume (frame, server_fgetxattr_resume); -out: - return 0; -} - - - -int -server_removexattr (rpcsvc_request_t *req) -{ - server_state_t *state = NULL; - call_frame_t *frame = NULL; - gfs3_removexattr_req args = {0,}; - char path[SERVER_PATH_MAX] = {0,}; - char name[4096] = {0,}; - - if (!req) - return 0; - - args.path = path; - args.name = name; - if (!xdr_to_removexattr_req (req->msg[0], &args)) { - //failed to decode msg; - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - frame = get_frame_from_request (req); - if (!frame) { - // something wrong, mostly insufficient memory - req->rpc_err = GARBAGE_ARGS; /* TODO */ - goto out; - } - frame->root->op = GF_FOP_REMOVEXATTR; - - state = CALL_STATE (frame); - if (!state->conn->bound_xl) { - /* auth failure, request on subvolume without setvolume */ - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - state->resolve.type = RESOLVE_MUST; - state->resolve.path = gf_strdup (args.path); - memcpy (state->resolve.gfid, args.gfid, 16); - state->name = gf_strdup (args.name); - - resolve_and_resume (frame, server_removexattr_resume); -out: - return 0; -} - - - - -int -server_opendir (rpcsvc_request_t *req) -{ - server_state_t *state = NULL; - call_frame_t *frame = NULL; - gfs3_opendir_req args = {0,}; - char path[SERVER_PATH_MAX] = {0,}; - - if (!req) - return 0; - - args.path = path; - - if (!xdr_to_opendir_req (req->msg[0], &args)) { - //failed to decode msg; - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - frame = get_frame_from_request (req); - if (!frame) { - // something wrong, mostly insufficient memory - req->rpc_err = GARBAGE_ARGS; /* TODO */ - goto out; - } - frame->root->op = GF_FOP_OPENDIR; - - state = CALL_STATE (frame); - if (!state->conn->bound_xl) { - /* auth failure, request on subvolume without setvolume */ - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - state->resolve.type = RESOLVE_MUST; - state->resolve.path = gf_strdup (args.path); - memcpy (state->resolve.gfid, args.gfid, 16); - - resolve_and_resume (frame, server_opendir_resume); -out: - return 0; -} - - -int -server_readdirp (rpcsvc_request_t *req) -{ - server_state_t *state = NULL; - call_frame_t *frame = NULL; - gfs3_readdirp_req args = {0,}; - size_t headers_size = 0; - - if (!req) - return 0; - - if (!xdr_to_readdirp_req (req->msg[0], &args)) { - //failed to decode msg; - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - frame = get_frame_from_request (req); - if (!frame) { - // something wrong, mostly insufficient memory - req->rpc_err = GARBAGE_ARGS; /* TODO */ - goto out; - } - frame->root->op = GF_FOP_READDIRP; - - state = CALL_STATE(frame); - if (!state->conn->bound_xl) { - /* auth failure, request on subvolume without setvolume */ - req->rpc_err = GARBAGE_ARGS; - 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 (gfs3_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; - - resolve_and_resume (frame, server_readdirp_resume); -out: - return 0; -} - -int -server_readdir (rpcsvc_request_t *req) -{ - server_state_t *state = NULL; - call_frame_t *frame = NULL; - gfs3_readdir_req args = {0,}; - size_t headers_size = 0; - - if (!req) - return 0; - - if (!xdr_to_readdir_req (req->msg[0], &args)) { - //failed to decode msg; - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - frame = get_frame_from_request (req); - if (!frame) { - // something wrong, mostly insufficient memory - req->rpc_err = GARBAGE_ARGS; /* TODO */ - goto out; - } - frame->root->op = GF_FOP_READDIR; - - state = CALL_STATE(frame); - if (!state->conn->bound_xl) { - /* auth failure, request on subvolume without setvolume */ - req->rpc_err = GARBAGE_ARGS; - 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 (gfs3_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; - - resolve_and_resume (frame, server_readdir_resume); -out: - return 0; -} - -int -server_fsyncdir (rpcsvc_request_t *req) -{ - server_state_t *state = NULL; - call_frame_t *frame = NULL; - gfs3_fsyncdir_req args = {0,}; - - if (!req) - return 0; - - if (!xdr_to_fsyncdir_req (req->msg[0], &args)) { - //failed to decode msg; - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - frame = get_frame_from_request (req); - if (!frame) { - // something wrong, mostly insufficient memory - req->rpc_err = GARBAGE_ARGS; /* TODO */ - goto out; - } - frame->root->op = GF_FOP_FSYNCDIR; - - state = CALL_STATE(frame); - if (!state->conn->bound_xl) { - /* auth failure, request on subvolume without setvolume */ - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - state->resolve.type = RESOLVE_MUST; - state->resolve.fd_no = args.fd; - state->flags = args.data; - - resolve_and_resume (frame, server_fsyncdir_resume); -out: - return 0; -} - - - -int -server_mknod (rpcsvc_request_t *req) -{ - server_state_t *state = NULL; - call_frame_t *frame = NULL; - dict_t *params = NULL; - char *buf = NULL; - gfs3_mknod_req args = {0,}; - char bname[SERVER_PATH_MAX] = {0,}; - char path[SERVER_PATH_MAX] = {0,}; - int ret = 0; - - if (!req) - return 0; - - args.path = path; - args.bname = bname; - - if (!xdr_to_mknod_req (req->msg[0], &args)) { - //failed to decode msg; - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - frame = get_frame_from_request (req); - if (!frame) { - // something wrong, mostly insufficient memory - req->rpc_err = GARBAGE_ARGS; /* TODO */ - goto out; - } - frame->root->op = GF_FOP_MKNOD; - - state = CALL_STATE (frame); - if (!state->conn->bound_xl) { - /* auth failure, request on subvolume without setvolume */ - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - if (args.dict.dict_len) { - /* Unserialize the dictionary */ - params = dict_new (); - - buf = memdup (args.dict.dict_val, args.dict.dict_len); - if (buf == NULL) { - gf_log (state->conn->bound_xl->name, GF_LOG_ERROR, - "out of memory"); - goto out; - } - - ret = dict_unserialize (buf, args.dict.dict_len, - ¶ms); - if (ret < 0) { - gf_log (state->conn->bound_xl->name, GF_LOG_ERROR, - "%"PRId64": %s (%"PRId64"): failed to " - "unserialize req-buffer to dictionary", - frame->root->unique, state->resolve.path, - state->resolve.ino); - goto out; - } - - state->params = params; - - params->extra_free = buf; - - buf = NULL; - } - - state->resolve.type = RESOLVE_NOT; - memcpy (state->resolve.pargfid, args.pargfid, 16); - state->resolve.path = gf_strdup (args.path); - state->resolve.bname = gf_strdup (args.bname); - - state->mode = args.mode; - state->dev = args.dev; - - resolve_and_resume (frame, server_mknod_resume); - - /* memory allocated by libc, don't use GF_FREE */ - if (args.dict.dict_val != NULL) { - free (args.dict.dict_val); - } - - return 0; -out: - if (params) - dict_unref (params); - - if (buf) { - GF_FREE (buf); - } - - /* memory allocated by libc, don't use GF_FREE */ - if (args.dict.dict_val != NULL) { - free (args.dict.dict_val); - } - - return 0; - -} - - -int -server_mkdir (rpcsvc_request_t *req) -{ - server_state_t *state = NULL; - call_frame_t *frame = NULL; - dict_t *params = NULL; - char *buf = NULL; - gfs3_mkdir_req args = {0,}; - char bname[SERVER_PATH_MAX] = {0,}; - char path[SERVER_PATH_MAX] = {0,}; - int ret = 0; - - if (!req) - return 0; - - args.path = path; - args.bname = bname; - - if (!xdr_to_mkdir_req (req->msg[0], &args)) { - //failed to decode msg; - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - frame = get_frame_from_request (req); - if (!frame) { - // something wrong, mostly insufficient memory - req->rpc_err = GARBAGE_ARGS; /* TODO */ - goto out; - } - frame->root->op = GF_FOP_MKDIR; - - state = CALL_STATE (frame); - if (!state->conn->bound_xl) { - /* auth failure, request on subvolume without setvolume */ - req->rpc_err = GARBAGE_ARGS; - goto out; - } - if (args.dict.dict_len) { - /* Unserialize the dictionary */ - params = dict_new (); - - buf = memdup (args.dict.dict_val, args.dict.dict_len); - if (buf == NULL) { - gf_log (state->conn->bound_xl->name, GF_LOG_ERROR, - "out of memory"); - goto out; - } - - ret = dict_unserialize (buf, args.dict.dict_len, - ¶ms); - if (ret < 0) { - gf_log (state->conn->bound_xl->name, GF_LOG_ERROR, - "%"PRId64": %s (%"PRId64"): failed to " - "unserialize req-buffer to dictionary", - frame->root->unique, state->resolve.path, - state->resolve.ino); - goto out; - } - - state->params = params; - - params->extra_free = buf; - - buf = NULL; - } - - state->resolve.type = RESOLVE_NOT; - memcpy (state->resolve.pargfid, args.pargfid, 16); - state->resolve.path = gf_strdup (args.path); - state->resolve.bname = gf_strdup (args.bname); - - state->mode = args.mode; - - resolve_and_resume (frame, server_mkdir_resume); - - if (args.dict.dict_val != NULL) { - /* memory allocated by libc, don't use GF_FREE */ - free (args.dict.dict_val); - } - - return 0; -out: - if (params) - dict_unref (params); - - if (buf) { - GF_FREE (buf); - } - - if (args.dict.dict_val != NULL) { - /* memory allocated by libc, don't use GF_FREE */ - free (args.dict.dict_val); - } - - return 0; -} - - -int -server_rmdir (rpcsvc_request_t *req) -{ - server_state_t *state = NULL; - call_frame_t *frame = NULL; - gfs3_rmdir_req args = {0,}; - char bname[SERVER_PATH_MAX] = {0,}; - char path[SERVER_PATH_MAX] = {0,}; - - if (!req) - return 0; - - args.path = path; - args.bname = bname; - - if (!xdr_to_rmdir_req (req->msg[0], &args)) { - //failed to decode msg; - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - frame = get_frame_from_request (req); - if (!frame) { - // something wrong, mostly insufficient memory - req->rpc_err = GARBAGE_ARGS; /* TODO */ - goto out; - } - frame->root->op = GF_FOP_RMDIR; - - state = CALL_STATE (frame); - if (!state->conn->bound_xl) { - /* auth failure, request on subvolume without setvolume */ - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - state->resolve.type = RESOLVE_MUST; - memcpy (state->resolve.pargfid, args.pargfid, 16); - state->resolve.path = gf_strdup (args.path); - state->resolve.bname = gf_strdup (args.bname); - - resolve_and_resume (frame, server_rmdir_resume); -out: - return 0; -} - - - -int -server_inodelk (rpcsvc_request_t *req) -{ - server_state_t *state = NULL; - call_frame_t *frame = NULL; - gfs3_inodelk_req args = {0,}; - char path[SERVER_PATH_MAX] = {0,}; - char volume[4096] = {0,}; - int cmd = 0; - - if (!req) - return 0; - - args.path = path; - args.volume = volume; - - if (!xdr_to_inodelk_req (req->msg[0], &args)) { - //failed to decode msg; - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - frame = get_frame_from_request (req); - if (!frame) { - // something wrong, mostly insufficient memory - req->rpc_err = GARBAGE_ARGS; /* TODO */ - goto out; - } - frame->root->op = GF_FOP_INODELK; - - state = CALL_STATE (frame); - if (!state->conn->bound_xl) { - /* auth failure, request on subvolume without setvolume */ - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - state->resolve.type = RESOLVE_EXACT; - memcpy (state->resolve.gfid, args.gfid, 16); - state->resolve.path = gf_strdup (args.path); - - 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_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; - } - - resolve_and_resume (frame, server_inodelk_resume); -out: - return 0; -} - -int -server_finodelk (rpcsvc_request_t *req) -{ - server_state_t *state = NULL; - call_frame_t *frame = NULL; - gfs3_finodelk_req args = {0,}; - char volume[4096] = {0,}; - - if (!req) - return 0; - - args.volume = volume; - if (!xdr_to_finodelk_req (req->msg[0], &args)) { - //failed to decode msg; - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - frame = get_frame_from_request (req); - if (!frame) { - // something wrong, mostly insufficient memory - req->rpc_err = GARBAGE_ARGS; /* TODO */ - goto out; - } - frame->root->op = GF_FOP_FINODELK; - - state = CALL_STATE(frame); - if (!state->conn->bound_xl) { - /* auth failure, request on subvolume without setvolume */ - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - state->resolve.type = RESOLVE_EXACT; - state->volume = gf_strdup (args.volume); - state->resolve.fd_no = args.fd; - state->cmd = args.cmd; - - 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_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; - } - - resolve_and_resume (frame, server_finodelk_resume); -out: - return 0; -} - - -int -server_entrylk (rpcsvc_request_t *req) -{ - server_state_t *state = NULL; - call_frame_t *frame = NULL; - gfs3_entrylk_req args = {0,}; - char path[SERVER_PATH_MAX] = {0,}; - char name[4096] = {0,}; - char volume[4096] = {0,}; - - if (!req) - return 0; - - args.path = path; - args.volume = volume; - args.name = name; - - if (!xdr_to_entrylk_req (req->msg[0], &args)) { - //failed to decode msg; - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - frame = get_frame_from_request (req); - if (!frame) { - // something wrong, mostly insufficient memory - req->rpc_err = GARBAGE_ARGS; /* TODO */ - goto out; - } - frame->root->op = GF_FOP_ENTRYLK; - - state = CALL_STATE (frame); - if (!state->conn->bound_xl) { - /* auth failure, request on subvolume without setvolume */ - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - state->resolve.type = RESOLVE_EXACT; - state->resolve.path = gf_strdup (args.path); - memcpy (state->resolve.gfid, args.gfid, 16); - - if (args.namelen) - state->name = gf_strdup (args.name); - state->volume = gf_strdup (args.volume); - - state->cmd = args.cmd; - state->type = args.type; - - resolve_and_resume (frame, server_entrylk_resume); -out: - return 0; -} - -int -server_fentrylk (rpcsvc_request_t *req) -{ - server_state_t *state = NULL; - call_frame_t *frame = NULL; - gfs3_fentrylk_req args = {0,}; - char name[4096] = {0,}; - char volume[4096] = {0,}; - - if (!req) - return 0; - - args.name = name; - args.volume = volume; - if (!xdr_to_fentrylk_req (req->msg[0], &args)) { - //failed to decode msg; - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - frame = get_frame_from_request (req); - if (!frame) { - // something wrong, mostly insufficient memory - req->rpc_err = GARBAGE_ARGS; /* TODO */ - goto out; - } - frame->root->op = GF_FOP_FENTRYLK; - - state = CALL_STATE(frame); - if (!state->conn->bound_xl) { - /* auth failure, request on subvolume without setvolume */ - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - state->resolve.type = RESOLVE_EXACT; - state->resolve.fd_no = args.fd; - state->cmd = args.cmd; - state->type = args.type; - - if (args.namelen) - state->name = gf_strdup (args.name); - state->volume = gf_strdup (args.volume); - - resolve_and_resume (frame, server_fentrylk_resume); -out: - return 0; -} - -int -server_access (rpcsvc_request_t *req) -{ - server_state_t *state = NULL; - call_frame_t *frame = NULL; - gfs3_access_req args = {0,}; - char path[SERVER_PATH_MAX] = {0,}; - - if (!req) - return 0; - - args.path = path; - if (!xdr_to_access_req (req->msg[0], &args)) { - //failed to decode msg; - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - frame = get_frame_from_request (req); - if (!frame) { - // something wrong, mostly insufficient memory - req->rpc_err = GARBAGE_ARGS; /* TODO */ - goto out; - } - frame->root->op = GF_FOP_ACCESS; - - state = CALL_STATE (frame); - if (!state->conn->bound_xl) { - /* auth failure, request on subvolume without setvolume */ - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - state->resolve.type = RESOLVE_MUST; - memcpy (state->resolve.gfid, args.gfid, 16); - state->resolve.path = gf_strdup (args.path); - state->mask = args.mask; - - resolve_and_resume (frame, server_access_resume); -out: - return 0; -} - - - -int -server_symlink (rpcsvc_request_t *req) -{ - server_state_t *state = NULL; - call_frame_t *frame = NULL; - dict_t *params = NULL; - char *buf = NULL; - gfs3_symlink_req args = {0,}; - char linkname[4096] = {0,}; - char path[SERVER_PATH_MAX] = {0,}; - char bname[4096] = {0,}; - int ret = 0; - - if (!req) - return 0; - - args.path = path; - args.bname = bname; - args.linkname = linkname; - - if (!xdr_to_symlink_req (req->msg[0], &args)) { - //failed to decode msg; - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - frame = get_frame_from_request (req); - if (!frame) { - // something wrong, mostly insufficient memory - req->rpc_err = GARBAGE_ARGS; /* TODO */ - goto out; - } - frame->root->op = GF_FOP_SYMLINK; - - state = CALL_STATE (frame); - if (!state->conn->bound_xl) { - /* auth failure, request on subvolume without setvolume */ - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - if (args.dict.dict_len) { - /* Unserialize the dictionary */ - params = dict_new (); - - buf = memdup (args.dict.dict_val, args.dict.dict_len); - if (buf == NULL) { - gf_log (state->conn->bound_xl->name, GF_LOG_ERROR, - "out of memory"); - goto out; - } - - ret = dict_unserialize (buf, args.dict.dict_len, - ¶ms); - if (ret < 0) { - gf_log (state->conn->bound_xl->name, GF_LOG_ERROR, - "%"PRId64": %s (%"PRId64"): failed to " - "unserialize req-buffer to dictionary", - frame->root->unique, state->resolve.path, - state->resolve.ino); - goto out; - } - - state->params = params; - - params->extra_free = buf; - - buf = NULL; - } - - state->resolve.type = RESOLVE_NOT; - memcpy (state->resolve.pargfid, args.pargfid, 16); - state->resolve.path = gf_strdup (args.path); - state->resolve.bname = gf_strdup (args.bname); - state->name = gf_strdup (args.linkname); - - resolve_and_resume (frame, server_symlink_resume); - - /* memory allocated by libc, don't use GF_FREE */ - if (args.dict.dict_val != NULL) { - free (args.dict.dict_val); - } - return 0; -out: - if (params) - dict_unref (params); - - if (buf) { - GF_FREE (buf); - } - - /* memory allocated by libc, don't use GF_FREE */ - if (args.dict.dict_val != NULL) { - free (args.dict.dict_val); - } - - return 0; -} - - - -int -server_link (rpcsvc_request_t *req) -{ - server_state_t *state = NULL; - call_frame_t *frame = NULL; - gfs3_link_req args = {0,}; - char oldpath[SERVER_PATH_MAX] = {0,}; - char newpath[SERVER_PATH_MAX] = {0,}; - char newbname[SERVER_PATH_MAX] = {0,}; - - if (!req) - return 0; - - args.oldpath = oldpath; - args.newpath = newpath; - args.newbname = newbname; - - if (!xdr_to_link_req (req->msg[0], &args)) { - //failed to decode msg; - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - frame = get_frame_from_request (req); - if (!frame) { - // something wrong, mostly insufficient memory - req->rpc_err = GARBAGE_ARGS; /* TODO */ - goto out; - } - frame->root->op = GF_FOP_LINK; - - state = CALL_STATE (frame); - if (!state->conn->bound_xl) { - /* auth failure, request on subvolume without setvolume */ - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - state->resolve.type = RESOLVE_MUST; - state->resolve.path = gf_strdup (args.oldpath); - memcpy (state->resolve.gfid, args.oldgfid, 16); - - state->resolve2.type = RESOLVE_NOT; - state->resolve2.path = gf_strdup (args.newpath); - state->resolve2.bname = gf_strdup (args.newbname); - memcpy (state->resolve2.pargfid, args.newgfid, 16); - - resolve_and_resume (frame, server_link_resume); -out: - return 0; -} - - -int -server_rename (rpcsvc_request_t *req) -{ - server_state_t *state = NULL; - call_frame_t *frame = NULL; - gfs3_rename_req args = {0,}; - char oldpath[SERVER_PATH_MAX] = {0,}; - char oldbname[SERVER_PATH_MAX] = {0,}; - char newpath[SERVER_PATH_MAX] = {0,}; - char newbname[SERVER_PATH_MAX] = {0,}; - - if (!req) - return 0; - - args.oldpath = oldpath; - args.oldbname = oldbname; - args.newpath = newpath; - args.newbname = newbname; - if (!xdr_to_rename_req (req->msg[0], &args)) { - //failed to decode msg; - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - frame = get_frame_from_request (req); - if (!frame) { - // something wrong, mostly insufficient memory - req->rpc_err = GARBAGE_ARGS; /* TODO */ - goto out; - } - frame->root->op = GF_FOP_RENAME; - - state = CALL_STATE (frame); - if (!state->conn->bound_xl) { - /* auth failure, request on subvolume without setvolume */ - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - state->resolve.type = RESOLVE_MUST; - state->resolve.path = gf_strdup (args.oldpath); - state->resolve.bname = gf_strdup (args.oldbname); - memcpy (state->resolve.pargfid, args.oldgfid, 16); - - state->resolve2.type = RESOLVE_MAY; - state->resolve2.path = gf_strdup (args.newpath); - state->resolve2.bname = gf_strdup (args.newbname); - memcpy (state->resolve2.pargfid, args.newgfid, 16); - - resolve_and_resume (frame, server_rename_resume); -out: - return 0; -} - -int -server_lk (rpcsvc_request_t *req) -{ - server_state_t *state = NULL; - server_connection_t *conn = NULL; - call_frame_t *frame = NULL; - gfs3_lk_req args = {0,}; - - if (!req) - return 0; - - conn = req->trans->xl_private; - - if (!xdr_to_lk_req (req->msg[0], &args)) { - //failed to decode msg; - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - frame = get_frame_from_request (req); - if (!frame) { - // something wrong, mostly insufficient memory - req->rpc_err = GARBAGE_ARGS; /* TODO */ - goto out; - } - frame->root->op = GF_FOP_LK; - - state = CALL_STATE (frame); - if (!state->conn->bound_xl) { - /* auth failure, request on subvolume without setvolume */ - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - state->resolve.fd_no = args.fd; - state->cmd = args.cmd; - state->type = args.type; - - 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; - } - - gf_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_log (conn->bound_xl->name, GF_LOG_ERROR, - "fd - %"PRId64" (%"PRId64"): Unknown lock type: %"PRId32"!", - state->resolve.fd_no, state->fd->inode->ino, state->type); - break; - } - - - resolve_and_resume (frame, server_lk_resume); -out: - return 0; -} - - -int -server_rchecksum (rpcsvc_request_t *req) -{ - server_state_t *state = NULL; - call_frame_t *frame = NULL; - gfs3_rchecksum_req args = {0,}; - - if (!req) - return 0; - - if (!xdr_to_rchecksum_req (req->msg[0], &args)) { - //failed to decode msg; - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - frame = get_frame_from_request (req); - if (!frame) { - // something wrong, mostly insufficient memory - req->rpc_err = GARBAGE_ARGS; /* TODO */ - goto out; - } - frame->root->op = GF_FOP_RCHECKSUM; - - state = CALL_STATE(frame); - if (!state->conn->bound_xl) { - /* auth failure, request on subvolume without setvolume */ - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - state->resolve.type = RESOLVE_MAY; - state->resolve.fd_no = args.fd; - state->offset = args.offset; - state->size = args.len; - - resolve_and_resume (frame, server_rchecksum_resume); -out: - return 0; -} - -int -server_null (rpcsvc_request_t *req) -{ - gf_common_rsp rsp = {0,}; - - rsp.gfs_id = req->gfs_id; - /* Accepted */ - rsp.op_ret = 0; - - server_submit_reply (NULL, req, &rsp, NULL, 0, NULL, - (gfs_serialize_t)xdr_serialize_common_rsp); - - return 0; -} - -int -server_lookup (rpcsvc_request_t *req) -{ - call_frame_t *frame = NULL; - server_connection_t *conn = NULL; - server_state_t *state = NULL; - dict_t *xattr_req = NULL; - char *buf = NULL; - gfs3_lookup_req args = {0,}; - int ret = 0; - char path[SERVER_PATH_MAX] = {0,}; - char bname[SERVER_PATH_MAX] = {0,}; - char dict_val[(16 * 1024)] = {0,}; - - if (!req) - return 0; - - conn = req->trans->xl_private; - - args.path = path; - args.bname = bname; - args.dict.dict_val = dict_val; - - if (!xdr_to_lookup_req (req->msg[0], &args)) { - //failed to decode msg; - req->rpc_err = GARBAGE_ARGS; - goto err; - } - - frame = get_frame_from_request (req); - if (!frame) { - // something wrong, mostly insufficient memory - req->rpc_err = GARBAGE_ARGS; - goto err; - } - frame->root->op = GF_FOP_LOOKUP; - - /* NOTE: lookup() uses req->ino only to identify if a lookup() - * is requested for 'root' or not - */ - - state = CALL_STATE (frame); - if (!state->conn->bound_xl) { - /* auth failure, request on subvolume without setvolume */ - req->rpc_err = GARBAGE_ARGS; - goto out; - } - memcpy (state->resolve.gfid, args.gfid, 16); - - state->resolve.type = RESOLVE_DONTCARE; - memcpy (state->resolve.pargfid, args.pargfid, 16); - state->resolve.path = gf_strdup (args.path); - - if (IS_NOT_ROOT (STRLEN_0 (args.path))) { - state->resolve.bname = gf_strdup (args.bname); - } - - if (args.dict.dict_len) { - /* Unserialize the dictionary */ - xattr_req = dict_new (); - - buf = memdup (args.dict.dict_val, args.dict.dict_len); - if (buf == NULL) { - gf_log (conn->bound_xl->name, GF_LOG_ERROR, - "out of memory"); - goto out; - } - - ret = dict_unserialize (buf, args.dict.dict_len, - &xattr_req); - if (ret < 0) { - gf_log (conn->bound_xl->name, GF_LOG_ERROR, - "%"PRId64": %s (%"PRId64"): failed to " - "unserialize req-buffer to dictionary", - frame->root->unique, state->resolve.path, - state->resolve.ino); - goto out; - } - - state->dict = xattr_req; - - xattr_req->extra_free = buf; - - buf = NULL; - } - - resolve_and_resume (frame, server_lookup_resume); - - return 0; -out: - if (xattr_req) - dict_unref (xattr_req); - - if (buf) { - GF_FREE (buf); - } - - server_lookup_cbk (frame, NULL, frame->this, -1, EINVAL, NULL, NULL, - NULL, NULL); -err: - return 0; -} - -int -server_statfs (rpcsvc_request_t *req) -{ - server_state_t *state = NULL; - call_frame_t *frame = NULL; - gfs3_statfs_req args = {0,}; - char path[SERVER_PATH_MAX] = {0,}; - - if (!req) - return 0; - - args.path = path; - if (!xdr_to_statfs_req (req->msg[0], &args)) { - //failed to decode msg; - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - frame = get_frame_from_request (req); - if (!frame) { - // something wrong, mostly insufficient memory - req->rpc_err = GARBAGE_ARGS; /* TODO */ - goto out; - } - frame->root->op = GF_FOP_STATFS; - - state = CALL_STATE (frame); - if (!state->conn->bound_xl) { - /* auth failure, request on subvolume without setvolume */ - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - state->resolve.type = RESOLVE_MUST; - memcpy (state->resolve.gfid, args.gfid, 16); - state->resolve.path = gf_strdup (args.path); - - resolve_and_resume (frame, server_statfs_resume); -out: - return 0; -} - - -rpcsvc_actor_t glusterfs3_1_fop_actors[] = { - [GFS3_OP_NULL] = { "NULL", GFS3_OP_NULL, server_null, NULL, NULL}, - [GFS3_OP_STAT] = { "STAT", GFS3_OP_STAT, server_stat, NULL, NULL }, - [GFS3_OP_READLINK] = { "READLINK", GFS3_OP_READLINK, server_readlink, NULL, NULL }, - [GFS3_OP_MKNOD] = { "MKNOD", GFS3_OP_MKNOD, server_mknod, NULL, NULL }, - [GFS3_OP_MKDIR] = { "MKDIR", GFS3_OP_MKDIR, server_mkdir, NULL, NULL }, - [GFS3_OP_UNLINK] = { "UNLINK", GFS3_OP_UNLINK, server_unlink, NULL, NULL }, - [GFS3_OP_RMDIR] = { "RMDIR", GFS3_OP_RMDIR, server_rmdir, NULL, NULL }, - [GFS3_OP_SYMLINK] = { "SYMLINK", GFS3_OP_SYMLINK, server_symlink, NULL, NULL }, - [GFS3_OP_RENAME] = { "RENAME", GFS3_OP_RENAME, server_rename, NULL, NULL }, - [GFS3_OP_LINK] = { "LINK", GFS3_OP_LINK, server_link, NULL, NULL }, - [GFS3_OP_TRUNCATE] = { "TRUNCATE", GFS3_OP_TRUNCATE, server_truncate, NULL, NULL }, - [GFS3_OP_OPEN] = { "OPEN", GFS3_OP_OPEN, server_open, NULL, NULL }, - [GFS3_OP_READ] = { "READ", GFS3_OP_READ, server_readv, NULL, NULL }, - [GFS3_OP_WRITE] = { "WRITE", GFS3_OP_WRITE, server_writev, server_writev_vec, NULL }, - [GFS3_OP_STATFS] = { "STATFS", GFS3_OP_STATFS, server_statfs, NULL, NULL }, - [GFS3_OP_FLUSH] = { "FLUSH", GFS3_OP_FLUSH, server_flush, NULL, NULL }, - [GFS3_OP_FSYNC] = { "FSYNC", GFS3_OP_FSYNC, server_fsync, NULL, NULL }, - [GFS3_OP_SETXATTR] = { "SETXATTR", GFS3_OP_SETXATTR, server_setxattr, NULL, NULL }, - [GFS3_OP_GETXATTR] = { "GETXATTR", GFS3_OP_GETXATTR, server_getxattr, NULL, NULL }, - [GFS3_OP_REMOVEXATTR] = { "REMOVEXATTR", GFS3_OP_REMOVEXATTR, server_removexattr, NULL, NULL }, - [GFS3_OP_OPENDIR] = { "OPENDIR", GFS3_OP_OPENDIR, server_opendir, NULL, NULL }, - [GFS3_OP_FSYNCDIR] = { "FSYNCDIR", GFS3_OP_FSYNCDIR, server_fsyncdir, NULL, NULL }, - [GFS3_OP_ACCESS] = { "ACCESS", GFS3_OP_ACCESS, server_access, NULL, NULL }, - [GFS3_OP_CREATE] = { "CREATE", GFS3_OP_CREATE, server_create, NULL, NULL }, - [GFS3_OP_FTRUNCATE] = { "FTRUNCATE", GFS3_OP_FTRUNCATE, server_ftruncate, NULL, NULL }, - [GFS3_OP_FSTAT] = { "FSTAT", GFS3_OP_FSTAT, server_fstat, NULL, NULL }, - [GFS3_OP_LK] = { "LK", GFS3_OP_LK, server_lk, NULL, NULL }, - [GFS3_OP_LOOKUP] = { "LOOKUP", GFS3_OP_LOOKUP, server_lookup, NULL, NULL }, - [GFS3_OP_READDIR] = { "READDIR", GFS3_OP_READDIR, server_readdir, NULL, NULL }, - [GFS3_OP_INODELK] = { "INODELK", GFS3_OP_INODELK, server_inodelk, NULL, NULL }, - [GFS3_OP_FINODELK] = { "FINODELK", GFS3_OP_FINODELK, server_finodelk, NULL, NULL }, - [GFS3_OP_ENTRYLK] = { "ENTRYLK", GFS3_OP_ENTRYLK, server_entrylk, NULL, NULL }, - [GFS3_OP_FENTRYLK] = { "FENTRYLK", GFS3_OP_FENTRYLK, server_fentrylk, NULL, NULL }, - [GFS3_OP_XATTROP] = { "XATTROP", GFS3_OP_XATTROP, server_xattrop, NULL, NULL }, - [GFS3_OP_FXATTROP] = { "FXATTROP", GFS3_OP_FXATTROP, server_fxattrop, NULL, NULL }, - [GFS3_OP_FGETXATTR] = { "FGETXATTR", GFS3_OP_FGETXATTR, server_fgetxattr, NULL, NULL }, - [GFS3_OP_FSETXATTR] = { "FSETXATTR", GFS3_OP_FSETXATTR, server_fsetxattr, NULL, NULL }, - [GFS3_OP_RCHECKSUM] = { "RCHECKSUM", GFS3_OP_RCHECKSUM, server_rchecksum, NULL, NULL }, - [GFS3_OP_SETATTR] = { "SETATTR", GFS3_OP_SETATTR, server_setattr, NULL, NULL }, - [GFS3_OP_FSETATTR] = { "FSETATTR", GFS3_OP_FSETATTR, server_fsetattr, NULL, NULL }, - [GFS3_OP_READDIRP] = { "READDIRP", GFS3_OP_READDIRP, server_readdirp, NULL, NULL }, - [GFS3_OP_RELEASE] = { "RELEASE", GFS3_OP_RELEASE, server_release, NULL, NULL }, - [GFS3_OP_RELEASEDIR] = { "RELEASEDIR", GFS3_OP_RELEASEDIR, server_releasedir, NULL, NULL }, -}; - - -struct rpcsvc_program glusterfs3_1_fop_prog = { - .progname = "GlusterFS-3.1.0", - .prognum = GLUSTER3_1_FOP_PROGRAM, - .progver = GLUSTER3_1_FOP_VERSION, - .numactors = GLUSTER3_1_FOP_PROCCNT, - .actors = glusterfs3_1_fop_actors, -}; |
