From 2f499e85a4ae0ac1e84785daa60a5bbfe979cc7f Mon Sep 17 00:00:00 2001 From: Kotresh H R Date: Wed, 8 Jan 2014 10:52:28 +0530 Subject: glusterd/geo-rep : Allow volume to stop if geo-rep is not active. In staging phase of volume stop, code is added to read the state_file for each slave of the master to which the volume belongs. If any of the geo-rep session is active with at least one slave, volume is not allowed to stop else it is allowed. Change-Id: I4a01a357fc86b872e9635b3d19998cdbd9545114 BUG: 1049727 Signed-off-by: Kotresh H R Reviewed-on: http://review.gluster.org/6663 Tested-by: Gluster Build System Reviewed-by: Vijay Bellur --- xlators/mgmt/glusterd/src/glusterd-geo-rep.c | 152 ++++++++++++++++++++++++ xlators/mgmt/glusterd/src/glusterd-op-sm.h | 5 + xlators/mgmt/glusterd/src/glusterd-volume-ops.c | 20 +++- 3 files changed, 176 insertions(+), 1 deletion(-) diff --git a/xlators/mgmt/glusterd/src/glusterd-geo-rep.c b/xlators/mgmt/glusterd/src/glusterd-geo-rep.c index c5c76e11a..849480a28 100644 --- a/xlators/mgmt/glusterd/src/glusterd-geo-rep.c +++ b/xlators/mgmt/glusterd/src/glusterd-geo-rep.c @@ -1295,6 +1295,158 @@ glusterd_check_gsync_running (glusterd_volinfo_t *volinfo, gf_boolean_t *flag) return 0; } +/* + * is_geo_rep_active: + * This function reads the state_file and sets is_active to 1 if the + * monitor status is neither "Stopped" or "Not Started" + * + * RETURN VALUE: + * 0: On successful read of state_file. + * -1: error. + */ + +static int +is_geo_rep_active (glusterd_volinfo_t *volinfo, char *slave, + char *conf_path, int *is_active) +{ + dict_t *confd = NULL; + char *statefile = NULL; + char *master = NULL; + char monitor_status[PATH_MAX] = ""; + int ret = -1; + xlator_t *this = NULL; + + this = THIS; + GF_ASSERT (this); + + master = volinfo->volname; + + confd = dict_new (); + if (!confd) { + gf_log ("", GF_LOG_ERROR, "Not able to create dict."); + goto out; + } + + ret = glusterd_gsync_get_config (master, slave, conf_path, + confd); + if (ret) { + gf_log ("", GF_LOG_ERROR, "Unable to get configuration data " + "for %s(master), %s(slave)", master, slave); + ret = -1; + goto out; + } + + ret = dict_get_param (confd, "state_file", &statefile); + if (ret) { + gf_log ("", GF_LOG_ERROR, "Unable to get state_file's name " + "for %s(master), %s(slave). Please check gsync " + "config file.", master, slave); + ret = -1; + goto out; + } + + ret = glusterd_gsync_read_frm_status (statefile, monitor_status, + sizeof (monitor_status)); + if (ret <= 0) { + gf_log ("", GF_LOG_ERROR, "Unable to read the status " + "file for %s(master), %s(slave)", master, slave); + strncpy (monitor_status, "defunct", sizeof (monitor_status)); + } + + if ((!strcmp(monitor_status, "Stopped")) || + (!strcmp(monitor_status, "Not Started"))) { + *is_active = 0; + } else { + *is_active = 1; + } + ret = 0; +out: + if (confd) + dict_destroy (confd); + return ret; +} + +/* + * _get_slave_status: + * Called for each slave in the volume from dict_foreach. + * It calls is_geo_rep_active to get the monitor status. + * + * RETURN VALUE: + * 0: On successful read of state_file from is_geo_rep_active. + * When it is found geo-rep is already active from previous calls. + * When there is no slave. + * -1: On error. + */ + +int +_get_slave_status (dict_t *dict, char *key, data_t *value, void *data) +{ + gsync_status_param_t *param = NULL; + char *slave = NULL; + char *slave_ip = NULL; + char *slave_vol = NULL; + char *errmsg = NULL; + char conf_path[PATH_MAX] = ""; + int ret = -1; + glusterd_conf_t *priv = NULL; + xlator_t *this = NULL; + + param = (gsync_status_param_t *)data; + + GF_ASSERT (param); + GF_ASSERT (param->volinfo); + + if (param->is_active) { + ret = 0; + goto out; + } + + this = THIS; + GF_ASSERT (this); + + if (this) + priv = this->private; + if (priv == NULL) { + gf_log ("", GF_LOG_ERROR, "priv of glusterd not present"); + goto out; + } + + slave = strchr(value->data, ':'); + if (!slave) { + ret = 0; + goto out; + } + slave++; + + ret = glusterd_get_slave_info (slave, &slave_ip, &slave_vol, &errmsg); + if (ret) { + if (errmsg) + gf_log ("", GF_LOG_ERROR, "Unable to fetch " + "slave details. Error: %s", errmsg); + else + gf_log ("", GF_LOG_ERROR, + "Unable to fetch slave details."); + ret = -1; + goto out; + } + + ret = snprintf (conf_path, sizeof(conf_path) - 1, + "%s/"GEOREP"/%s_%s_%s/gsyncd.conf", + priv->workdir, param->volinfo->volname, + slave_ip, slave_vol); + if (ret < 0) { + gf_log ("", GF_LOG_ERROR, "Unable to assign conf_path."); + ret = -1; + goto out; + } + conf_path[ret] = '\0'; + + ret = is_geo_rep_active (param->volinfo,slave, conf_path, + ¶m->is_active); +out: + return ret; +} + static int glusterd_op_verify_gsync_running (glusterd_volinfo_t *volinfo, char *slave, char *conf_path, diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.h b/xlators/mgmt/glusterd/src/glusterd-op-sm.h index 62f991933..1125368ce 100644 --- a/xlators/mgmt/glusterd/src/glusterd-op-sm.h +++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.h @@ -165,6 +165,11 @@ typedef struct glusterd_gsync_status_temp { char *node; }glusterd_gsync_status_temp_t; +typedef struct gsync_status_param { + int is_active; + glusterd_volinfo_t *volinfo; +}gsync_status_param_t; + typedef enum cli_cmd_type_ { PER_REPLICA, ALL_REPLICA, diff --git a/xlators/mgmt/glusterd/src/glusterd-volume-ops.c b/xlators/mgmt/glusterd/src/glusterd-volume-ops.c index df2562ba6..db9f39c7c 100644 --- a/xlators/mgmt/glusterd/src/glusterd-volume-ops.c +++ b/xlators/mgmt/glusterd/src/glusterd-volume-ops.c @@ -30,6 +30,8 @@ #define glusterd_op_start_volume_args_get(dict, volname, flags) \ glusterd_op_stop_volume_args_get (dict, volname, flags) +extern int +_get_slave_status (dict_t *this, char *key, data_t *value, void *data); int __glusterd_handle_create_volume (rpcsvc_request_t *req) @@ -1059,6 +1061,7 @@ glusterd_op_stage_stop_volume (dict_t *dict, char **op_errstr) glusterd_volinfo_t *volinfo = NULL; char msg[2048] = {0}; xlator_t *this = NULL; + gsync_status_param_t param = {0,}; this = THIS; GF_ASSERT (this); @@ -1102,7 +1105,22 @@ glusterd_op_stage_stop_volume (dict_t *dict, char **op_errstr) if (ret && (is_run == _gf_false)) gf_log (this->name, GF_LOG_WARNING, "Unable to get the status" " of active "GEOREP" session"); - if (is_run) { + + param.volinfo = volinfo; + ret = dict_foreach (volinfo->gsync_slaves, _get_slave_status, ¶m); + + if (ret) { + gf_log (this->name, GF_LOG_WARNING, "_get_slave_satus failed"); + snprintf (msg, sizeof(msg), GEOREP" Unable to get the status " + "of active "GEOREP" session for the volume '%s'.\n" + "Please check the log file for more info. Use " + "'force' option to ignore and stop the volume.", + volname); + ret = -1; + goto out; + } + + if (is_run && param.is_active) { gf_log (this->name, GF_LOG_WARNING, GEOREP" sessions active" "for the volume %s ", volname); snprintf (msg, sizeof(msg), GEOREP" sessions are active " -- cgit From f139fc7e44da27670e90bd7ba55ff80e7c8b8ecd Mon Sep 17 00:00:00 2001 From: Kaushal M Date: Mon, 13 Jan 2014 12:42:31 +0530 Subject: cli: Don't override cli mode when stdin in not a tty Change-Id: I801c6e6ecd6c5a91e487e8e54ec5f684d450a080 BUG: 1047378 Signed-off-by: Kaushal M Reviewed-on: http://review.gluster.org/6687 Tested-by: Gluster Build System Reviewed-by: Vijay Bellur --- cli/src/input.c | 2 +- tests/bugs/bug-1047378.t | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 tests/bugs/bug-1047378.t diff --git a/cli/src/input.c b/cli/src/input.c index a8ea46c6d..26f337c3c 100644 --- a/cli/src/input.c +++ b/cli/src/input.c @@ -87,7 +87,7 @@ cli_input_init (struct cli_state *state) cli_rl_enable (state); } else { state->prompt = ""; - state->mode = GLUSTER_MODE_SCRIPT | GLUSTER_MODE_ERR_FATAL; + state->mode |= GLUSTER_MODE_SCRIPT | GLUSTER_MODE_ERR_FATAL; } if (!state->rl_enabled) diff --git a/tests/bugs/bug-1047378.t b/tests/bugs/bug-1047378.t new file mode 100644 index 000000000..b441ee9b1 --- /dev/null +++ b/tests/bugs/bug-1047378.t @@ -0,0 +1,12 @@ +#!/bin/bash + +. $(dirname $0)/../include.rc + +cleanup; + +TEST glusterd +TEST pidof glusterd + +TEST "echo volume list | $CLI --xml | xmllint --format -" + +cleanup -- cgit From f3e227d525ee04a3ea0196f7a15aa9b1a8f8cae1 Mon Sep 17 00:00:00 2001 From: Lalatendu Mohanty Date: Tue, 14 Jan 2014 23:24:50 +0530 Subject: geo-rep: Fixing null pointer dereference of "op_value" Change-Id: Id39743eaa5a52cc7fd4e2a1378a23384f5ef1fed BUG: 789278 Signed-off-by: Lalatendu Mohanty Reviewed-on: http://review.gluster.org/6700 Reviewed-by: Avra Sengupta Tested-by: Avra Sengupta --- xlators/mgmt/glusterd/src/glusterd-geo-rep.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xlators/mgmt/glusterd/src/glusterd-geo-rep.c b/xlators/mgmt/glusterd/src/glusterd-geo-rep.c index 849480a28..3969db17c 100644 --- a/xlators/mgmt/glusterd/src/glusterd-geo-rep.c +++ b/xlators/mgmt/glusterd/src/glusterd-geo-rep.c @@ -2614,7 +2614,7 @@ glusterd_gsync_configure (glusterd_volinfo_t *volinfo, char *slave, goto out; } - if (!strcmp (op_name, "state_file")) { + if ((!strcmp (op_name, "state_file")) && (op_value)) { ret = lstat (op_value, &stbuf); if (ret) { -- cgit From 260e817b8a652ddb705808098da1e07e3660f4c7 Mon Sep 17 00:00:00 2001 From: Santosh Kumar Pradhan Date: Tue, 14 Jan 2014 11:21:44 +0530 Subject: gNFS: Set default outstanding RPC limit to 16 With 64, NFS server hangs with large I/O load (~ 64 threads writing to NFS server). The test results from Ben England (Performance expert) suggest to set it as 16 instead of 64. Change-Id: I418ff5ba0a3e9fdb14f395b8736438ee1bbd95f4 BUG: 1008301 Signed-off-by: Santosh Kumar Pradhan Reviewed-on: http://review.gluster.org/6696 Tested-by: Gluster Build System Reviewed-by: ben england --- rpc/rpc-lib/src/rpcsvc.c | 46 ++++++++++++++++++++---------------- rpc/rpc-lib/src/rpcsvc.h | 5 ++-- xlators/nfs/server/src/nfs.c | 22 ++++++++++++++++- xlators/protocol/server/src/server.c | 20 ++++++++++++++-- 4 files changed, 67 insertions(+), 26 deletions(-) diff --git a/rpc/rpc-lib/src/rpcsvc.c b/rpc/rpc-lib/src/rpcsvc.c index 69db8b70b..96242dff7 100644 --- a/rpc/rpc-lib/src/rpcsvc.c +++ b/rpc/rpc-lib/src/rpcsvc.c @@ -1883,8 +1883,7 @@ rpcsvc_init_options (rpcsvc_t *svc, dict_t *options) if (!svc->register_portmap) gf_log (GF_RPCSVC, GF_LOG_DEBUG, "Portmap registration " "disabled"); - - ret = rpcsvc_set_outstanding_rpc_limit (svc, options); + ret = 0; out: return ret; } @@ -2016,10 +2015,15 @@ out: } /* - * Reconfigure() the rpc.outstanding-rpc-limit param. + * Configure() the rpc.outstanding-rpc-limit param. + * If dict_get_int32() for dict-key "rpc.outstanding-rpc-limit" FAILS, + * it would set the value as "defvalue". Otherwise it would fetch the + * value and round up to multiple-of-8. defvalue must be +ve. + * + * NB: defval or set-value "0" is special which means unlimited/65536. */ int -rpcsvc_set_outstanding_rpc_limit (rpcsvc_t *svc, dict_t *options) +rpcsvc_set_outstanding_rpc_limit (rpcsvc_t *svc, dict_t *options, int defvalue) { int ret = -1; /* FAILURE */ int rpclim = 0; @@ -2028,30 +2032,30 @@ rpcsvc_set_outstanding_rpc_limit (rpcsvc_t *svc, dict_t *options) if ((!svc) || (!options)) return (-1); - /* Reconfigure() the rpc.outstanding-rpc-limit param */ + if ((defvalue < RPCSVC_MIN_OUTSTANDING_RPC_LIMIT) || + (defvalue > RPCSVC_MAX_OUTSTANDING_RPC_LIMIT)) { + return (-1); + } + + /* Fetch the rpc.outstanding-rpc-limit from dict. */ ret = dict_get_int32 (options, rpclimkey, &rpclim); if (ret < 0) { /* Fall back to default for FAILURE */ - rpclim = RPCSVC_DEFAULT_OUTSTANDING_RPC_LIMIT; - } else { - /* SUCCESS: round off to multiple of 8. - * If the input value fails Boundary check, fall back to - * default i.e. RPCSVC_DEFAULT_OUTSTANDING_RPC_LIMIT. - * NB: value 0 is special, means its unset i.e. unlimited. - */ - rpclim = ((rpclim + 8 - 1) >> 3) * 8; - if (rpclim < RPCSVC_MIN_OUTSTANDING_RPC_LIMIT) { - rpclim = RPCSVC_DEFAULT_OUTSTANDING_RPC_LIMIT; - } else if (rpclim > RPCSVC_MAX_OUTSTANDING_RPC_LIMIT) { - rpclim = RPCSVC_MAX_OUTSTANDING_RPC_LIMIT; - } + rpclim = defvalue; + } + + /* Round up to multiple-of-8. It must not exceed + * RPCSVC_MAX_OUTSTANDING_RPC_LIMIT. + */ + rpclim = ((rpclim + 8 - 1) >> 3) * 8; + if (rpclim > RPCSVC_MAX_OUTSTANDING_RPC_LIMIT) { + rpclim = RPCSVC_MAX_OUTSTANDING_RPC_LIMIT; } if (svc->outstanding_rpc_limit != rpclim) { svc->outstanding_rpc_limit = rpclim; gf_log (GF_RPCSVC, GF_LOG_INFO, - "Configured %s with value %d", - rpclimkey, rpclim); + "Configured %s with value %d", rpclimkey, rpclim); } return (0); @@ -2066,7 +2070,7 @@ rpcsvc_init (xlator_t *xl, glusterfs_ctx_t *ctx, dict_t *options, rpcsvc_t *svc = NULL; int ret = -1; - if ((!ctx) || (!options)) + if ((!xl) || (!ctx) || (!options)) return NULL; svc = GF_CALLOC (1, sizeof (*svc), gf_common_mt_rpcsvc_t); diff --git a/rpc/rpc-lib/src/rpcsvc.h b/rpc/rpc-lib/src/rpcsvc.h index 30a969b11..5a6f930d3 100644 --- a/rpc/rpc-lib/src/rpcsvc.h +++ b/rpc/rpc-lib/src/rpcsvc.h @@ -38,7 +38,8 @@ #define MAX_IOVEC 16 #endif -#define RPCSVC_DEFAULT_OUTSTANDING_RPC_LIMIT 64 +#define RPCSVC_DEFAULT_OUTSTANDING_RPC_LIMIT 64 /* Default for protocol/server */ +#define RPCSVC_DEF_NFS_OUTSTANDING_RPC_LIMIT 16 /* Default for nfs/server */ #define RPCSVC_MAX_OUTSTANDING_RPC_LIMIT 65536 #define RPCSVC_MIN_OUTSTANDING_RPC_LIMIT 0 /* No limit i.e. Unlimited */ @@ -597,7 +598,7 @@ rpcsvc_set_addr_namelookup (rpcsvc_t *svc, dict_t *options); int rpcsvc_set_root_squash (rpcsvc_t *svc, dict_t *options); int -rpcsvc_set_outstanding_rpc_limit (rpcsvc_t *svc, dict_t *options); +rpcsvc_set_outstanding_rpc_limit (rpcsvc_t *svc, dict_t *options, int defvalue); int rpcsvc_auth_array (rpcsvc_t *svc, char *volname, int *autharr, int arrlen); rpcsvc_vector_sizer diff --git a/xlators/nfs/server/src/nfs.c b/xlators/nfs/server/src/nfs.c index 4ab5cbc90..04cf030dc 100644 --- a/xlators/nfs/server/src/nfs.c +++ b/xlators/nfs/server/src/nfs.c @@ -967,6 +967,15 @@ nfs_init_state (xlator_t *this) goto free_foppool; } + ret = rpcsvc_set_outstanding_rpc_limit (nfs->rpcsvc, + this->options, + RPCSVC_DEF_NFS_OUTSTANDING_RPC_LIMIT); + if (ret < 0) { + gf_log (GF_NFS, GF_LOG_ERROR, + "Failed to configure outstanding-rpc-limit"); + goto free_foppool; + } + nfs->register_portmap = rpcsvc_register_portmap_enabled (nfs->rpcsvc); this->private = (void *)nfs; @@ -1210,6 +1219,17 @@ reconfigure (xlator_t *this, dict_t *options) "rpcsvc reconfigure options failed"); return (-1); } + + /* Reconfigure rpc.outstanding-rpc-limit */ + ret = rpcsvc_set_outstanding_rpc_limit (nfs->rpcsvc, + options, + RPCSVC_DEF_NFS_OUTSTANDING_RPC_LIMIT); + if (ret < 0) { + gf_log (GF_NFS, GF_LOG_ERROR, + "Failed to reconfigure outstanding-rpc-limit"); + return (-1); + } + regpmap = rpcsvc_register_portmap_enabled(nfs->rpcsvc); if (nfs->register_portmap != regpmap) { nfs->register_portmap = regpmap; @@ -1741,7 +1761,7 @@ struct volume_options options[] = { .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), + .default_value = TOSTRING(RPCSVC_DEF_NFS_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)" diff --git a/xlators/protocol/server/src/server.c b/xlators/protocol/server/src/server.c index 56b83cb9a..378aa393a 100644 --- a/xlators/protocol/server/src/server.c +++ b/xlators/protocol/server/src/server.c @@ -746,7 +746,15 @@ reconfigure (xlator_t *this, dict_t *options) (void) rpcsvc_set_allow_insecure (rpc_conf, options); (void) rpcsvc_set_root_squash (rpc_conf, options); - (void) rpcsvc_set_outstanding_rpc_limit (rpc_conf, options); + + ret = rpcsvc_set_outstanding_rpc_limit (rpc_conf, options, + RPCSVC_DEFAULT_OUTSTANDING_RPC_LIMIT); + if (ret < 0) { + gf_log (this->name, GF_LOG_ERROR, + "Failed to reconfigure outstanding-rpc-limit"); + goto out; + } + list_for_each_entry (listeners, &(rpc_conf->listeners), list) { if (listeners->trans != NULL) { if (listeners->trans->reconfigure ) @@ -860,12 +868,20 @@ init (xlator_t *this) /* RPC related */ conf->rpc = rpcsvc_init (this, this->ctx, this->options, 0); if (conf->rpc == NULL) { - gf_log (this->name, GF_LOG_WARNING, + gf_log (this->name, GF_LOG_ERROR, "creation of rpcsvc failed"); ret = -1; goto out; } + ret = rpcsvc_set_outstanding_rpc_limit (conf->rpc, this->options, + RPCSVC_DEFAULT_OUTSTANDING_RPC_LIMIT); + if (ret < 0) { + gf_log (this->name, GF_LOG_ERROR, + "Failed to configure outstanding-rpc-limit"); + goto out; + } + ret = rpcsvc_create_listeners (conf->rpc, this->options, this->name); if (ret < 1) { -- cgit From dd1f4a480511c4785d004c06dd9c41ba54f05143 Mon Sep 17 00:00:00 2001 From: Vijaykumar M Date: Mon, 30 Dec 2013 18:06:56 +0530 Subject: dht: Ignore directory with missing xattrs, which have err == 0, and start == stop From the history (Patch: http://review.gluster.org/4668/) When subvols-per-directory is < available subvols, then there are layouts which are not populated. This leads to incorrect identification of holes or overlaps. We need to ignore layouts, which have err == 0, and start == stop. In the current scenario (start == stop == 0). Additionally, in layout-merge, treat missing xattrs as err = 0. In case of missing layouts, anomalies will reset them. For any other valid subvoles, err != 0 in case of layouts being zeroed out. Also reverted back dht_selfheal_dir_xattr, which does layout calculation only on subvols which have errors. Change-Id: Idb72a869f1a6f103046bb7e6fe0019f6ac853fd4 BUG: 1047331 Signed-off-by: Vijaykumar M Reviewed-on: http://review.gluster.org/6618 Reviewed-by: Krishnan Parthasarathi Tested-by: Gluster Build System Reviewed-by: Shyamsundar Ranganathan Reviewed-by: Anand Avati --- xlators/cluster/dht/src/dht-layout.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xlators/cluster/dht/src/dht-layout.c b/xlators/cluster/dht/src/dht-layout.c index 2bd9e5ff6..f7413c8a0 100644 --- a/xlators/cluster/dht/src/dht-layout.c +++ b/xlators/cluster/dht/src/dht-layout.c @@ -722,7 +722,7 @@ dht_layout_dir_mismatch (xlator_t *this, dht_layout_t *layout, xlator_t *subvol, &disk_layout_raw); if (dict_ret < 0) { - if (err == 0) { + if (err == 0 && layout->list[pos].stop) { gf_log (this->name, GF_LOG_INFO, "%s - disk layout missing", loc->path); ret = -1; -- cgit From de557c602c8f0480686c4d560f012924ee0de936 Mon Sep 17 00:00:00 2001 From: ndarshan Date: Fri, 27 Dec 2013 03:11:19 -0500 Subject: cli: Addition of new child elements under brick in volume info xml. Added new child elements; name and hostUuid under brick in volume info xml where name and host uuid of the bricks are stored. This does not break backward compatibility as the old value under brick is not removed. Change-Id: Ib9e388889c8dc0c7cd34dcc1871a59003f982f36 Signed-off-by: ndarshan Reviewed-on: http://review.gluster.org/6604 Reviewed-by: Kaushal M Tested-by: Gluster Build System --- cli/src/cli-xml-output.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cli/src/cli-xml-output.c b/cli/src/cli-xml-output.c index 69fed1bc9..886c372dc 100644 --- a/cli/src/cli-xml-output.c +++ b/cli/src/cli-xml-output.c @@ -2715,6 +2715,16 @@ cli_xml_output_vol_info (cli_local_t *local, dict_t *dict) (local->writer, "%s", brick); XML_RET_CHECK_AND_GOTO (ret, out); + ret = xmlTextWriterWriteFormatElement + (local->writer, (xmlChar *)"name", "%s", + brick); + XML_RET_CHECK_AND_GOTO (ret, out); + + ret = xmlTextWriterWriteFormatElement + (local->writer, (xmlChar *)"hostUuid", "%s", + uuid); + XML_RET_CHECK_AND_GOTO (ret, out); + /* */ ret = xmlTextWriterEndElement (local->writer); XML_RET_CHECK_AND_GOTO (ret, out); -- cgit From c9008fe6a1a4d9c25c4b11804bcc9e5b6edf9bec Mon Sep 17 00:00:00 2001 From: Lalatendu Mohanty Date: Tue, 14 Jan 2014 12:35:54 +0530 Subject: libgfapi: Fixing possible dereferencing of null pointer "glfd" Fix: Putting a check so that pointer derefrence does not happen when "gfld" is null Change-Id: I281b10be445bbeec3a2728fc139d5ac94372e5b6 BUG: 789278 Signed-off-by: Lalatendu Mohanty Reviewed-on: http://review.gluster.org/6697 Tested-by: Gluster Build System Reviewed-by: Shyamsundar Ranganathan Reviewed-by: Vijay Bellur --- api/src/glfs-fops.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/glfs-fops.c b/api/src/glfs-fops.c index b09dd90f7..5ea54567d 100644 --- a/api/src/glfs-fops.c +++ b/api/src/glfs-fops.c @@ -1790,7 +1790,7 @@ out: if (ret && glfd) { glfs_fd_destroy (glfd); glfd = NULL; - } else { + } else if (glfd) { fd_bind (glfd->fd); glfs_fd_bind (glfd); } -- cgit From 902276ebd7d6d7b3158d7c4796cdd392b6e958c3 Mon Sep 17 00:00:00 2001 From: Raghavendra Talur Date: Thu, 9 Jan 2014 17:03:37 +0530 Subject: test: Remove unnecessary code from test. We have not meddled with mount point to check for it again. Change-Id: I88eed777b6573a320065b9e14c2031db964e36d0 BUG: 1053362 Signed-off-by: Raghavendra Talur Reviewed-on: http://review.gluster.org/6675 Tested-by: Gluster Build System Reviewed-by: Vijay Bellur --- tests/bugs/bug-858488-min-free-disk.t | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tests/bugs/bug-858488-min-free-disk.t b/tests/bugs/bug-858488-min-free-disk.t index ae5ac3bde..dfed0fd33 100644 --- a/tests/bugs/bug-858488-min-free-disk.t +++ b/tests/bugs/bug-858488-min-free-disk.t @@ -5,11 +5,6 @@ cleanup; -function pidgrep() -{ - ps ax | grep "$1" | grep -v grep | awk '{print $1}' | head -1 -} - ## Start glusterd TEST glusterd; TEST pidof glusterd; @@ -38,7 +33,6 @@ EXPECT 'Created' volinfo_field $V0 'Status'; TEST $CLI volume start $V0; EXPECT 'Started' volinfo_field $V0 'Status'; TEST glusterfs -s $H0 --volfile-id=$V0 --acl $M0 -MOUNT_PID=`ps ax |grep "glusterfs -s $H0 --volfile-id=$V0 --acl $M0" | awk '{print $1}' | head -1` ## Real test starts here ## ---------------------------------------------------------------------------- @@ -103,7 +97,6 @@ dd if=/dev/zero of=$M0/$FILETOCREATE bs=1024 count=2048 1>/dev/null 2>&1 TEST [ -e $OTHERBRICK/$FILETOCREATE ] ## Done testing, lets clean up -EXPECT "$MOUNT_PID" pidgrep $MOUNT_PID TEST rm -rf $M0/* ## Finish up -- cgit From 39968c09626074b34b62541af5940f44ba70cc06 Mon Sep 17 00:00:00 2001 From: Varun Shastry Date: Tue, 22 Oct 2013 16:12:58 +0530 Subject: features/quota: Metadata cleanup Quota and marker uses 'trusted.glusterfs.quota*' and 'trusted.pgfid*' xattrs to store its configurations and accounting information and also to build the parent inode chain in case of absense of path. Problem: After disabling and then enabling quota back, the xattrs may contain stale data leading to impaired accounting and thus improper enforcement. Solution: Clean up all the quota related xattrs after quota disable. Marker xlator implements a virtual xattr to cleanup quota and pgfid xattrs. In this approach glusterd mounts an auxiliary mount and sends the below command to all the files by crawling the mountpoint. #setfattr -n "glusterfs.quota-xattr-cleanup" -v 1 Credit: Krishnan Parthasarathi Varun Shastry Change-Id: I9380eca58a285dc27dd572de1767aac8f2cd8049 BUG: 969461 Signed-off-by: Varun Shastry Reviewed-on: http://review.gluster.org/6369 Reviewed-by: Raghavendra G Tested-by: Gluster Build System Reviewed-by: Krishnan Parthasarathi Reviewed-by: Vijay Bellur --- extras/Makefile.am | 10 +- extras/quota-metadata-cleanup.sh | 24 ----- extras/quota-remove-xattr.sh | 24 ----- libglusterfs/src/glusterfs.h | 1 + xlators/features/marker/src/marker.c | 143 ++++++++++++++++++++++++++++- xlators/mgmt/glusterd/src/glusterd-quota.c | 30 +++++- 6 files changed, 169 insertions(+), 63 deletions(-) delete mode 100755 extras/quota-metadata-cleanup.sh delete mode 100755 extras/quota-remove-xattr.sh diff --git a/extras/Makefile.am b/extras/Makefile.am index cf619329b..2633e20a5 100644 --- a/extras/Makefile.am +++ b/extras/Makefile.am @@ -1,4 +1,3 @@ - EditorModedir = $(docdir) EditorMode_DATA = glusterfs-mode.el glusterfs.vim @@ -13,8 +12,7 @@ vol_DATA = glusterd.vol EXTRA_DIST = specgen.scm MacOSX/Portfile glusterfs-mode.el glusterfs.vim \ migrate-unify-to-distribute.sh backend-xattr-sanitize.sh \ - backend-cleanup.sh disk_usage_sync.sh quota-remove-xattr.sh \ - quota-metadata-cleanup.sh glusterfs-logrotate clear_xattrs.sh \ - group-virt.example glusterd-sysconfig gluster-rsyslog-7.2.conf \ - gluster-rsyslog-5.8.conf logger.conf.example glusterd.vol \ - glusterfs-georep-logrotate + backend-cleanup.sh disk_usage_sync.sh glusterfs-logrotate \ + clear_xattrs.sh group-virt.example glusterd-sysconfig \ + gluster-rsyslog-7.2.conf gluster-rsyslog-5.8.conf \ + logger.conf.example glusterd.vol glusterfs-georep-logrotate diff --git a/extras/quota-metadata-cleanup.sh b/extras/quota-metadata-cleanup.sh deleted file mode 100755 index 37ad8bc31..000000000 --- a/extras/quota-metadata-cleanup.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/bash - -# This script is used to cleanup xattrs setup by quota-translator in (a) -# backend directory(ies). It takes a single or list of backend directories -# as argument(s). - -usage () -{ - echo >&2 "usage: $0 " -} - -main () -{ - [ $# -lt 1 ] && usage - - INSTALL_DIR=`dirname $0` - - for i in $@; do - find $i -exec $INSTALL_DIR/quota-remove-xattr.sh '{}' \; - done - -} - -main $@ diff --git a/extras/quota-remove-xattr.sh b/extras/quota-remove-xattr.sh deleted file mode 100755 index 7191f9bd4..000000000 --- a/extras/quota-remove-xattr.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/bash - -# This script is used to remove xattrs set by quota translator on a path. -# It is generally invoked from quota-metadata-cleanup.sh, but can -# also be used stand-alone. - -usage () -{ - echo >&2 "usage: $0 " -} - -main () -{ - [ $# -ne 1 ] && usage $0 - - XATTR_KEY_VALUE_PAIRS=`getfattr -h -d -m 'trusted.glusterfs.quota' $1 2>/dev/null | sed -e '/^# file/d'` - - for i in $XATTR_KEY_VALUE_PAIRS; do - XATTR_KEY=`echo $i | sed -e 's/\([^=]*\).*/\1/g'` - setfattr -h -x $XATTR_KEY $1 - done -} - -main $@ diff --git a/libglusterfs/src/glusterfs.h b/libglusterfs/src/glusterfs.h index 6dc2fe6df..09b26ecf3 100644 --- a/libglusterfs/src/glusterfs.h +++ b/libglusterfs/src/glusterfs.h @@ -87,6 +87,7 @@ #define GF_XATTR_GET_REAL_FILENAME_KEY "glusterfs.get_real_filename:" #define GF_XATTR_USER_PATHINFO_KEY "glusterfs.pathinfo" #define QUOTA_LIMIT_KEY "trusted.glusterfs.quota.limit-set" +#define VIRTUAL_QUOTA_XATTR_CLEANUP_KEY "glusterfs.quota-xattr-cleanup" #define GF_READDIR_SKIP_DIRS "readdir-filter-directories" diff --git a/xlators/features/marker/src/marker.c b/xlators/features/marker/src/marker.c index 280d43ae3..d6b6dd358 100644 --- a/xlators/features/marker/src/marker.c +++ b/xlators/features/marker/src/marker.c @@ -21,6 +21,7 @@ #include "marker-quota-helper.h" #include "marker-common.h" #include "byte-order.h" +#include "syncop.h" #define _GF_UID_GID_CHANGED 1 @@ -2153,16 +2154,150 @@ out: return 0; } +int +remove_quota_keys (dict_t *dict, char *k, data_t *v, void *data) +{ + call_frame_t *frame = data; + marker_local_t *local = frame->local; + xlator_t *this = frame->this; + int ret = -1; + + ret = syncop_removexattr (FIRST_CHILD (this), &local->loc, k); + if (ret) { + gf_log (this->name, GF_LOG_ERROR, "%s: Failed to remove " + "extended attribute: %s", local->loc.path, k); + return -1; + } + return 0; +} + +int +quota_xattr_cleaner_cbk (int ret, call_frame_t *frame, void *args) +{ + dict_t *xdata = args; + int op_ret = -1; + int op_errno = 0; + marker_local_t *local = NULL; + + local = frame->local; + frame->local = NULL; + + op_ret = (ret < 0)? -1: 0; + op_errno = -ret; + + STACK_UNWIND_STRICT (setxattr, frame, op_ret, op_errno, xdata); + marker_local_unref (local); + return ret; +} + +int +quota_xattr_cleaner (void *args) +{ + struct synctask *task = NULL; + call_frame_t *frame = NULL; + xlator_t *this = NULL; + marker_local_t *local = NULL; + dict_t *xdata = NULL; + int ret = -1; + + task = synctask_get (); + if (!task) + goto out; + + frame = task->frame; + this = frame->this; + local = frame->local; + + ret = syncop_listxattr (FIRST_CHILD(this), &local->loc, &xdata); + if (ret == -1) { + ret = -errno; + goto out; + } + + ret = dict_foreach_fnmatch (xdata, "trusted.glusterfs.quota.*", + remove_quota_keys, frame); + if (ret == -1) { + ret = -errno; + goto out; + } + ret = dict_foreach_fnmatch (xdata, PGFID_XATTR_KEY_PREFIX"*", + remove_quota_keys, frame); + if (ret == -1) { + ret = -errno; + goto out; + } + + ret = 0; +out: + if (xdata) + dict_unref (xdata); + + return ret; +} + +int +marker_do_xattr_cleanup (call_frame_t *frame, xlator_t *this, dict_t *xdata, + loc_t *loc) +{ + int ret = -1; + marker_local_t *local = NULL; + + local = mem_get0 (this->local_pool); + if (!local) + goto out; + + MARKER_INIT_LOCAL (frame, local); + + loc_copy (&local->loc, loc); + ret = synctask_new (this->ctx->env, quota_xattr_cleaner, + quota_xattr_cleaner_cbk, frame, xdata); + if (ret) { + gf_log (this->name, GF_LOG_ERROR, "Failed to create synctask " + "for cleaning up quota extended attributes"); + goto out; + } + + ret = 0; +out: + if (ret) { + frame->local = NULL; + STACK_UNWIND_STRICT (setxattr, frame, -1, ENOMEM, xdata); + marker_local_unref (local); + } + return ret; +} + +static inline gf_boolean_t +marker_xattr_cleanup_cmd (dict_t *dict) +{ + return (dict_get (dict, VIRTUAL_QUOTA_XATTR_CLEANUP_KEY) != NULL); +} + int32_t marker_setxattr (call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *dict, int32_t flags, dict_t *xdata) { - int32_t ret = 0; - marker_local_t *local = NULL; - marker_conf_t *priv = NULL; + int32_t ret = 0; + marker_local_t *local = NULL; + marker_conf_t *priv = NULL; + int op_errno = ENOMEM; priv = this->private; + if (marker_xattr_cleanup_cmd (dict)) { + if (frame->root->uid != 0 || frame->root->gid != 0) { + op_errno = EPERM; + ret = -1; + goto err; + } + + /* The following function does the cleanup and then unwinds the + * corresponding call*/ + loc_path (loc, NULL); + marker_do_xattr_cleanup (frame, this, xdata, loc); + return 0; + } + if (priv->feature_enabled == 0) goto wind; @@ -2183,7 +2318,7 @@ wind: FIRST_CHILD(this)->fops->setxattr, loc, dict, flags, xdata); return 0; err: - STACK_UNWIND_STRICT (setxattr, frame, -1, ENOMEM, NULL); + STACK_UNWIND_STRICT (setxattr, frame, -1, op_errno, NULL); return 0; } diff --git a/xlators/mgmt/glusterd/src/glusterd-quota.c b/xlators/mgmt/glusterd/src/glusterd-quota.c index 3c8dcf8dd..ffde532bd 100644 --- a/xlators/mgmt/glusterd/src/glusterd-quota.c +++ b/xlators/mgmt/glusterd/src/glusterd-quota.c @@ -28,6 +28,8 @@ #include #include +/* Any negative pid to make it special client */ +#define QUOTA_CRAWL_PID "-100" const char *gd_quota_op_list[GF_QUOTA_OPTION_TYPE_DEFAULT_SOFT_LIMIT+1] = { [GF_QUOTA_OPTION_TYPE_NONE] = "none", @@ -158,7 +160,8 @@ out: } int32_t -glusterd_quota_initiate_fs_crawl (glusterd_conf_t *priv, char *volname) +glusterd_quota_initiate_fs_crawl (glusterd_conf_t *priv, char *volname, + int type) { pid_t pid; int32_t ret = 0; @@ -178,6 +181,7 @@ glusterd_quota_initiate_fs_crawl (glusterd_conf_t *priv, char *volname) "-s", "localhost", "--volfile-id", volname, "--use-readdirp=no", + "--client-pid", QUOTA_CRAWL_PID, "-l", DEFAULT_LOG_FILE_DIRECTORY"/quota-crawl.log", mountdir, NULL); @@ -210,7 +214,19 @@ glusterd_quota_initiate_fs_crawl (glusterd_conf_t *priv, char *volname) exit (EXIT_FAILURE); } runinit (&runner); - runner_add_args (&runner, "/usr/bin/find", "find", ".", NULL); + + if (type == GF_QUOTA_OPTION_TYPE_ENABLE) + + runner_add_args (&runner, "/usr/bin/find", "find", ".", + NULL); + + else if (type == GF_QUOTA_OPTION_TYPE_DISABLE) + + runner_add_args (&runner, "/usr/bin/find", ".", + "-exec", "/usr/bin/setfattr", "-n", + VIRTUAL_QUOTA_XATTR_CLEANUP_KEY, "-v", + "1", "{}", "\\", ";", NULL); + if (runner_start (&runner) == -1) _exit (EXIT_FAILURE); @@ -325,7 +341,8 @@ out: } int32_t -glusterd_quota_disable (glusterd_volinfo_t *volinfo, char **op_errstr) +glusterd_quota_disable (glusterd_volinfo_t *volinfo, char **op_errstr, + gf_boolean_t *crawl) { int32_t ret = -1; int i = 0; @@ -381,6 +398,8 @@ glusterd_quota_disable (glusterd_volinfo_t *volinfo, char **op_errstr) if (ret) goto out; + *crawl = _gf_true; + (void) glusterd_clean_up_quota_store (volinfo); ret = 0; @@ -1045,7 +1064,8 @@ glusterd_op_quota (dict_t *dict, char **op_errstr, dict_t *rsp_dict) break; case GF_QUOTA_OPTION_TYPE_DISABLE: - ret = glusterd_quota_disable (volinfo, op_errstr); + ret = glusterd_quota_disable (volinfo, op_errstr, + &start_crawl); if (ret < 0) goto out; @@ -1129,7 +1149,7 @@ glusterd_op_quota (dict_t *dict, char **op_errstr, dict_t *rsp_dict) } if (rsp_dict && start_crawl == _gf_true) - glusterd_quota_initiate_fs_crawl (priv, volname); + glusterd_quota_initiate_fs_crawl (priv, volname, type); if (priv->op_version > GD_OP_VERSION_MIN) { ret = glusterd_quotad_op (type); -- cgit From a20e79ab3d0827936b679689055ea453c1d01abb Mon Sep 17 00:00:00 2001 From: Krishnan Parthasarathi Date: Tue, 17 Dec 2013 16:04:46 +0530 Subject: quota: fix recording of last alert log message PROBLEM: Alert log messages, corresponding to disk usage crossing soft-limit on a directory, weren't being logged as often as expected. CAUSE: The mechanism in place to log alert messages, once every alert-time seconds, set the previous logged time incorrectly. FIX: Update previous logged time only if we logged an alert message, ie. when the "time was right" to alert. Change-Id: Iafcb7be11e3240e2d04b0bb29ddb88e4f4a1bd25 BUG: 969461 Signed-off-by: Krishnan Parthasarathi Reviewed-on: http://review.gluster.org/6532 Tested-by: Gluster Build System Reviewed-by: Raghavendra G Reviewed-by: Vijay Bellur --- xlators/features/quota/src/quota.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/xlators/features/quota/src/quota.c b/xlators/features/quota/src/quota.c index a531ab123..c42b23027 100644 --- a/xlators/features/quota/src/quota.c +++ b/xlators/features/quota/src/quota.c @@ -3935,7 +3935,7 @@ wind: /* Logs if * i. Usage crossed soft limit -* ii. Usage above soft limit and alert-time timed out +* ii. Usage above soft limit and alert-time elapsed */ void quota_log_usage (xlator_t *this, quota_inode_ctx_t *ctx, inode_t *inode, @@ -3943,39 +3943,45 @@ quota_log_usage (xlator_t *this, quota_inode_ctx_t *ctx, inode_t *inode, { struct timeval cur_time = {0,}; char *usage_str = NULL; + char size_str[32] = {0}; char *path = NULL; int64_t cur_size = 0; quota_priv_t *priv = NULL; priv = this->private; - cur_size = ctx->size + delta; if ((ctx->soft_lim <= 0) || (timerisset (&ctx->prev_log) && !quota_timeout (&ctx->prev_log, priv->log_timeout))) { return; } - gettimeofday (&cur_time, NULL); - ctx->prev_log = cur_time; + cur_size = ctx->size + delta; usage_str = gf_uint64_2human_readable (cur_size); + if (!usage_str) { + snprintf (size_str, sizeof (size_str), "%"PRId64, cur_size); + usage_str = (char*) size_str; + } inode_path (inode, NULL, &path); if (!path) path = uuid_utoa (inode->gfid); + gettimeofday (&cur_time, NULL); /* Usage crossed/reached soft limit */ if (DID_REACH_LIMIT (ctx->soft_lim, ctx->size, cur_size)) { gf_log (this->name, GF_LOG_ALERT, "Usage crossed " "soft limit: %s used by %s", usage_str, path); + ctx->prev_log = cur_time; } /* Usage is above soft limit */ else if (cur_size > ctx->soft_lim){ gf_log (this->name, GF_LOG_ALERT, "Usage is above " "soft limit: %s used by %s", usage_str, path); + ctx->prev_log = cur_time; } - if (usage_str) - GF_FREE (usage_str); + + GF_FREE (usage_str); } int32_t -- cgit From c0a14c00bfb9152abdb5cedcf5aa1b9ed9a6ac6a Mon Sep 17 00:00:00 2001 From: Varun Shastry Date: Fri, 29 Nov 2013 14:49:33 +0530 Subject: features/quota: Make grep search more accurately The hook script was searching the info file for "features.quota" to know the quota status (enable/disabled). When features.quota-deem-statfs the grep is not accurate. Fixed this issue. Change-Id: I4104a93c1c1e0ac9fd7ef7bfef993425ab50e651 BUG: 969461 Signed-off-by: Varun Shastry Reviewed-on: http://review.gluster.org/6380 Tested-by: Gluster Build System Reviewed-by: Pranith Kumar Karampuri Reviewed-by: Vijay Bellur --- extras/hook-scripts/add-brick/pre/S28Quota-enable-root-xattr-heal.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/extras/hook-scripts/add-brick/pre/S28Quota-enable-root-xattr-heal.sh b/extras/hook-scripts/add-brick/pre/S28Quota-enable-root-xattr-heal.sh index 2580a4c58..d5658e3c8 100755 --- a/extras/hook-scripts/add-brick/pre/S28Quota-enable-root-xattr-heal.sh +++ b/extras/hook-scripts/add-brick/pre/S28Quota-enable-root-xattr-heal.sh @@ -80,7 +80,7 @@ then fi ## Is quota enabled? -FLAG=`cat $GLUSTERD_WORKING_DIR/vols/$VOL_NAME/info | grep "^features.quota" \ +FLAG=`cat $GLUSTERD_WORKING_DIR/vols/$VOL_NAME/info | grep "^features.quota=" \ | awk -F'=' '{print $NF}'`; if [ "$FLAG" != "on" ] then @@ -88,7 +88,7 @@ then fi ## Is volume started? -FLAG=`cat $GLUSTERD_WORKING_DIR/vols/$VOL_NAME/info | grep "^status" \ +FLAG=`cat $GLUSTERD_WORKING_DIR/vols/$VOL_NAME/info | grep "^status=" \ | awk -F'=' '{print $NF}'`; if [ "$FLAG" != "1" ] then -- cgit From 63638748d744377d899e9ee0b5e7831d7c1c2496 Mon Sep 17 00:00:00 2001 From: Varun Shastry Date: Fri, 27 Dec 2013 15:39:19 +0530 Subject: features/quota: Handle the corner case in statfs call Problem: Even though limit is not set quota used to send 'quota-deem-statfs' key in the dictionary resulting in incorrect calculations. Change-Id: I643cb35cca6648e40f1c745135280876958ddaa9 BUG: 1046894 Signed-off-by: Varun Shastry Reviewed-on: http://review.gluster.org/6607 Tested-by: Gluster Build System Reviewed-by: Raghavendra G --- xlators/features/quota/src/quota.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/xlators/features/quota/src/quota.c b/xlators/features/quota/src/quota.c index c42b23027..d46247241 100644 --- a/xlators/features/quota/src/quota.c +++ b/xlators/features/quota/src/quota.c @@ -3461,13 +3461,13 @@ quota_statfs_cbk (call_frame_t *frame, void *cookie, xlator_t *this, if (ctx->hard_lim <= 0) { inode_ctx_get (inode->table->root, this, &value); ctx = (quota_inode_ctx_t *)(unsigned long) value; - if (!ctx) + if (!ctx || ctx->hard_lim < 0) goto unwind; } - usage = (ctx->size) / buf->f_bsize; + { /* statfs is adjusted in this code block */ + usage = (ctx->size) / buf->f_bsize; - if (ctx->hard_lim > 0) { blocks = ctx->hard_lim / buf->f_bsize; buf->f_blocks = blocks; -- cgit From 1ffc3ac9639e25c91ac26488b648d5523becb08e Mon Sep 17 00:00:00 2001 From: Lalatendu Mohanty Date: Tue, 14 Jan 2014 23:50:51 +0530 Subject: core: Coverity issue "Use of uninitialized scalar variable" Issue: 1. In "unlink (export_path)" "export_path" might contain an arbitrary value left from earlier computations. 2. In "(msg[0] != '\0')" msg might contain an arbitrary value Change-Id: Icca8f557fd6b5e046dff1d5a84a72061975868d0 BUG: 789278 Signed-off-by: Lalatendu Mohanty Reviewed-on: http://review.gluster.org/6701 Tested-by: Gluster Build System Reviewed-by: Vijay Bellur --- glusterfsd/src/glusterfsd-mgmt.c | 4 ++-- xlators/mgmt/glusterd/src/glusterd-volume-ops.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/glusterfsd/src/glusterfsd-mgmt.c b/glusterfsd/src/glusterfsd-mgmt.c index 0484779ce..de2829ddd 100644 --- a/glusterfsd/src/glusterfsd-mgmt.c +++ b/glusterfsd/src/glusterfsd-mgmt.c @@ -365,7 +365,7 @@ glusterfs_volume_top_write_perf (uint32_t blk_size, uint32_t blk_count, { int32_t fd = -1; int32_t input_fd = -1; - char export_path[PATH_MAX]; + char export_path[PATH_MAX] = {0,}; char *buf = NULL; int32_t iter = 0; int32_t ret = -1; @@ -448,7 +448,7 @@ glusterfs_volume_top_read_perf (uint32_t blk_size, uint32_t blk_count, int32_t fd = -1; int32_t input_fd = -1; int32_t output_fd = -1; - char export_path[PATH_MAX]; + char export_path[PATH_MAX] = {0,}; char *buf = NULL; int32_t iter = 0; int32_t ret = -1; diff --git a/xlators/mgmt/glusterd/src/glusterd-volume-ops.c b/xlators/mgmt/glusterd/src/glusterd-volume-ops.c index db9f39c7c..85a537306 100644 --- a/xlators/mgmt/glusterd/src/glusterd-volume-ops.c +++ b/xlators/mgmt/glusterd/src/glusterd-volume-ops.c @@ -923,7 +923,7 @@ glusterd_op_stage_start_volume (dict_t *dict, char **op_errstr) gf_boolean_t exists = _gf_false; glusterd_volinfo_t *volinfo = NULL; glusterd_brickinfo_t *brickinfo = NULL; - char msg[2048]; + char msg[2048] = {0,}; glusterd_conf_t *priv = NULL; xlator_t *this = NULL; uuid_t volume_id = {0,}; -- cgit From c2b09dc87e0763dfdff1e93a1dc6cc4c05f091bf Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Sat, 17 Aug 2013 13:01:23 -0700 Subject: build: Start using library versioning for various libraries According to libtool three individual numbers stand for CURRENT:REVISION:AGE, or C:R:A for short. The libtool script typically tacks these three numbers onto the end of the name of the .so file it creates. The formula for calculating the file numbers on Linux and Solaris is /path/to/library/.(C - A).(A).(R) As you release new versions of your library, you will update the library's C:R:A. Although the rules for changing these version numbers can quickly become confusing, a few simple tips should help keep you on track. The libtool documentation goes into greater depth. In essence, every time you make a change to the library and release it, the C:R:A should change. A new library should start with 0:0:0. Each time you change the public interface (i.e., your installed header files), you should increment the CURRENT number. This is called your interface number. The main use of this interface number is to tag successive revisions of your API. The AGE number is how many consecutive versions of the API the current implementation supports. Thus if the CURRENT library API is the sixth published version of the interface and it is also binary compatible with the fourth and fifth versions (i.e., the last two), the C:R:A might be 6:0:2. When you break binary compatibility, you need to set AGE to 0 and of course increment CURRENT. The REVISION marks a change in the source code of the library that doesn't affect the interface-for example, a minor bug fix. Anytime you increment CURRENT, you should set REVISION back to 0. Change-Id: Id72e74c1642c804fea6f93ec109135c7c16f1810 BUG: 862082 Signed-off-by: Harshavardhana Reviewed-on: http://review.gluster.org/5645 Tested-by: Gluster Build System Reviewed-by: Niels de Vos Reviewed-by: Vijay Bellur --- api/src/Makefile.am | 1 + configure.ac | 18 +++++++++++ doc/versioning.md | 44 ++++++++++++++++++++++++++ glusterfs-api.pc.in | 3 +- libgfchangelog.pc.in | 2 +- libglusterfs/src/Makefile.am | 1 + rpc/rpc-lib/src/Makefile.am | 1 + rpc/xdr/src/Makefile.am | 2 ++ xlators/features/changelog/lib/src/Makefile.am | 2 +- 9 files changed, 70 insertions(+), 4 deletions(-) create mode 100644 doc/versioning.md diff --git a/api/src/Makefile.am b/api/src/Makefile.am index 7c5df3e20..c9992d1d3 100644 --- a/api/src/Makefile.am +++ b/api/src/Makefile.am @@ -15,6 +15,7 @@ libgfapi_la_CPPFLAGS = $(GF_CPPFLAGS) -D__USE_FILE_OFFSET64 \ -I$(top_srcdir)/rpc/rpc-lib/src \ -I$(top_srcdir)/rpc/xdr/src +libgfapi_la_LDFLAGS = -version-info $(GFAPI_LT_VERSION) xlator_LTLIBRARIES = api.la xlatordir = $(libdir)/glusterfs/$(PACKAGE_VERSION)/xlator/mount diff --git a/configure.ac b/configure.ac index be1ec7ab6..abcf99ac9 100644 --- a/configure.ac +++ b/configure.ac @@ -888,6 +888,24 @@ AM_CONDITIONAL([GF_DARWIN_HOST_OS], test "${GF_HOST_OS}" = "GF_DARWIN_HOST_OS") AM_CONDITIONAL([GF_INSTALL_VAR_LIB_GLUSTERD], test ! -d ${localstatedir}/lib/glusterd && test -d ${sysconfdir}/glusterd ) +dnl pkg-config versioning +GFAPI_VERSION="0.0.6" +LIBGFCHANGELOG_VERSION="0.0.1" +AC_SUBST(GFAPI_VERSION) +AC_SUBST(LIBGFCHANGELOG_VERSION) + +dnl libtool versioning +LIBGFXDR_LT_VERSION="0:1:0" +LIBGFRPC_LT_VERSION="0:1:0" +LIBGLUSTERFS_LT_VERSION="0:1:0" +LIBGFCHANGELOG_LT_VERSION="0:1:0" +GFAPI_LT_VERSION="0:6:0" +AC_SUBST(LIBGFXDR_LT_VERSION) +AC_SUBST(LIBGFRPC_LT_VERSION) +AC_SUBST(LIBGLUSTERFS_LT_VERSION) +AC_SUBST(LIBGFCHANGELOG_LT_VERSION) +AC_SUBST(GFAPI_LT_VERSION) + AC_OUTPUT echo diff --git a/doc/versioning.md b/doc/versioning.md new file mode 100644 index 000000000..10c1511b7 --- /dev/null +++ b/doc/versioning.md @@ -0,0 +1,44 @@ +Versioning +========== + +### current + +The number of the current interface exported by the library. A current value +of '1', means that you are calling the interface exported by this library +interface 1. + +### revision + +The implementation number of the most recent interface exported by this library. +In this case, a revision value of `0` means that this is the first +implementation of the interface. + +If the next release of this library exports the same interface, but has a +different implementation (perhaps some bugs have been fixed), the revision +number will be higher, but current number will be the same. In that case, when +given a choice, the library with the highest revision will always be used by +the runtime loader. + +### age + +The number of previous additional interfaces supported by this library. If age +were '2', then this library can be linked into executables which were built with +a release of this library that exported the current interface number, current, +or any of the previous two interfaces. By definition age must be less than or +equal to current. At the outset, only the first ever interface is implemented, +so age can only be `0'. + +For every release of the library `-version-info` argument needs to be set +correctly depending on any interface changes you have made. + +This is quite straightforward when you understand what the three numbers mean: + +If you have changed any of the sources for this library, the revision number +must be incremented. This is a new revision of the current interface. If the +interface has changed, then current must be incremented, and revision reset +to '0'. + +This is the first revision of a new interface. If the new interface is a +superset of the previous interface (that is, if the previous interface has not +been broken by the changes in this new release), then age must be incremented. +This release is backwards compatible with the previous release. diff --git a/glusterfs-api.pc.in b/glusterfs-api.pc.in index fab4a57d5..e88e70369 100644 --- a/glusterfs-api.pc.in +++ b/glusterfs-api.pc.in @@ -3,10 +3,9 @@ exec_prefix=@exec_prefix@ libdir=@libdir@ includedir=@includedir@ - Name: glusterfs-api Description: GlusterFS API /* This is the API version, NOT package version */ -Version: 6 +Version: @GFAPI_VERSION@ Libs: -L${libdir} -lgfapi -lglusterfs -lgfrpc -lgfxdr Cflags: -I${includedir}/glusterfs -D_FILE_OFFSET_BITS=64 -D__USE_FILE_OFFSET64 diff --git a/libgfchangelog.pc.in b/libgfchangelog.pc.in index d654280d0..398f1233f 100644 --- a/libgfchangelog.pc.in +++ b/libgfchangelog.pc.in @@ -6,6 +6,6 @@ includedir=@includedir@ Name: libgfchangelog Description: GlusterFS Changelog Consumer Library -Version: @VERSION@ +Version: @LIBGFCHANGELOG_VERSION@ Libs: -L${libdir} -lgfchangelog -lglusterfs Cflags: -I${includedir}/glusterfs/gfchangelog -D_FILE_OFFSET_BITS=64 -D__USE_FILE_OFFSET64 diff --git a/libglusterfs/src/Makefile.am b/libglusterfs/src/Makefile.am index 907399ae6..634e217ed 100644 --- a/libglusterfs/src/Makefile.am +++ b/libglusterfs/src/Makefile.am @@ -7,6 +7,7 @@ libglusterfs_la_CPPFLAGS = $(GF_CPPFLAGS) -D__USE_FILE_OFFSET64 \ -I$(top_srcdir)/rpc/rpc-lib/src/ -I$(CONTRIBDIR)/rbtree libglusterfs_la_LIBADD = @LEXLIB@ +libglusterfs_la_LDFLAGS = -version-info $(LIBGLUSTERFS_LT_VERSION) lib_LTLIBRARIES = libglusterfs.la diff --git a/rpc/rpc-lib/src/Makefile.am b/rpc/rpc-lib/src/Makefile.am index f19c3c8a4..4cdeaad0b 100644 --- a/rpc/rpc-lib/src/Makefile.am +++ b/rpc/rpc-lib/src/Makefile.am @@ -5,6 +5,7 @@ libgfrpc_la_SOURCES = auth-unix.c rpcsvc-auth.c rpcsvc.c auth-null.c \ rpc-drc.c libgfrpc_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la +libgfrpc_la_LDFLAGS = -version-info $(LIBGFRPC_LT_VERSION) noinst_HEADERS = rpcsvc.h rpc-transport.h xdr-common.h xdr-rpc.h xdr-rpcclnt.h \ rpc-clnt.h rpcsvc-common.h protocol-common.h rpc-drc.h diff --git a/rpc/xdr/src/Makefile.am b/rpc/xdr/src/Makefile.am index 949e75e8d..0ec96e464 100644 --- a/rpc/xdr/src/Makefile.am +++ b/rpc/xdr/src/Makefile.am @@ -8,6 +8,8 @@ libgfxdr_la_CPPFLAGS = $(GF_CPPFLAGS) -D__USE_FILE_OFFSET64 \ libgfxdr_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la \ $(top_builddir)/rpc/rpc-lib/src/libgfrpc.la +libgfxdr_la_LDFLAGS = -version-info $(LIBGFXDR_LT_VERSION) + libgfxdr_la_SOURCES = xdr-generic.c rpc-common-xdr.c \ glusterfs3-xdr.c \ cli1-xdr.c \ diff --git a/xlators/features/changelog/lib/src/Makefile.am b/xlators/features/changelog/lib/src/Makefile.am index fbaaea628..775f026cf 100644 --- a/xlators/features/changelog/lib/src/Makefile.am +++ b/xlators/features/changelog/lib/src/Makefile.am @@ -9,7 +9,7 @@ libgfchangelog_la_CPPFLAGS = $(GF_CPPFLAGS) -D__USE_FILE_OFFSET64 -fpic \ libgfchangelog_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la \ $(GF_GLUSTERFS_LIBS) -libgfchangelog_la_LDFLAGS = $(GF_LDFLAGS) +libgfchangelog_la_LDFLAGS = $(GF_LDFLAGS) -version-info $(LIBGFCHANGELOG_LT_VERSION) libgfchangelogdir = $(includedir)/glusterfs/gfchangelog lib_LTLIBRARIES = libgfchangelog.la -- cgit From 8d55c25f158921b508bff0e7f25158991913f922 Mon Sep 17 00:00:00 2001 From: Pranith Kumar K Date: Wed, 11 Dec 2013 09:33:53 +0530 Subject: syncop: Change return value of syncop Problem: We found a day-1 bug when syncop_xxx() infra is used inside a synctask with compilation optimization (CFLAGS -O2). Detailed explanation of the Root cause: We found the bug in 'gf_defrag_migrate_data' in rebalance operation: Lets look at interesting parts of the function: int gf_defrag_migrate_data (xlator_t *this, gf_defrag_info_t *defrag, loc_t *loc, dict_t *migrate_data) { ..... code section - [ Loop ] while ((ret = syncop_readdirp (this, fd, 131072, offset, NULL, &entries)) != 0) { ..... code section - [ ERRNO-1 ] (errno of readdirp is stored in readdir_operrno by a thread) /* Need to keep track of ENOENT errno, that means, there is no need to send more readdirp() */ readdir_operrno = errno; ..... code section - [ SYNCOP-1 ] (syncop_getxattr is called by a thread) ret = syncop_getxattr (this, &entry_loc, &dict, GF_XATTR_LINKINFO_KEY); code section - [ ERRNO-2] (checking for failures of syncop_getxattr(). This may not always be executed in same thread which executed [SYNCOP-1]) if (ret < 0) { if (errno != ENODATA) { loglevel = GF_LOG_ERROR; defrag->total_failures += 1; ..... } the function above could be executed by thread(t1) till [SYNCOP-1] and code from [ERRNO-2] can be executed by a different thread(t2) because of the way syncop-infra schedules the tasks. when the code is compiled with -O2 optimization this is the assembly code that is generated: [ERRNO-1] 1165 readdir_operrno = errno; <<---- errno gets expanded as *(__errno_location()) 0x00007fd149d48b60 <+496>: callq 0x7fd149d410c0 0x00007fd149d48b72 <+514>: mov %rax,0x50(%rsp) <<------ Address returned by __errno_location() is stored in a special location in stack for later use. 0x00007fd149d48b77 <+519>: mov (%rax),%eax 0x00007fd149d48b79 <+521>: mov %eax,0x78(%rsp) .... [ERRNO-2] 1281 if (errno != ENODATA) { 0x00007fd149d492ae <+2366>: mov 0x50(%rsp),%rax <<----- Because it already stored the address returned by __errno_location(), it just dereferences the address to get the errno value. BUT THIS CODE NEED NOT BE EXECUTED BY SAME THREAD!!! 0x00007fd149d492b3 <+2371>: mov $0x9,%ebp 0x00007fd149d492b8 <+2376>: mov (%rax),%edi 0x00007fd149d492ba <+2378>: cmp $0x3d,%edi The problem is that __errno_location() value of t1 and t2 are different. So [ERRNO-2] ends up reading errno of t1 instead of errno of t2 even though t2 is executing [ERRNO-2] code section. When code is compiled without any optimization for [ERRNO-2]: 1281 if (errno != ENODATA) { 0x00007fd58e7a326f <+2237>: callq 0x7fd58e797300 <<--- As it is calling __errno_location() again it gets the location from t2 so it works as intended. 0x00007fd58e7a3274 <+2242>: mov (%rax),%eax 0x00007fd58e7a3276 <+2244>: cmp $0x3d,%eax 0x00007fd58e7a3279 <+2247>: je 0x7fd58e7a32a1 Fix: Make syncop_xxx() return (-errno) value as the return value in case of errors and all the functions which make syncop_xxx() will need to use (-ret) to figure out the reason for failure in case of syncop_xxx() failures. Change-Id: I314d20dabe55d3e62ff66f3b4adb1cac2eaebb57 BUG: 1040356 Signed-off-by: Pranith Kumar K Reviewed-on: http://review.gluster.org/6475 Tested-by: Gluster Build System Reviewed-by: Anand Avati --- api/src/glfs-fops.c | 36 +++++ api/src/glfs-handleops.c | 15 ++ api/src/glfs-internal.h | 20 +++ api/src/glfs-resolve.c | 10 ++ libglusterfs/src/syncop.c | 117 ++++++++++------ xlators/cluster/afr/src/afr-self-heald.c | 44 ++++-- xlators/cluster/afr/src/pump.c | 6 +- xlators/cluster/dht/src/dht-helper.c | 24 ++-- xlators/cluster/dht/src/dht-rebalance.c | 176 ++++++++++++++---------- xlators/cluster/dht/src/dht-selfheal.c | 5 +- xlators/features/locks/src/posix.c | 3 +- xlators/features/qemu-block/src/bdrv-xlator.c | 15 +- xlators/features/qemu-block/src/qb-coroutines.c | 15 +- xlators/mount/fuse/src/fuse-bridge.c | 18 ++- 14 files changed, 343 insertions(+), 161 deletions(-) diff --git a/api/src/glfs-fops.c b/api/src/glfs-fops.c index 5ea54567d..67d5616fe 100644 --- a/api/src/glfs-fops.c +++ b/api/src/glfs-fops.c @@ -124,6 +124,7 @@ retry: } ret = syncop_open (subvol, &loc, flags, glfd->fd); + DECODE_SYNCOP_ERR (ret); ESTALE_RETRY (ret, errno, reval, &loc, retry); out: @@ -169,6 +170,7 @@ glfs_close (struct glfs_fd *glfd) } ret = syncop_flush (subvol, fd); + DECODE_SYNCOP_ERR (ret); out: fs = glfd->fs; glfs_fd_destroy (glfd); @@ -273,6 +275,7 @@ glfs_fstat (struct glfs_fd *glfd, struct stat *stat) } ret = syncop_fstat (subvol, fd, &iatt); + DECODE_SYNCOP_ERR (ret); if (ret == 0 && stat) glfs_iatt_to_stat (glfd->fs, &iatt, stat); @@ -392,9 +395,11 @@ retry: if (ret == 0) { ret = syncop_open (subvol, &loc, flags, glfd->fd); + DECODE_SYNCOP_ERR (ret); } else { ret = syncop_create (subvol, &loc, flags, mode, glfd->fd, xattr_req, &iatt); + DECODE_SYNCOP_ERR (ret); } ESTALE_RETRY (ret, errno, reval, &loc, retry); @@ -484,6 +489,7 @@ glfs_preadv (struct glfs_fd *glfd, const struct iovec *iovec, int iovcnt, size = iov_length (iovec, iovcnt); ret = syncop_readv (subvol, fd, size, offset, 0, &iov, &cnt, &iobref); + DECODE_SYNCOP_ERR (ret); if (ret <= 0) goto out; @@ -833,6 +839,7 @@ glfs_pwritev (struct glfs_fd *glfd, const struct iovec *iovec, int iovcnt, iov.iov_len = size; ret = syncop_writev (subvol, fd, &iov, 1, offset, iobref, flags); + DECODE_SYNCOP_ERR (ret); iobuf_unref (iobuf); iobref_unref (iobref); @@ -1005,6 +1012,7 @@ glfs_fsync (struct glfs_fd *glfd) } ret = syncop_fsync (subvol, fd, 0); + DECODE_SYNCOP_ERR (ret); out: if (fd) fd_unref (fd); @@ -1079,6 +1087,7 @@ glfs_fdatasync (struct glfs_fd *glfd) } ret = syncop_fsync (subvol, fd, 1); + DECODE_SYNCOP_ERR (ret); out: if (fd) fd_unref (fd); @@ -1120,6 +1129,7 @@ glfs_ftruncate (struct glfs_fd *glfd, off_t offset) } ret = syncop_ftruncate (subvol, fd, offset); + DECODE_SYNCOP_ERR (ret); out: if (fd) fd_unref (fd); @@ -1188,6 +1198,7 @@ retry: goto out; ret = syncop_access (subvol, &loc, mode); + DECODE_SYNCOP_ERR (ret); ESTALE_RETRY (ret, errno, reval, &loc, retry); out: @@ -1263,6 +1274,7 @@ retry: } ret = syncop_symlink (subvol, &loc, data, xattr_req, &iatt); + DECODE_SYNCOP_ERR (ret); ESTALE_RETRY (ret, errno, reval, &loc, retry); @@ -1313,6 +1325,7 @@ retry: } ret = syncop_readlink (subvol, &loc, &linkval, bufsiz); + DECODE_SYNCOP_ERR (ret); if (ret > 0) { memcpy (buf, linkval, ret); GF_FREE (linkval); @@ -1392,6 +1405,7 @@ retry: } ret = syncop_mknod (subvol, &loc, mode, dev, xattr_req, &iatt); + DECODE_SYNCOP_ERR (ret); ESTALE_RETRY (ret, errno, reval, &loc, retry); @@ -1473,6 +1487,7 @@ retry: } ret = syncop_mkdir (subvol, &loc, mode, xattr_req, &iatt); + DECODE_SYNCOP_ERR (ret); ESTALE_RETRY (ret, errno, reval, &loc, retry); @@ -1522,6 +1537,7 @@ retry: } ret = syncop_unlink (subvol, &loc); + DECODE_SYNCOP_ERR (ret); ESTALE_RETRY (ret, errno, reval, &loc, retry); @@ -1568,6 +1584,7 @@ retry: } ret = syncop_rmdir (subvol, &loc, 0); + DECODE_SYNCOP_ERR (ret); ESTALE_RETRY (ret, errno, reval, &loc, retry); @@ -1631,6 +1648,7 @@ retrynew: /* TODO: check if new or old is a prefix of the other, and fail EINVAL */ ret = syncop_rename (subvol, &oldloc, &newloc); + DECODE_SYNCOP_ERR (ret); if (ret == -1 && errno == ESTALE) { if (reval < DEFAULT_REVAL_COUNT) { @@ -1708,6 +1726,7 @@ retrynew: newloc.inode = inode_ref (oldloc.inode); ret = syncop_link (subvol, &oldloc, &newloc); + DECODE_SYNCOP_ERR (ret); if (ret == -1 && errno == ESTALE) { loc_wipe (&oldloc); @@ -1782,6 +1801,7 @@ retry: } ret = syncop_opendir (subvol, &loc, glfd->fd); + DECODE_SYNCOP_ERR (ret); ESTALE_RETRY (ret, errno, reval, &loc, retry); out: @@ -1972,6 +1992,7 @@ glfd_entry_refresh (struct glfs_fd *glfd, int plus) else ret = syncop_readdir (subvol, fd, 131072, glfd->offset, &entries); + DECODE_SYNCOP_ERR (ret); if (ret >= 0) { if (plus) gf_link_inodes_from_dirent (THIS, fd->inode, &entries); @@ -2150,6 +2171,7 @@ retry: goto out; ret = syncop_statfs (subvol, &loc, buf); + DECODE_SYNCOP_ERR (ret); ESTALE_RETRY (ret, errno, reval, &loc, retry); out: @@ -2191,6 +2213,7 @@ retry: goto out; ret = syncop_setattr (subvol, &loc, iatt, valid, 0, 0); + DECODE_SYNCOP_ERR (ret); ESTALE_RETRY (ret, errno, reval, &loc, retry); out: @@ -2226,6 +2249,7 @@ glfs_fsetattr (struct glfs_fd *glfd, struct iatt *iatt, int valid) } ret = syncop_fsetattr (subvol, fd, iatt, valid, 0, 0); + DECODE_SYNCOP_ERR (ret); out: if (fd) fd_unref (fd); @@ -2442,6 +2466,7 @@ retry: goto out; ret = syncop_getxattr (subvol, &loc, &xattr, name); + DECODE_SYNCOP_ERR (ret); ESTALE_RETRY (ret, errno, reval, &loc, retry); @@ -2500,6 +2525,7 @@ glfs_fgetxattr (struct glfs_fd *glfd, const char *name, void *value, } ret = syncop_fgetxattr (subvol, fd, &xattr, name); + DECODE_SYNCOP_ERR (ret); if (ret) goto out; @@ -2570,6 +2596,7 @@ retry: goto out; ret = syncop_getxattr (subvol, &loc, &xattr, NULL); + DECODE_SYNCOP_ERR (ret); ESTALE_RETRY (ret, errno, reval, &loc, retry); @@ -2625,6 +2652,7 @@ glfs_flistxattr (struct glfs_fd *glfd, void *value, size_t size) } ret = syncop_fgetxattr (subvol, fd, &xattr, NULL); + DECODE_SYNCOP_ERR (ret); if (ret) goto out; @@ -2697,6 +2725,7 @@ retry: } ret = syncop_setxattr (subvol, &loc, xattr, flags); + DECODE_SYNCOP_ERR (ret); ESTALE_RETRY (ret, errno, reval, &loc, retry); @@ -2760,6 +2789,7 @@ glfs_fsetxattr (struct glfs_fd *glfd, const char *name, const void *value, } ret = syncop_fsetxattr (subvol, fd, xattr, flags); + DECODE_SYNCOP_ERR (ret); out: if (xattr) dict_unref (xattr); @@ -2803,6 +2833,7 @@ retry: goto out; ret = syncop_removexattr (subvol, &loc, name); + DECODE_SYNCOP_ERR (ret); ESTALE_RETRY (ret, errno, reval, &loc, retry); @@ -2853,6 +2884,7 @@ glfs_fremovexattr (struct glfs_fd *glfd, const char *name) } ret = syncop_fremovexattr (subvol, fd, name); + DECODE_SYNCOP_ERR (ret); out: if (fd) fd_unref (fd); @@ -2887,6 +2919,7 @@ glfs_fallocate (struct glfs_fd *glfd, int keep_size, off_t offset, size_t len) } ret = syncop_fallocate (subvol, fd, keep_size, offset, len); + DECODE_SYNCOP_ERR (ret); out: if (fd) fd_unref(fd); @@ -2921,6 +2954,7 @@ glfs_discard (struct glfs_fd *glfd, off_t offset, size_t len) } ret = syncop_discard (subvol, fd, offset, len); + DECODE_SYNCOP_ERR (ret); out: if (fd) fd_unref(fd); @@ -2952,6 +2986,7 @@ glfs_zerofill (struct glfs_fd *glfd, off_t offset, off_t len) } ret = syncop_zerofill (subvol, fd, offset, len); + DECODE_SYNCOP_ERR (ret); out: if (fd) fd_unref(fd); @@ -3200,6 +3235,7 @@ glfs_posix_lock (struct glfs_fd *glfd, int cmd, struct flock *flock) gf_flock_from_flock (&gf_flock, flock); gf_flock_from_flock (&saved_flock, flock); ret = syncop_lk (subvol, fd, cmd, &gf_flock); + DECODE_SYNCOP_ERR (ret); gf_flock_to_flock (&gf_flock, flock); if (ret == 0 && (cmd == F_SETLK || cmd == F_SETLKW)) diff --git a/api/src/glfs-handleops.c b/api/src/glfs-handleops.c index 0f996d3a2..5bba38b5f 100644 --- a/api/src/glfs-handleops.c +++ b/api/src/glfs-handleops.c @@ -152,6 +152,7 @@ glfs_h_stat (struct glfs *fs, struct glfs_object *object, struct stat *stat) /* fop/op */ ret = syncop_stat (subvol, &loc, &iatt); + DECODE_SYNCOP_ERR (ret); /* populate out args */ if (!ret && stat) { @@ -258,6 +259,7 @@ glfs_h_setattrs (struct glfs *fs, struct glfs_object *object, struct stat *stat, /* fop/op */ ret = syncop_setattr (subvol, &loc, &iatt, glvalid, 0, 0); + DECODE_SYNCOP_ERR (ret); out: loc_wipe (&loc); @@ -331,6 +333,7 @@ glfs_h_open (struct glfs *fs, struct glfs_object *object, int flags) /* fop/op */ ret = syncop_open (subvol, &loc, flags, glfd->fd); + DECODE_SYNCOP_ERR (ret); out: loc_wipe (&loc); @@ -420,6 +423,7 @@ glfs_h_creat (struct glfs *fs, struct glfs_object *parent, const char *path, /* fop/op */ ret = syncop_create (subvol, &loc, flags, mode, glfd->fd, xattr_req, &iatt); + DECODE_SYNCOP_ERR (ret); /* populate out args */ if (ret == 0) { @@ -518,6 +522,7 @@ glfs_h_mkdir (struct glfs *fs, struct glfs_object *parent, const char *path, /* fop/op */ ret = syncop_mkdir (subvol, &loc, mode, xattr_req, &iatt); + DECODE_SYNCOP_ERR (ret); /* populate out args */ if ( ret == 0 ) { @@ -606,6 +611,7 @@ glfs_h_mknod (struct glfs *fs, struct glfs_object *parent, const char *path, /* fop/op */ ret = syncop_mknod (subvol, &loc, mode, dev, xattr_req, &iatt); + DECODE_SYNCOP_ERR (ret); /* populate out args */ if (ret == 0) { @@ -676,11 +682,13 @@ glfs_h_unlink (struct glfs *fs, struct glfs_object *parent, const char *path) if (!IA_ISDIR(loc.inode->ia_type)) { ret = syncop_unlink (subvol, &loc); + DECODE_SYNCOP_ERR (ret); if (ret != 0) { goto out; } } else { ret = syncop_rmdir (subvol, &loc, 0); + DECODE_SYNCOP_ERR (ret); if (ret != 0) { goto out; } @@ -755,6 +763,7 @@ glfs_h_opendir (struct glfs *fs, struct glfs_object *object) /* fop/op */ ret = syncop_opendir (subvol, &loc, glfd->fd); + DECODE_SYNCOP_ERR (ret); out: loc_wipe (&loc); @@ -846,6 +855,7 @@ glfs_h_create_from_handle (struct glfs *fs, unsigned char *handle, int len, } ret = syncop_lookup (subvol, &loc, 0, &iatt, 0, 0); + DECODE_SYNCOP_ERR (ret); if (ret) { gf_log (subvol->name, GF_LOG_WARNING, "inode refresh of %s failed: %s", @@ -934,6 +944,7 @@ glfs_h_truncate (struct glfs *fs, struct glfs_object *object, off_t offset) /* fop/op */ ret = syncop_truncate (subvol, &loc, (off_t)offset); + DECODE_SYNCOP_ERR (ret); /* populate out args */ if (ret == 0) @@ -1006,6 +1017,7 @@ glfs_h_symlink (struct glfs *fs, struct glfs_object *parent, const char *name, /* fop/op */ ret = syncop_symlink (subvol, &loc, data, xattr_req, &iatt); + DECODE_SYNCOP_ERR (ret); /* populate out args */ if (ret == 0) { @@ -1081,6 +1093,7 @@ glfs_h_readlink (struct glfs *fs, struct glfs_object *object, char *buf, /* fop/op */ ret = syncop_readlink (subvol, &loc, &linkval, bufsiz); + DECODE_SYNCOP_ERR (ret); /* populate out args */ if (ret > 0) @@ -1166,6 +1179,7 @@ glfs_h_link (struct glfs *fs, struct glfs_object *linksrc, /* fop/op */ ret = syncop_link (subvol, &oldloc, &newloc); + DECODE_SYNCOP_ERR (ret); if (ret == 0) /* TODO: No iatt to pass as there has been no lookup */ @@ -1256,6 +1270,7 @@ glfs_h_rename (struct glfs *fs, struct glfs_object *olddir, const char *oldname, /* TODO: check if new or old is a prefix of the other, and fail EINVAL */ ret = syncop_rename (subvol, &oldloc, &newloc); + DECODE_SYNCOP_ERR (ret); if (ret == 0) inode_rename (oldloc.parent->table, oldloc.parent, oldloc.name, diff --git a/api/src/glfs-internal.h b/api/src/glfs-internal.h index ec1d5579d..f04557323 100644 --- a/api/src/glfs-internal.h +++ b/api/src/glfs-internal.h @@ -18,6 +18,26 @@ #define DEFAULT_REVAL_COUNT 1 +/* + * syncop_xxx() calls are executed in two ways, one is inside a synctask where + * the executing function will do 'swapcontext' and the other is without + * synctask where the executing thread is made to wait using pthread_cond_wait. + * Executing thread may change when syncop_xxx() is executed inside a synctask. + * This leads to errno_location change i.e. errno may give errno of + * non-executing thread. So errno is not touched inside a synctask execution. + * All gfapi calls are executed using the second way of executing syncop_xxx() + * where the executing thread waits using pthread_cond_wait so it is ok to set + * errno in these cases. The following macro makes syncop_xxx() behave just + * like a system call, where -1 is returned and errno is set when a failure + * occurs. + */ +#define DECODE_SYNCOP_ERR(ret) do { \ + if (ret < 0) { \ + errno = -ret; \ + ret = -1; \ + } \ + } while (0) + #define ESTALE_RETRY(ret,errno,reval,loc,label) do { \ if (ret == -1 && errno == ESTALE) { \ if (reval < DEFAULT_REVAL_COUNT) { \ diff --git a/api/src/glfs-resolve.c b/api/src/glfs-resolve.c index 4ca2eb6fc..c88330aa4 100644 --- a/api/src/glfs-resolve.c +++ b/api/src/glfs-resolve.c @@ -48,6 +48,7 @@ glfs_first_lookup_safe (xlator_t *subvol) loc.name = ""; ret = syncop_lookup (subvol, &loc, 0, 0, 0, 0); + DECODE_SYNCOP_ERR (ret); gf_log (subvol->name, GF_LOG_DEBUG, "first lookup complete %d", ret); @@ -98,6 +99,7 @@ glfs_refresh_inode_safe (xlator_t *subvol, inode_t *oldinode) return NULL; ret = syncop_lookup (subvol, &loc, 0, &iatt, 0, 0); + DECODE_SYNCOP_ERR (ret); if (ret) { gf_log (subvol->name, GF_LOG_WARNING, @@ -181,6 +183,7 @@ glfs_resolve_symlink (struct glfs *fs, xlator_t *subvol, inode_t *inode, loc.path = rpath; ret = syncop_readlink (subvol, &loc, &path, 4096); + DECODE_SYNCOP_ERR (ret); if (ret < 0) goto out; @@ -210,6 +213,7 @@ glfs_resolve_base (struct glfs *fs, xlator_t *subvol, inode_t *inode, goto out; ret = syncop_lookup (subvol, &loc, NULL, iatt, NULL, NULL); + DECODE_SYNCOP_ERR (ret); out: loc_wipe (&loc); @@ -268,6 +272,7 @@ glfs_resolve_component (struct glfs *fs, xlator_t *subvol, inode_t *parent, } ret = syncop_lookup (subvol, &loc, NULL, &ciatt, NULL, NULL); + DECODE_SYNCOP_ERR (ret); if (ret && reval) { inode_unref (loc.inode); loc.inode = inode_new (parent->table); @@ -292,6 +297,7 @@ glfs_resolve_component (struct glfs *fs, xlator_t *subvol, inode_t *parent, ret = syncop_lookup (subvol, &loc, xattr_req, &ciatt, NULL, NULL); + DECODE_SYNCOP_ERR (ret); } if (ret) goto out; @@ -515,6 +521,7 @@ glfs_migrate_fd_locks_safe (struct glfs *fs, xlator_t *oldsubvol, fd_t *oldfd, ret = syncop_fgetxattr (oldsubvol, oldfd, &lockinfo, GF_XATTR_LOCKINFO_KEY); + DECODE_SYNCOP_ERR (ret); if (ret < 0) { gf_log (fs->volname, GF_LOG_WARNING, "fgetxattr (%s) failed (%s) on graph %s (%d)", @@ -533,6 +540,7 @@ glfs_migrate_fd_locks_safe (struct glfs *fs, xlator_t *oldsubvol, fd_t *oldfd, } ret = syncop_fsetxattr (newsubvol, newfd, lockinfo, 0); + DECODE_SYNCOP_ERR (ret); if (ret < 0) { gf_log (fs->volname, GF_LOG_WARNING, "fsetxattr (%s) failed (%s) on graph %s (%d)", @@ -568,6 +576,7 @@ glfs_migrate_fd_safe (struct glfs *fs, xlator_t *newsubvol, fd_t *oldfd) if (!oldsubvol->switched) { ret = syncop_fsync (oldsubvol, oldfd, 0); + DECODE_SYNCOP_ERR (ret); if (ret) { gf_log (fs->volname, GF_LOG_WARNING, "fsync() failed (%s) on %s graph %s (%d)", @@ -614,6 +623,7 @@ glfs_migrate_fd_safe (struct glfs *fs, xlator_t *newsubvol, fd_t *oldfd) ret = syncop_open (newsubvol, &loc, oldfd->flags & ~(O_TRUNC|O_EXCL|O_CREAT), newfd); + DECODE_SYNCOP_ERR (ret); loc_wipe (&loc); if (ret) { diff --git a/libglusterfs/src/syncop.c b/libglusterfs/src/syncop.c index 1f36e5776..efcd9c5f3 100644 --- a/libglusterfs/src/syncop.c +++ b/libglusterfs/src/syncop.c @@ -983,7 +983,8 @@ syncop_lookup (xlator_t *subvol, loc_t *loc, dict_t *xdata_req, else if (args.xdata) dict_unref (args.xdata); - errno = args.op_errno; + if (args.op_ret < 0) + return -args.op_errno; return args.op_ret; } @@ -1059,7 +1060,8 @@ syncop_readdirp (xlator_t *subvol, list_splice_init (&args.entries.list, &entries->list); /* TODO: need to free all the 'args.entries' in 'else' case */ - errno = args.op_errno; + if (args.op_ret < 0) + return -args.op_errno; return args.op_ret; } @@ -1118,7 +1120,8 @@ syncop_readdir (xlator_t *subvol, list_splice_init (&args.entries.list, &entries->list); /* TODO: need to free all the 'args.entries' in 'else' case */ - errno = args.op_errno; + if (args.op_ret < 0) + return -args.op_errno; return args.op_ret; } @@ -1153,7 +1156,8 @@ syncop_opendir (xlator_t *subvol, SYNCOP (subvol, (&args), syncop_opendir_cbk, subvol->fops->opendir, loc, fd, NULL); - errno = args.op_errno; + if (args.op_ret < 0) + return -args.op_errno; return args.op_ret; } @@ -1182,7 +1186,8 @@ syncop_fsyncdir (xlator_t *subvol, fd_t *fd, int datasync) SYNCOP (subvol, (&args), syncop_fsyncdir_cbk, subvol->fops->fsyncdir, fd, datasync, NULL); - errno = args.op_errno; + if (args.op_ret < 0) + return -args.op_errno; return args.op_ret; } @@ -1210,7 +1215,8 @@ syncop_removexattr (xlator_t *subvol, loc_t *loc, const char *name) SYNCOP (subvol, (&args), syncop_removexattr_cbk, subvol->fops->removexattr, loc, name, NULL); - errno = args.op_errno; + if (args.op_ret < 0) + return -args.op_errno; return args.op_ret; } @@ -1238,7 +1244,8 @@ syncop_fremovexattr (xlator_t *subvol, fd_t *fd, const char *name) SYNCOP (subvol, (&args), syncop_fremovexattr_cbk, subvol->fops->fremovexattr, fd, name, NULL); - errno = args.op_errno; + if (args.op_ret < 0) + return -args.op_errno; return args.op_ret; } @@ -1267,7 +1274,8 @@ syncop_setxattr (xlator_t *subvol, loc_t *loc, dict_t *dict, int32_t flags) SYNCOP (subvol, (&args), syncop_setxattr_cbk, subvol->fops->setxattr, loc, dict, flags, NULL); - errno = args.op_errno; + if (args.op_ret < 0) + return -args.op_errno; return args.op_ret; } @@ -1296,7 +1304,8 @@ syncop_fsetxattr (xlator_t *subvol, fd_t *fd, dict_t *dict, int32_t flags) SYNCOP (subvol, (&args), syncop_fsetxattr_cbk, subvol->fops->fsetxattr, fd, dict, flags, NULL); - errno = args.op_errno; + if (args.op_ret < 0) + return -args.op_errno; return args.op_ret; } @@ -1331,7 +1340,8 @@ syncop_listxattr (xlator_t *subvol, loc_t *loc, dict_t **dict) else if (args.xattr) dict_unref (args.xattr); - errno = args.op_errno; + if (args.op_ret < 0) + return -args.op_errno; return args.op_ret; } @@ -1348,7 +1358,8 @@ syncop_getxattr (xlator_t *subvol, loc_t *loc, dict_t **dict, const char *key) else if (args.xattr) dict_unref (args.xattr); - errno = args.op_errno; + if (args.op_ret < 0) + return -args.op_errno; return args.op_ret; } @@ -1365,7 +1376,8 @@ syncop_fgetxattr (xlator_t *subvol, fd_t *fd, dict_t **dict, const char *key) else if (args.xattr) dict_unref (args.xattr); - errno = args.op_errno; + if (args.op_ret < 0) + return -args.op_errno; return args.op_ret; } @@ -1404,7 +1416,8 @@ syncop_statfs (xlator_t *subvol, loc_t *loc, struct statvfs *buf) if (buf) *buf = args.statvfs_buf; - errno = args.op_errno; + if (args.op_ret < 0) + return -args.op_errno; return args.op_ret; } @@ -1445,7 +1458,8 @@ syncop_setattr (xlator_t *subvol, loc_t *loc, struct iatt *iatt, int valid, if (postop) *postop = args.iatt2; - errno = args.op_errno; + if (args.op_ret < 0) + return -args.op_errno; return args.op_ret; } @@ -1464,7 +1478,8 @@ syncop_fsetattr (xlator_t *subvol, fd_t *fd, struct iatt *iatt, int valid, if (postop) *postop = args.iatt2; - errno = args.op_errno; + if (args.op_ret < 0) + return -args.op_errno; return args.op_ret; } @@ -1493,7 +1508,8 @@ syncop_open (xlator_t *subvol, loc_t *loc, int32_t flags, fd_t *fd) SYNCOP (subvol, (&args), syncop_open_cbk, subvol->fops->open, loc, flags, fd, NULL); - errno = args.op_errno; + if (args.op_ret < 0) + return -args.op_errno; return args.op_ret; } @@ -1555,7 +1571,8 @@ syncop_readv (xlator_t *subvol, fd_t *fd, size_t size, off_t off, iobref_unref (args.iobref); out: - errno = args.op_errno; + if (args.op_ret < 0) + return -args.op_errno; return args.op_ret; } @@ -1588,7 +1605,8 @@ syncop_writev (xlator_t *subvol, fd_t *fd, const struct iovec *vector, fd, (struct iovec *) vector, count, offset, flags, iobref, NULL); - errno = args.op_errno; + if (args.op_ret < 0) + return -args.op_errno; return args.op_ret; } @@ -1604,7 +1622,8 @@ int syncop_write (xlator_t *subvol, fd_t *fd, const char *buf, int size, SYNCOP (subvol, (&args), syncop_writev_cbk, subvol->fops->writev, fd, &vec, 1, offset, flags, iobref, NULL); - errno = args.op_errno; + if (args.op_ret < 0) + return -args.op_errno; return args.op_ret; } @@ -1647,10 +1666,11 @@ syncop_create (xlator_t *subvol, loc_t *loc, int32_t flags, mode_t mode, SYNCOP (subvol, (&args), syncop_create_cbk, subvol->fops->create, loc, flags, mode, 0, fd, xdata); - errno = args.op_errno; if (iatt) *iatt = args.iatt1; + if (args.op_ret < 0) + return -args.op_errno; return args.op_ret; } @@ -1680,7 +1700,8 @@ syncop_unlink (xlator_t *subvol, loc_t *loc) SYNCOP (subvol, (&args), syncop_unlink_cbk, subvol->fops->unlink, loc, 0, NULL); - errno = args.op_errno; + if (args.op_ret < 0) + return -args.op_errno; return args.op_ret; } @@ -1709,7 +1730,8 @@ syncop_rmdir (xlator_t *subvol, loc_t *loc, int flags) SYNCOP (subvol, (&args), syncop_rmdir_cbk, subvol->fops->rmdir, loc, flags, NULL); - errno = args.op_errno; + if (args.op_ret < 0) + return -args.op_errno; return args.op_ret; } @@ -1741,7 +1763,8 @@ syncop_link (xlator_t *subvol, loc_t *oldloc, loc_t *newloc) SYNCOP (subvol, (&args), syncop_link_cbk, subvol->fops->link, oldloc, newloc, NULL); - errno = args.op_errno; + if (args.op_ret < 0) + return -args.op_errno; return args.op_ret; } @@ -1775,7 +1798,8 @@ syncop_rename (xlator_t *subvol, loc_t *oldloc, loc_t *newloc) SYNCOP (subvol, (&args), syncop_rename_cbk, subvol->fops->rename, oldloc, newloc, NULL); - errno = args.op_errno; + if (args.op_ret < 0) + return -args.op_errno; return args.op_ret; } @@ -1806,7 +1830,8 @@ syncop_ftruncate (xlator_t *subvol, fd_t *fd, off_t offset) SYNCOP (subvol, (&args), syncop_ftruncate_cbk, subvol->fops->ftruncate, fd, offset, NULL); - errno = args.op_errno; + if (args.op_ret < 0) + return -args.op_errno; return args.op_ret; } @@ -1818,7 +1843,8 @@ syncop_truncate (xlator_t *subvol, loc_t *loc, off_t offset) SYNCOP (subvol, (&args), syncop_ftruncate_cbk, subvol->fops->truncate, loc, offset, NULL); - errno = args.op_errno; + if (args.op_ret < 0) + return -args.op_errno; return args.op_ret; } @@ -1848,7 +1874,8 @@ syncop_fsync (xlator_t *subvol, fd_t *fd, int dataonly) SYNCOP (subvol, (&args), syncop_fsync_cbk, subvol->fops->fsync, fd, dataonly, NULL); - errno = args.op_errno; + if (args.op_ret < 0) + return -args.op_errno; return args.op_ret; } @@ -1879,7 +1906,8 @@ syncop_flush (xlator_t *subvol, fd_t *fd) SYNCOP (subvol, (&args), syncop_flush_cbk, subvol->fops->flush, fd, NULL); - errno = args.op_errno; + if (args.op_ret < 0) + return -args.op_errno; return args.op_ret; } @@ -1914,7 +1942,8 @@ syncop_fstat (xlator_t *subvol, fd_t *fd, struct iatt *stbuf) if (stbuf) *stbuf = args.iatt1; - errno = args.op_errno; + if (args.op_ret < 0) + return -args.op_errno; return args.op_ret; } @@ -1930,7 +1959,8 @@ syncop_stat (xlator_t *subvol, loc_t *loc, struct iatt *stbuf) if (stbuf) *stbuf = args.iatt1; - errno = args.op_errno; + if (args.op_ret < 0) + return -args.op_errno; return args.op_ret; } @@ -1964,10 +1994,11 @@ syncop_symlink (xlator_t *subvol, loc_t *loc, const char *newpath, dict_t *dict, SYNCOP (subvol, (&args), syncop_symlink_cbk, subvol->fops->symlink, newpath, loc, 0, dict); - errno = args.op_errno; if (iatt) *iatt = args.iatt1; + if (args.op_ret < 0) + return -args.op_errno; return args.op_ret; } @@ -2004,7 +2035,8 @@ syncop_readlink (xlator_t *subvol, loc_t *loc, char **buffer, size_t size) *buffer = args.buffer; else GF_FREE (args.buffer); - errno = args.op_errno; + if (args.op_ret < 0) + return -args.op_errno; return args.op_ret; } @@ -2038,10 +2070,11 @@ syncop_mknod (xlator_t *subvol, loc_t *loc, mode_t mode, dev_t rdev, SYNCOP (subvol, (&args), syncop_mknod_cbk, subvol->fops->mknod, loc, mode, rdev, 0, dict); - errno = args.op_errno; if (iatt) *iatt = args.iatt1; + if (args.op_ret < 0) + return -args.op_errno; return args.op_ret; } @@ -2077,10 +2110,11 @@ syncop_mkdir (xlator_t *subvol, loc_t *loc, mode_t mode, dict_t *dict, SYNCOP (subvol, (&args), syncop_mkdir_cbk, subvol->fops->mkdir, loc, mode, 0, dict); - errno = args.op_errno; if (iatt) *iatt = args.iatt1; + if (args.op_ret < 0) + return -args.op_errno; return args.op_ret; } @@ -2108,7 +2142,8 @@ syncop_access (xlator_t *subvol, loc_t *loc, int32_t mask) SYNCOP (subvol, (&args), syncop_access_cbk, subvol->fops->access, loc, mask, NULL); - errno = args.op_errno; + if (args.op_ret < 0) + return -args.op_errno; return args.op_ret; } @@ -2139,7 +2174,8 @@ syncop_fallocate(xlator_t *subvol, fd_t *fd, int32_t keep_size, off_t offset, SYNCOP (subvol, (&args), syncop_fallocate_cbk, subvol->fops->fallocate, fd, keep_size, offset, len, NULL); - errno = args.op_errno; + if (args.op_ret < 0) + return -args.op_errno; return args.op_ret; } @@ -2169,7 +2205,8 @@ syncop_discard(xlator_t *subvol, fd_t *fd, off_t offset, size_t len) SYNCOP (subvol, (&args), syncop_discard_cbk, subvol->fops->discard, fd, offset, len, NULL); - errno = args.op_errno; + if (args.op_ret < 0) + return -args.op_errno; return args.op_ret; } @@ -2198,7 +2235,8 @@ syncop_zerofill(xlator_t *subvol, fd_t *fd, off_t offset, off_t len) SYNCOP (subvol, (&args), syncop_zerofill_cbk, subvol->fops->zerofill, fd, offset, len, NULL); - errno = args.op_errno; + if (args.op_ret < 0) + return -args.op_errno; return args.op_ret; } @@ -2230,8 +2268,9 @@ syncop_lk (xlator_t *subvol, fd_t *fd, int cmd, struct gf_flock *flock) SYNCOP (subvol, (&args), syncop_lk_cbk, subvol->fops->lk, fd, cmd, flock, NULL); - errno = args.op_errno; *flock = args.flock; + if (args.op_ret < 0) + return -args.op_errno; return args.op_ret; } diff --git a/xlators/cluster/afr/src/afr-self-heald.c b/xlators/cluster/afr/src/afr-self-heald.c index 5f85c3047..9e5c1b3e7 100644 --- a/xlators/cluster/afr/src/afr-self-heald.c +++ b/xlators/cluster/afr/src/afr-self-heald.c @@ -336,8 +336,9 @@ _get_path_from_gfid_loc (xlator_t *this, xlator_t *readdir_xl, loc_t *child, ret = syncop_getxattr (readdir_xl, child, &xattr, GFID_TO_PATH_KEY); if (ret < 0) { - if ((errno == ENOENT || errno == ESTALE) && missing) + if ((-ret == ENOENT || -ret == ESTALE) && missing) *missing = _gf_true; + ret = -1; goto out; } ret = dict_get_str (xattr, GFID_TO_PATH_KEY, &path); @@ -437,10 +438,10 @@ _remove_stale_index (xlator_t *this, xlator_t *readdir_xl, gf_log (this->name, GF_LOG_DEBUG, "Removing stale index " "for %s on %s", index_loc.name, readdir_xl->name); ret = syncop_unlink (readdir_xl, &index_loc); - if(ret && (errno != ENOENT)) { + if((ret < 0) && (-ret != ENOENT)) { gf_log(this->name, GF_LOG_ERROR, "%s: Failed to remove index " "on %s - %s",index_loc.name, readdir_xl->name, - strerror (errno)); + strerror (-ret)); } index_loc.path = NULL; loc_wipe (&index_loc); @@ -467,8 +468,10 @@ _count_hard_links_under_base_indices_dir (xlator_t *this, child = crawl_data->child; ret = syncop_lookup (readdir_xl, childloc, NULL, iattr, NULL, &parent); - if (ret) + if (ret) { + ret = -1; goto out; + } ret = dict_get_int32 (output, this->name, &xl_id); if (ret) @@ -648,8 +651,10 @@ _self_heal_entry (xlator_t *this, afr_crawl_data_t *crawl_data, gf_dirent_t *ent ret = syncop_lookup (this, child, xattr_req, iattr, &xattr_rsp, &parentbuf); - _crawl_post_sh_action (this, parent, child, ret, errno, xattr_rsp, + _crawl_post_sh_action (this, parent, child, ret, -ret, xattr_rsp, crawl_data); + if (ret < 0) + ret = -1; if (xattr_rsp) dict_unref (xattr_rsp); if (ret == 0) @@ -1190,8 +1195,10 @@ afr_crawl_build_start_loc (xlator_t *this, afr_crawl_data_t *crawl_data, afr_build_root_loc (this, &rootloc); ret = syncop_getxattr (readdir_xl, &rootloc, &xattr, GF_XATTROP_INDEX_GFID); - if (ret < 0) + if (ret < 0) { + ret = -1; goto out; + } ret = dict_get_ptr (xattr, GF_XATTROP_INDEX_GFID, &index_gfid); if (ret < 0) { gf_log (this->name, GF_LOG_ERROR, "failed to get index " @@ -1210,11 +1217,12 @@ afr_crawl_build_start_loc (xlator_t *this, afr_crawl_data_t *crawl_data, ret = syncop_lookup (readdir_xl, dirloc, NULL, &iattr, NULL, &parent); if (ret < 0) { - if (errno != ENOENT) { + if (-ret != ENOENT) { gf_log (this->name, GF_LOG_ERROR, "lookup " "failed on index dir on %s - (%s)", - readdir_xl->name, strerror (errno)); + readdir_xl->name, strerror (-ret)); } + ret = -1; goto out; } ret = _link_inode_update_loc (this, dirloc, &iattr); @@ -1224,8 +1232,10 @@ afr_crawl_build_start_loc (xlator_t *this, afr_crawl_data_t *crawl_data, afr_build_root_loc (this, &rootloc); ret = syncop_getxattr (readdir_xl, &rootloc, &xattr, GF_BASE_INDICES_HOLDER_GFID); - if (ret < 0) + if (ret < 0) { + ret = -1; goto out; + } ret = dict_get_ptr (xattr, GF_BASE_INDICES_HOLDER_GFID, &base_indices_holder_vgfid); if (ret < 0) { @@ -1246,16 +1256,17 @@ afr_crawl_build_start_loc (xlator_t *this, afr_crawl_data_t *crawl_data, ret = syncop_lookup (readdir_xl, dirloc, NULL, &iattr, NULL, &parent); if (ret < 0) { - if (errno != ENOENT) { + if (-ret != ENOENT) { gf_log (this->name, GF_LOG_ERROR, "lookup " "failed for base_indices_holder dir" " on %s - (%s)", readdir_xl->name, - strerror (errno)); + strerror (-ret)); } else { gf_log (this->name, GF_LOG_ERROR, "base_indices" "_holder is not yet created."); } + ret = -1; goto out; } ret = _link_inode_update_loc (this, dirloc, &iattr); @@ -1290,6 +1301,7 @@ afr_crawl_opendir (xlator_t *this, afr_crawl_data_t *crawl_data, fd_t **dirfd, if (ret < 0) { gf_log (this->name, GF_LOG_ERROR, "opendir failed on %s", dirloc->path); + ret = -1; goto out; } } else { @@ -1442,8 +1454,13 @@ _crawl_directory (fd_t *fd, loc_t *loc, afr_crawl_data_t *crawl_data) else ret = syncop_readdir (readdir_xl, fd, 131072, offset, &entries); - if (ret <= 0) + if (ret < 0) { + ret = -1; + break; + } else if (ret == 0) { break; + } + ret = 0; free_entries = _gf_true; @@ -1503,7 +1520,8 @@ afr_find_child_position (xlator_t *this, int child, afr_child_pos_t *pos) GF_XATTR_NODE_UUID_KEY); if (ret < 0) { gf_log (this->name, GF_LOG_ERROR, "getxattr failed on %s - " - "(%s)", priv->children[child]->name, strerror (errno)); + "(%s)", priv->children[child]->name, strerror (-ret)); + ret = -1; goto out; } diff --git a/xlators/cluster/afr/src/pump.c b/xlators/cluster/afr/src/pump.c index a7f72fb30..9027e2a33 100644 --- a/xlators/cluster/afr/src/pump.c +++ b/xlators/cluster/afr/src/pump.c @@ -504,9 +504,10 @@ pump_xattr_cleaner (call_frame_t *frame, void *cookie, xlator_t *this, for (i = 0; i < priv->child_count; i++) { ret = syncop_removexattr (priv->children[i], &loc, PUMP_SOURCE_COMPLETE); - if (ret) + if (ret) { gf_log (this->name, GF_LOG_DEBUG, "removexattr " - "failed with %s", strerror (errno)); + "failed with %s", strerror (-ret)); + } } loc_wipe (&loc); @@ -598,6 +599,7 @@ pump_lookup_sink (loc_t *loc) if (ret) { gf_log (this->name, GF_LOG_DEBUG, "Lookup on sink child failed"); + ret = -1; goto out; } diff --git a/xlators/cluster/dht/src/dht-helper.c b/xlators/cluster/dht/src/dht-helper.c index 00a98f1cf..76bfbaedb 100644 --- a/xlators/cluster/dht/src/dht-helper.c +++ b/xlators/cluster/dht/src/dht-helper.c @@ -769,17 +769,20 @@ dht_migration_complete_check_task (void *data) dst_node = dht_linkfile_subvol (this, NULL, NULL, dict); if (ret) { - if (!dht_inode_missing(errno) || (!local->loc.inode)) { + if (!dht_inode_missing(-ret) || (!local->loc.inode)) { gf_log (this->name, GF_LOG_ERROR, "%s: failed to get the 'linkto' xattr %s", - local->loc.path, strerror (errno)); + local->loc.path, strerror (-ret)); + ret = -1; goto out; } /* Need to do lookup on hashed subvol, then get the file */ ret = syncop_lookup (this, &local->loc, NULL, &stbuf, NULL, NULL); - if (ret) + if (ret) { + ret = -1; goto out; + } dst_node = dht_subvol_get_cached (this, local->loc.inode); } @@ -799,6 +802,7 @@ dht_migration_complete_check_task (void *data) gf_log (this->name, GF_LOG_ERROR, "%s: failed to lookup the file on %s", local->loc.path, dst_node->name); + ret = -1; goto out; } @@ -869,10 +873,11 @@ dht_migration_complete_check_task (void *data) ret = syncop_open (dst_node, &tmp_loc, iter_fd->flags, iter_fd); - if (ret == -1) { + if (ret < 0) { gf_log (this->name, GF_LOG_ERROR, "failed to open " "the fd (%p, flags=0%o) on file %s @ %s", iter_fd, iter_fd->flags, path, dst_node->name); + ret = -1; open_failed = 1; } } @@ -955,11 +960,12 @@ dht_rebalance_inprogress_task (void *data) conf->link_xattr_name); } - if (ret) { + if (ret < 0) { gf_log (this->name, GF_LOG_ERROR, "%s: failed to get the 'linkto' xattr %s", - local->loc.path, strerror (errno)); - goto out; + local->loc.path, strerror (-ret)); + ret = -1; + goto out; } dst_node = dht_linkfile_subvol (this, NULL, NULL, dict); @@ -981,6 +987,7 @@ dht_rebalance_inprogress_task (void *data) gf_log (this->name, GF_LOG_ERROR, "%s: failed to lookup the file on %s", local->loc.path, dst_node->name); + ret = -1; goto out; } @@ -1014,10 +1021,11 @@ dht_rebalance_inprogress_task (void *data) ret = syncop_open (dst_node, &tmp_loc, iter_fd->flags, iter_fd); - if (ret == -1) { + if (ret < 0) { gf_log (this->name, GF_LOG_ERROR, "failed to send open " "the fd (%p, flags=0%o) on file %s @ %s", iter_fd, iter_fd->flags, path, dst_node->name); + ret = -1; open_failed = 1; } } diff --git a/xlators/cluster/dht/src/dht-rebalance.c b/xlators/cluster/dht/src/dht-rebalance.c index 9446dbe03..a5a4585f1 100644 --- a/xlators/cluster/dht/src/dht-rebalance.c +++ b/xlators/cluster/dht/src/dht-rebalance.c @@ -58,7 +58,8 @@ dht_write_with_holes (xlator_t *to, fd_t *fd, struct iovec *vec, int count, if (ret < 0) { gf_log (THIS->name, GF_LOG_WARNING, "failed to write (%s)", - strerror (errno)); + strerror (-ret)); + ret = -1; goto out; } @@ -76,7 +77,8 @@ dht_write_with_holes (xlator_t *to, fd_t *fd, struct iovec *vec, int count, /* 'path' will be logged in calling function */ gf_log (THIS->name, GF_LOG_WARNING, "failed to write (%s)", - strerror (errno)); + strerror (-ret)); + ret = -1; goto out; } } @@ -158,7 +160,8 @@ gf_defrag_handle_hardlink (xlator_t *this, loc_t *loc, dict_t *xattrs, if (ret) { gf_log (this->name, GF_LOG_ERROR, "Linkto setxattr " "failed %s -> %s (%s)", cached_subvol->name, - loc->name, strerror (errno)); + loc->name, strerror (-ret)); + ret = -1; goto out; } goto out; @@ -173,7 +176,8 @@ gf_defrag_handle_hardlink (xlator_t *this, loc_t *loc, dict_t *xattrs, ret = syncop_link (hashed_subvol, loc, loc); if (ret) { - op_errno = errno; + op_errno = -ret; + ret = -1; gf_log (this->name, GF_LOG_ERROR, "link of %s -> %s" " failed on subvol %s (%s)", loc->name, uuid_utoa(loc->gfid), @@ -185,7 +189,8 @@ gf_defrag_handle_hardlink (xlator_t *this, loc_t *loc, dict_t *xattrs, ret = syncop_lookup (hashed_subvol, loc, NULL, &iatt, NULL, NULL); if (ret) { gf_log (this->name, GF_LOG_ERROR, "Failed lookup %s on %s (%s)" - , loc->name, hashed_subvol->name, strerror (errno)); + , loc->name, hashed_subvol->name, strerror (-ret)); + ret = -1; goto out; } @@ -289,11 +294,12 @@ __dht_rebalance_create_dst_file (xlator_t *to, xlator_t *from, loc_t *loc, struc goto out; } } - if ((ret == -1) && (errno != ENOENT)) { + if ((ret < 0) && (-ret != ENOENT)) { /* File exists in destination, but not accessible */ gf_log (THIS->name, GF_LOG_WARNING, "%s: failed to lookup file (%s)", - loc->path, strerror (errno)); + loc->path, strerror (-ret)); + ret = -1; goto out; } @@ -304,21 +310,22 @@ __dht_rebalance_create_dst_file (xlator_t *to, xlator_t *from, loc_t *loc, struc if (ret < 0) { gf_log (this->name, GF_LOG_ERROR, "failed to create %s on %s (%s)", - loc->path, to->name, strerror (errno)); + loc->path, to->name, strerror (-ret)); + ret = -1; goto out; } ret = syncop_fsetxattr (to, fd, xattr, 0); - if (ret == -1) + if (ret < 0) gf_log (this->name, GF_LOG_WARNING, "%s: failed to set xattr on %s (%s)", - loc->path, to->name, strerror (errno)); + loc->path, to->name, strerror (-ret)); ret = syncop_ftruncate (to, fd, stbuf->ia_size); if (ret < 0) gf_log (this->name, GF_LOG_ERROR, "ftruncate failed for %s on %s (%s)", - loc->path, to->name, strerror (errno)); + loc->path, to->name, strerror (-ret)); ret = syncop_fsetattr (to, fd, stbuf, (GF_SET_ATTR_UID | GF_SET_ATTR_GID), @@ -326,7 +333,7 @@ __dht_rebalance_create_dst_file (xlator_t *to, xlator_t *from, loc_t *loc, struc if (ret < 0) gf_log (this->name, GF_LOG_ERROR, "chown failed for %s on %s (%s)", - loc->path, to->name, strerror (errno)); + loc->path, to->name, strerror (-ret)); if (dst_fd) *dst_fd = fd; @@ -356,7 +363,8 @@ __dht_check_free_space (xlator_t *to, xlator_t *from, loc_t *loc, if (ret) { gf_log (this->name, GF_LOG_ERROR, "failed to get statfs of %s on %s (%s)", - loc->path, from->name, strerror (errno)); + loc->path, from->name, strerror (-ret)); + ret = -1; goto out; } @@ -364,7 +372,8 @@ __dht_check_free_space (xlator_t *to, xlator_t *from, loc_t *loc, if (ret) { gf_log (this->name, GF_LOG_ERROR, "failed to get statfs of %s on %s (%s)", - loc->path, to->name, strerror (errno)); + loc->path, to->name, strerror (-ret)); + ret = -1; goto out; } @@ -463,6 +472,8 @@ __dht_rebalance_migrate_data (xlator_t *from, xlator_t *to, fd_t *src, fd_t *dst if (ret >= 0) ret = 0; + else + ret = -1; return ret; } @@ -491,10 +502,11 @@ __dht_rebalance_open_src_file (xlator_t *from, xlator_t *to, loc_t *loc, } ret = syncop_open (from, loc, O_RDWR, fd); - if (ret == -1) { + if (ret < 0) { gf_log (this->name, GF_LOG_ERROR, "failed to open file %s on %s (%s)", - loc->path, from->name, strerror (errno)); + loc->path, from->name, strerror (-ret)); + ret = -1; goto out; } @@ -517,7 +529,8 @@ __dht_rebalance_open_src_file (xlator_t *from, xlator_t *to, loc_t *loc, if (ret) { gf_log (this->name, GF_LOG_ERROR, "failed to set xattr on %s in %s (%s)", - loc->path, from->name, strerror (errno)); + loc->path, from->name, strerror (-ret)); + ret = -1; goto out; } @@ -531,7 +544,8 @@ __dht_rebalance_open_src_file (xlator_t *from, xlator_t *to, loc_t *loc, if (ret) { gf_log (this->name, GF_LOG_ERROR, "failed to set mode on %s in %s (%s)", - loc->path, from->name, strerror (errno)); + loc->path, from->name, strerror (-ret)); + ret = -1; goto out; } @@ -571,9 +585,10 @@ migrate_special_files (xlator_t *this, xlator_t *from, xlator_t *to, loc_t *loc, /* check in the destination if the file is link file */ ret = syncop_lookup (to, loc, dict, &stbuf, &rsp_dict, NULL); - if ((ret == -1) && (errno != ENOENT)) { + if ((ret < 0) && (-ret != ENOENT)) { gf_log (this->name, GF_LOG_WARNING, "%s: lookup failed (%s)", - loc->path, strerror (errno)); + loc->path, strerror (-ret)); + ret = -1; goto out; } @@ -596,7 +611,8 @@ migrate_special_files (xlator_t *this, xlator_t *from, xlator_t *to, loc_t *loc, if (ret) { gf_log (this->name, GF_LOG_WARNING, "%s: failed to delete the linkfile (%s)", - loc->path, strerror (errno)); + loc->path, strerror (-ret)); + ret = -1; goto out; } } @@ -616,7 +632,8 @@ migrate_special_files (xlator_t *this, xlator_t *from, xlator_t *to, loc_t *loc, if (ret < 0) { gf_log (this->name, GF_LOG_WARNING, "%s: readlink on symlink failed (%s)", - loc->path, strerror (errno)); + loc->path, strerror (-ret)); + ret = -1; goto out; } @@ -624,7 +641,8 @@ migrate_special_files (xlator_t *this, xlator_t *from, xlator_t *to, loc_t *loc, if (ret) { gf_log (this->name, GF_LOG_WARNING, "%s: creating symlink failed (%s)", - loc->path, strerror (errno)); + loc->path, strerror (-ret)); + ret = -1; goto out; } @@ -637,7 +655,8 @@ migrate_special_files (xlator_t *this, xlator_t *from, xlator_t *to, loc_t *loc, ia_minor (buf->ia_rdev)), dict, 0); if (ret) { gf_log (this->name, GF_LOG_WARNING, "%s: mknod failed (%s)", - loc->path, strerror (errno)); + loc->path, strerror (-ret)); + ret = -1; goto out; } @@ -648,13 +667,16 @@ done: if (ret) { gf_log (this->name, GF_LOG_WARNING, "%s: failed to perform setattr on %s (%s)", - loc->path, to->name, strerror (errno)); + loc->path, to->name, strerror (-ret)); + ret = -1; } ret = syncop_unlink (from, loc); - if (ret) + if (ret) { gf_log (this->name, GF_LOG_WARNING, "%s: unlink failed (%s)", - loc->path, strerror (errno)); + loc->path, strerror (-ret)); + ret = -1; + } out: if (dict) @@ -708,7 +730,8 @@ dht_migrate_file (xlator_t *this, loc_t *loc, xlator_t *from, xlator_t *to, ret = syncop_lookup (from, loc, dict, &stbuf, &xattr_rsp, NULL); if (ret) { gf_log (this->name, GF_LOG_ERROR, "%s: lookup failed on %s (%s)", - loc->path, from->name, strerror (errno)); + loc->path, from->name, strerror (-ret)); + ret = -1; goto out; } @@ -732,10 +755,12 @@ dht_migrate_file (xlator_t *this, loc_t *loc, xlator_t *from, xlator_t *to, /* TODO: move all xattr related operations to fd based operations */ ret = syncop_listxattr (from, loc, &xattr); - if (ret == -1) + if (ret < 0) { gf_log (this->name, GF_LOG_WARNING, "%s: failed to get xattr from %s (%s)", - loc->path, from->name, strerror (errno)); + loc->path, from->name, strerror (-ret)); + ret = -1; + } /* create the destination, with required modes/xattr */ ret = __dht_rebalance_create_dst_file (to, from, loc, &stbuf, @@ -760,7 +785,8 @@ dht_migrate_file (xlator_t *this, loc_t *loc, xlator_t *from, xlator_t *to, ret = syncop_fstat (from, src_fd, &stbuf); if (ret) { gf_log (this->name, GF_LOG_ERROR, "failed to lookup %s on %s (%s)", - loc->path, from->name, strerror (errno)); + loc->path, from->name, strerror (-ret)); + ret = -1; goto out; } @@ -779,7 +805,7 @@ dht_migrate_file (xlator_t *this, loc_t *loc, xlator_t *from, xlator_t *to, if (ret) { gf_log (this->name, GF_LOG_ERROR, "%s: failed to reset target size back to 0 (%s)", - loc->path, strerror (errno)); + loc->path, strerror (-ret)); } ret = -1; @@ -789,10 +815,12 @@ dht_migrate_file (xlator_t *this, loc_t *loc, xlator_t *from, xlator_t *to, /* TODO: Sync the locks */ ret = syncop_fsync (to, dst_fd, 0); - if (ret) + if (ret) { gf_log (this->name, GF_LOG_WARNING, "%s: failed to fsync on %s (%s)", - loc->path, to->name, strerror (errno)); + loc->path, to->name, strerror (-ret)); + ret = -1; + } /* Phase 2 - Data-Migration Complete, Housekeeping updates pending */ @@ -802,7 +830,8 @@ dht_migrate_file (xlator_t *this, loc_t *loc, xlator_t *from, xlator_t *to, /* Failed to get the stat info */ gf_log (this->name, GF_LOG_ERROR, "failed to fstat file %s on %s (%s)", - loc->path, from->name, strerror (errno)); + loc->path, from->name, strerror (-ret)); + ret = -1; goto out; } @@ -824,7 +853,8 @@ dht_migrate_file (xlator_t *this, loc_t *loc, xlator_t *from, xlator_t *to, if (ret) { gf_log (this->name, GF_LOG_WARNING, "%s: failed to perform setattr on %s (%s)", - loc->path, to->name, strerror (errno)); + loc->path, to->name, strerror (-ret)); + ret = -1; goto out; } @@ -835,7 +865,8 @@ dht_migrate_file (xlator_t *this, loc_t *loc, xlator_t *from, xlator_t *to, if (ret) { gf_log (this->name, GF_LOG_WARNING, "%s: failed to perform setattr on %s (%s)", - loc->path, to->name, strerror (errno)); + loc->path, to->name, strerror (-ret)); + ret = -1; } /* Make the source as a linkfile first before deleting it */ @@ -845,7 +876,8 @@ dht_migrate_file (xlator_t *this, loc_t *loc, xlator_t *from, xlator_t *to, if (ret) { gf_log (this->name, GF_LOG_WARNING, \ "%s: failed to perform setattr on %s (%s)", - loc->path, from->name, strerror (errno)); + loc->path, from->name, strerror (-ret)); + ret = -1; goto out; } @@ -855,7 +887,8 @@ dht_migrate_file (xlator_t *this, loc_t *loc, xlator_t *from, xlator_t *to, if (ret) { gf_log (this->name, GF_LOG_WARNING, "%s: failed to perform truncate on %s (%s)", - loc->path, from->name, strerror (errno)); + loc->path, from->name, strerror (-ret)); + ret = -1; } /* remove the 'linkto' xattr from the destination */ @@ -863,7 +896,8 @@ dht_migrate_file (xlator_t *this, loc_t *loc, xlator_t *from, xlator_t *to, if (ret) { gf_log (this->name, GF_LOG_WARNING, "%s: failed to perform removexattr on %s (%s)", - loc->path, to->name, strerror (errno)); + loc->path, to->name, strerror (-ret)); + ret = -1; } /* Do a stat and check the gfid before unlink */ @@ -871,7 +905,8 @@ dht_migrate_file (xlator_t *this, loc_t *loc, xlator_t *from, xlator_t *to, if (ret) { gf_log (this->name, GF_LOG_WARNING, "%s: failed to do a stat on %s (%s)", - loc->path, from->name, strerror (errno)); + loc->path, from->name, strerror (-ret)); + ret = -1; goto out; } @@ -881,7 +916,8 @@ dht_migrate_file (xlator_t *this, loc_t *loc, xlator_t *from, xlator_t *to, if (ret) { gf_log (this->name, GF_LOG_WARNING, "%s: failed to perform unlink on %s (%s)", - loc->path, from->name, strerror (errno)); + loc->path, from->name, strerror (-ret)); + ret = -1; goto out; } } @@ -890,7 +926,8 @@ dht_migrate_file (xlator_t *this, loc_t *loc, xlator_t *from, xlator_t *to, if (ret) { gf_log (this->name, GF_LOG_DEBUG, "%s: failed to lookup the file on subvolumes (%s)", - loc->path, strerror (errno)); + loc->path, strerror (-ret)); + ret = -1; } gf_log (this->name, GF_LOG_INFO, @@ -1053,10 +1090,10 @@ gf_defrag_handle_migrate_error (int32_t op_errno, gf_defrag_info_t *defrag) { /* if errno is not ENOSPC or ENOTCONN, we can still continue with rebalance process */ - if ((errno != ENOSPC) || (errno != ENOTCONN)) + if ((op_errno != ENOSPC) || (op_errno != ENOTCONN)) return 1; - if (errno == ENOTCONN) { + if (op_errno == ENOTCONN) { /* Most probably mount point went missing (mostly due to a brick down), say rebalance failure to user, let him restart it if everything is fine */ @@ -1064,7 +1101,7 @@ gf_defrag_handle_migrate_error (int32_t op_errno, gf_defrag_info_t *defrag) return -1; } - if (errno == ENOSPC) { + if (op_errno == ENOSPC) { /* rebalance process itself failed, may be remote brick went down, or write failed due to disk full etc etc.. */ @@ -1105,10 +1142,6 @@ gf_defrag_pattern_match (gf_defrag_info_t *defrag, char *name, uint64_t size) * have been fixed */ -#ifdef GF_LINUX_HOST_OS -#pragma GCC push_options -#pragma GCC optimize ("O0") -#endif int gf_defrag_migrate_data (xlator_t *this, gf_defrag_info_t *defrag, loc_t *loc, dict_t *migrate_data) @@ -1126,7 +1159,6 @@ gf_defrag_migrate_data (xlator_t *this, gf_defrag_info_t *defrag, loc_t *loc, int32_t op_errno = 0; char *uuid_str = NULL; uuid_t node_uuid = {0,}; - int readdir_operrno = 0; struct timeval dir_start = {0,}; struct timeval end = {0,}; double elapsed = {0,}; @@ -1148,6 +1180,7 @@ gf_defrag_migrate_data (xlator_t *this, gf_defrag_info_t *defrag, loc_t *loc, if (ret) { gf_log (this->name, GF_LOG_ERROR, "Failed to open dir %s", loc->path); + ret = -1; goto out; } @@ -1160,14 +1193,11 @@ gf_defrag_migrate_data (xlator_t *this, gf_defrag_info_t *defrag, loc_t *loc, gf_log (this->name, GF_LOG_ERROR, "Readdir returned %s." " Aborting migrate-data", - strerror(readdir_operrno)); + strerror(-ret)); + ret = -1; goto out; } - /* Need to keep track of ENOENT errno, that means, there is no - need to send more readdirp() */ - readdir_operrno = errno; - if (list_empty (&entries.list)) break; @@ -1232,6 +1262,7 @@ gf_defrag_migrate_data (xlator_t *this, gf_defrag_info_t *defrag, loc_t *loc, if (ret) { gf_log (this->name, GF_LOG_ERROR, "%s" " lookup failed", entry_loc.path); + ret = -1; continue; } @@ -1240,6 +1271,7 @@ gf_defrag_migrate_data (xlator_t *this, gf_defrag_info_t *defrag, loc_t *loc, if(ret < 0) { gf_log (this->name, GF_LOG_ERROR, "Failed to " "get node-uuid for %s", entry_loc.path); + ret = -1; continue; } @@ -1249,6 +1281,7 @@ gf_defrag_migrate_data (xlator_t *this, gf_defrag_info_t *defrag, loc_t *loc, gf_log (this->name, GF_LOG_ERROR, "Failed to " "get node-uuid from dict for %s", entry_loc.path); + ret = -1; continue; } @@ -1282,7 +1315,7 @@ gf_defrag_migrate_data (xlator_t *this, gf_defrag_info_t *defrag, loc_t *loc, ret = syncop_getxattr (this, &entry_loc, &dict, GF_XATTR_LINKINFO_KEY); if (ret < 0) { - if (errno != ENODATA) { + if (-ret != ENODATA) { loglevel = GF_LOG_ERROR; defrag->total_failures += 1; } else { @@ -1290,7 +1323,8 @@ gf_defrag_migrate_data (xlator_t *this, gf_defrag_info_t *defrag, loc_t *loc, } gf_log (this->name, loglevel, "%s: failed to " "get "GF_XATTR_LINKINFO_KEY" key - %s", - entry_loc.path, strerror (errno)); + entry_loc.path, strerror (-ret)); + ret = -1; continue; } @@ -1314,8 +1348,8 @@ gf_defrag_migrate_data (xlator_t *this, gf_defrag_info_t *defrag, loc_t *loc, } } - if (ret == -1) { - op_errno = errno; + if (ret < 0) { + op_errno = -ret; ret = gf_defrag_handle_migrate_error (op_errno, defrag); @@ -1350,9 +1384,6 @@ gf_defrag_migrate_data (xlator_t *this, gf_defrag_info_t *defrag, loc_t *loc, gf_dirent_free (&entries); free_entries = _gf_false; INIT_LIST_HEAD (&entries.list); - - if (readdir_operrno == ENOENT) - break; } gettimeofday (&end, NULL); @@ -1375,10 +1406,6 @@ out: return ret; } -#ifdef GF_LINUX_HOST_OS -#pragma GCC pop_options -#endif - int gf_defrag_fix_layout (xlator_t *this, gf_defrag_info_t *defrag, loc_t *loc, @@ -1394,12 +1421,12 @@ gf_defrag_fix_layout (xlator_t *this, gf_defrag_info_t *defrag, loc_t *loc, dict_t *dict = NULL; off_t offset = 0; struct iatt iatt = {0,}; - int readdirp_errno = 0; ret = syncop_lookup (this, loc, NULL, &iatt, NULL, NULL); if (ret) { gf_log (this->name, GF_LOG_ERROR, "Lookup failed on %s", loc->path); + ret = -1; goto out; } @@ -1433,14 +1460,11 @@ gf_defrag_fix_layout (xlator_t *this, gf_defrag_info_t *defrag, loc_t *loc, if (ret < 0) { gf_log (this->name, GF_LOG_ERROR, "Readdir returned %s" - ". Aborting fix-layout",strerror(errno)); + ". Aborting fix-layout",strerror(-ret)); + ret = -1; goto out; } - /* Need to keep track of ENOENT errno, that means, there is no - need to send more readdirp() */ - readdirp_errno = errno; - if (list_empty (&entries.list)) break; @@ -1494,6 +1518,7 @@ gf_defrag_fix_layout (xlator_t *this, gf_defrag_info_t *defrag, loc_t *loc, if (ret) { gf_log (this->name, GF_LOG_ERROR, "%s" " lookup failed", entry_loc.path); + ret = -1; continue; } @@ -1505,6 +1530,7 @@ gf_defrag_fix_layout (xlator_t *this, gf_defrag_info_t *defrag, loc_t *loc, defrag->defrag_status = GF_DEFRAG_STATUS_FAILED; defrag->total_failures ++; + ret = -1; goto out; } ret = gf_defrag_fix_layout (this, defrag, &entry_loc, @@ -1521,8 +1547,6 @@ gf_defrag_fix_layout (xlator_t *this, gf_defrag_info_t *defrag, loc_t *loc, gf_dirent_free (&entries); free_entries = _gf_false; INIT_LIST_HEAD (&entries.list); - if (readdirp_errno == ENOENT) - break; } ret = 0; @@ -1587,6 +1611,7 @@ gf_defrag_start_crawl (void *data) if (ret) { gf_log (this->name, GF_LOG_ERROR, "look up on / failed"); + ret = -1; goto out; } @@ -1607,6 +1632,7 @@ gf_defrag_start_crawl (void *data) gf_log (this->name, GF_LOG_ERROR, "fix layout on %s failed", loc.path); defrag->total_failures++; + ret = -1; goto out; } diff --git a/xlators/cluster/dht/src/dht-selfheal.c b/xlators/cluster/dht/src/dht-selfheal.c index 3fe96b1c7..06fa1ed3a 100644 --- a/xlators/cluster/dht/src/dht-selfheal.c +++ b/xlators/cluster/dht/src/dht-selfheal.c @@ -1012,10 +1012,11 @@ dht_dir_attr_heal (void *data) ret = syncop_setattr (subvol, &local->loc, &local->stbuf, (GF_SET_ATTR_UID | GF_SET_ATTR_GID), NULL, NULL); - if (ret) + if (ret) { gf_log ("dht", GF_LOG_ERROR, "Failed to set uid/gid on" " %s on %s subvol (%s)", local->loc.path, - subvol->name, strerror (errno)); + subvol->name, strerror (-ret)); + } } out: return 0; diff --git a/xlators/features/locks/src/posix.c b/xlators/features/locks/src/posix.c index fce0d509f..2db327687 100644 --- a/xlators/features/locks/src/posix.c +++ b/xlators/features/locks/src/posix.c @@ -552,7 +552,8 @@ fetch_pathinfo (xlator_t *this, inode_t *inode, int32_t *op_errno, ret = syncop_getxattr (FIRST_CHILD(this), &loc, &dict, GF_XATTR_PATHINFO_KEY); if (ret < 0) { - *op_errno = errno; + *op_errno = -ret; + ret = -1; goto out; } diff --git a/xlators/features/qemu-block/src/bdrv-xlator.c b/xlators/features/qemu-block/src/bdrv-xlator.c index 106c59775..aaf028cfe 100644 --- a/xlators/features/qemu-block/src/bdrv-xlator.c +++ b/xlators/features/qemu-block/src/bdrv-xlator.c @@ -109,7 +109,7 @@ qemu_gluster_open (BlockDriverState *bs, QDict *options, int bdrv_flags) NULL); if (ret) { loc_wipe(&loc); - return -errno; + return ret; } s->inode = inode_ref(loc.inode); @@ -153,7 +153,7 @@ qemu_gluster_create (const char *filename, QEMUOptionParameter *options) ret = syncop_fstat (FIRST_CHILD(THIS), fd, &stat); if (ret) { fd_unref (fd); - return -errno; + return ret; } if (stat.ia_size) { @@ -166,7 +166,7 @@ qemu_gluster_create (const char *filename, QEMUOptionParameter *options) ret = syncop_ftruncate (FIRST_CHILD(THIS), fd, total_size); if (ret) { fd_unref (fd); - return -errno; + return ret; } } @@ -196,10 +196,8 @@ qemu_gluster_co_readv (BlockDriverState *bs, int64_t sector_num, int nb_sectors, ret = syncop_readv (FIRST_CHILD(THIS), fd, size, offset, 0, &iov, &count, &iobref); - if (ret < 0) { - ret = -errno; + if (ret < 0) goto out; - } iov_copy (qiov->iov, qiov->niov, iov, count); /* *choke!* */ @@ -249,8 +247,6 @@ qemu_gluster_co_writev (BlockDriverState *bs, int64_t sector_num, int nb_sectors iov.iov_len = size; ret = syncop_writev (FIRST_CHILD(THIS), fd, &iov, 1, offset, iobref, 0); - if (ret < 0) - ret = -errno; out: if (iobuf) @@ -306,9 +302,6 @@ qemu_gluster_truncate (BlockDriverState *bs, int64_t offset) fd_unref (fd); - if (ret < 0) - return ret; - return ret; } diff --git a/xlators/features/qemu-block/src/qb-coroutines.c b/xlators/features/qemu-block/src/qb-coroutines.c index 7c52adb21..974312f12 100644 --- a/xlators/features/qemu-block/src/qb-coroutines.c +++ b/xlators/features/qemu-block/src/qb-coroutines.c @@ -86,7 +86,7 @@ qb_format_and_resume (void *opaque) GF_FREE(qb_inode->backing_fname); if (ret) { loc_wipe(&loc); - ret = errno; + ret = -ret; goto err; } @@ -150,11 +150,10 @@ qb_format_and_resume (void *opaque) ret = syncop_fsetxattr (FIRST_CHILD(THIS), fd, xattr, 0); if (ret) { - ret = errno; gf_log (frame->this->name, GF_LOG_ERROR, "failed to setxattr for %s", uuid_utoa (inode->gfid)); - QB_STUB_UNWIND (stub, -1, ret); + QB_STUB_UNWIND (stub, -1, -ret); fd_unref (fd); dict_unref (xattr); return 0; @@ -476,7 +475,10 @@ qb_co_truncate (void *opaque) } } - syncop_fstat (FIRST_CHILD(this), local->fd, &stub->args_cbk.prestat); + ret = syncop_fstat (FIRST_CHILD(this), local->fd, + &stub->args_cbk.prestat); + if (ret < 0) + goto out; stub->args_cbk.prestat.ia_size = qb_inode->size; ret = bdrv_truncate (qb_inode->bs, stub->args.offset); @@ -487,7 +489,10 @@ qb_co_truncate (void *opaque) qb_inode->size = offset; - syncop_fstat (FIRST_CHILD(this), local->fd, &stub->args_cbk.poststat); + ret = syncop_fstat (FIRST_CHILD(this), local->fd, + &stub->args_cbk.poststat); + if (ret < 0) + goto out; stub->args_cbk.poststat.ia_size = qb_inode->size; qb_update_size_xattr (this, local->fd, qb_inode->fmt, qb_inode->size); diff --git a/xlators/mount/fuse/src/fuse-bridge.c b/xlators/mount/fuse/src/fuse-bridge.c index ee12d869c..315259ece 100644 --- a/xlators/mount/fuse/src/fuse-bridge.c +++ b/xlators/mount/fuse/src/fuse-bridge.c @@ -4026,12 +4026,14 @@ fuse_nameless_lookup (xlator_t *xl, uuid_t gfid, loc_t *loc) inode_t *linked_inode = NULL; if ((loc == NULL) || (xl == NULL)) { + ret = -EINVAL; goto out; } if (loc->inode == NULL) { loc->inode = inode_new (xl->itable); if (loc->inode == NULL) { + ret = -ENOMEM; goto out; } } @@ -4040,13 +4042,13 @@ fuse_nameless_lookup (xlator_t *xl, uuid_t gfid, loc_t *loc) xattr_req = dict_new (); if (xattr_req == NULL) { + ret = -ENOMEM; goto out; } ret = syncop_lookup (xl, loc, xattr_req, &iatt, NULL, NULL); - if (ret < 0) { + if (ret < 0) goto out; - } linked_inode = inode_link (loc->inode, NULL, NULL, &iatt); inode_unref (loc->inode); @@ -4095,9 +4097,10 @@ fuse_migrate_fd_open (xlator_t *this, fd_t *basefd, fd_t *oldfd, "name-less lookup of gfid (%s) failed (%s)" "(old-subvolume:%s-%d new-subvolume:%s-%d)", uuid_utoa (basefd->inode->gfid), - strerror (errno), + strerror (-ret), old_subvol->name, old_subvol->graph->id, new_subvol->name, new_subvol->graph->id); + ret = -1; goto out; } @@ -4115,6 +4118,7 @@ fuse_migrate_fd_open (xlator_t *this, fd_t *basefd, fd_t *oldfd, uuid_utoa (loc.inode->gfid), old_subvol->name, old_subvol->graph->id, new_subvol->name, new_subvol->graph->id); + ret = -1; goto out; } @@ -4138,9 +4142,10 @@ fuse_migrate_fd_open (xlator_t *this, fd_t *basefd, fd_t *oldfd, gf_log ("glusterfs-fuse", GF_LOG_WARNING, "open on basefd (ptr:%p inode-gfid:%s) failed (%s)" "(old-subvolume:%s-%d new-subvolume:%s-%d)", basefd, - uuid_utoa (basefd->inode->gfid), strerror (errno), + uuid_utoa (basefd->inode->gfid), strerror (-ret), old_subvol->name, old_subvol->graph->id, new_subvol->name, new_subvol->graph->id); + ret = -1; goto out; } @@ -4208,6 +4213,7 @@ fuse_migrate_locks (xlator_t *this, fd_t *basefd, fd_t *oldfd, oldfd, newfd, uuid_utoa (newfd->inode->gfid), old_subvol->name, old_subvol->graph->id, new_subvol->name, new_subvol->graph->id); + ret = -1; goto out; } @@ -4233,6 +4239,7 @@ fuse_migrate_locks (xlator_t *this, fd_t *basefd, fd_t *oldfd, oldfd, newfd, uuid_utoa (newfd->inode->gfid), old_subvol->name, old_subvol->graph->id, new_subvol->name, new_subvol->graph->id); + ret = -1; goto out; } @@ -4300,10 +4307,11 @@ fuse_migrate_fd (xlator_t *this, fd_t *basefd, xlator_t *old_subvol, "syncop_fsync failed (%s) on fd (%p)" "(basefd:%p basefd-inode.gfid:%s) " "(old-subvolume:%s-%d new-subvolume:%s-%d)", - strerror (errno), oldfd, basefd, + strerror (-ret), oldfd, basefd, uuid_utoa (basefd->inode->gfid), old_subvol->name, old_subvol->graph->id, new_subvol->name, new_subvol->graph->id); + ret = -1; } } else { gf_log ("glusterfs-fuse", GF_LOG_WARNING, -- cgit From b2ef4e3d11af79a765406672bb6ca070b40c9b64 Mon Sep 17 00:00:00 2001 From: Susant Palai Date: Mon, 6 Jan 2014 12:38:08 +0000 Subject: quota: unmount quota aux mount for volume stop Previously df -h used to display "Transport end point not connected" for quota auxiliary mount after volume is stopped. This patch unmounts the auxiliary mount when the volume is stopped in all peer nodes for that volume. Change-Id: I78abb44386cd8242a532f92c13df8bdb57c78e31 BUG: 1049323 Signed-off-by: Susant Palai Reviewed-on: http://review.gluster.org/6656 Tested-by: Gluster Build System Reviewed-by: Vijay Bellur --- tests/bugs/bug-1049323.t | 64 +++++++++++++++++++++++++ xlators/mgmt/glusterd/src/glusterd-volume-ops.c | 27 +++++++++++ 2 files changed, 91 insertions(+) create mode 100755 tests/bugs/bug-1049323.t diff --git a/tests/bugs/bug-1049323.t b/tests/bugs/bug-1049323.t new file mode 100755 index 000000000..203612e91 --- /dev/null +++ b/tests/bugs/bug-1049323.t @@ -0,0 +1,64 @@ +#!/bin/bash +. $(dirname $0)/../include.rc +. $(dirname $0)/../volume.rc + +cleanup; + +function _init() +{ +# Start glusterd +TEST glusterd; +TEST pidof glusterd; +TEST $CLI volume info; + +#Create a volume +TEST $CLI volume create $V0 replica 2 $H0:$B0/${V0}{1,2}; + +#Verify volume is created +EXPECT "$V0" volinfo_field $V0 'Volume Name'; +EXPECT 'Created' volinfo_field $V0 'Status'; + +#Start volume and verify +TEST $CLI volume start $V0; +EXPECT 'Started' volinfo_field $V0 'Status'; +TEST glusterfs --volfile-id=$V0 --volfile-server=$H0 $M0 + +#Enable Quota +TEST $CLI volume quota $V0 enable + +##Wait for the auxiliary mount to comeup +sleep 3; +} + +function get_aux() +{ +##Check if a auxiliary mount is there +df -h | grep "/var/run/gluster/$V0" - + +if [ $? -eq 0 ] +then + echo "0" +else + echo "1" +fi +} + +function create_data() +{ +#set some limit on the volume +TEST $CLI volume quota $V0 limit-usage / 50MB; + +#Auxiliary mount should be there before stopping the volume +EXPECT "0" get_aux; + +TEST $CLI volume stop $V0; + +#Aux mount should have been removed +EXPECT "1" get_aux; + +} + + +_init; +create_data; +cleanup; diff --git a/xlators/mgmt/glusterd/src/glusterd-volume-ops.c b/xlators/mgmt/glusterd/src/glusterd-volume-ops.c index 85a537306..051e7d756 100644 --- a/xlators/mgmt/glusterd/src/glusterd-volume-ops.c +++ b/xlators/mgmt/glusterd/src/glusterd-volume-ops.c @@ -1774,6 +1774,9 @@ glusterd_op_stop_volume (dict_t *dict) glusterd_volinfo_t *volinfo = NULL; glusterd_brickinfo_t *brickinfo = NULL; xlator_t *this = NULL; + char mountdir[PATH_MAX] = {0,}; + runner_t runner = {0,}; + char pidfile[PATH_MAX] = {0,}; this = THIS; GF_ASSERT (this); @@ -1801,6 +1804,30 @@ glusterd_op_stop_volume (dict_t *dict) if (ret) goto out; + /* If quota auxiliary mount is present, unmount it */ + GLUSTERFS_GET_AUX_MOUNT_PIDFILE (pidfile, volname); + + if (!gf_is_service_running (pidfile, NULL)) { + gf_log (this->name, GF_LOG_DEBUG, "Aux mount of volume %s " + "absent", volname); + } else { + GLUSTERD_GET_QUOTA_AUX_MOUNT_PATH (mountdir, volname, "/"); + + runinit (&runner); + runner_add_args (&runner, "umount", + + #if GF_LINUX_HOST_OS + "-l", + #endif + mountdir, NULL); + ret = runner_run_reuse (&runner); + if (ret) + gf_log (this->name, GF_LOG_ERROR, "umount on %s failed, " + "reason : %s", mountdir, strerror (errno)); + + runner_end (&runner); + } + ret = glusterd_nodesvcs_handle_graph_change (volinfo); out: return ret; -- cgit From 17c4fb2d04f84b5632983866e8bddfbd7d77a054 Mon Sep 17 00:00:00 2001 From: Krishnan Parthasarathi Date: Mon, 28 Oct 2013 19:14:49 +0530 Subject: quota: get directory size before enforcing quota on rename Change-Id: If18cab5992ddc91457782786942971deb1b51ead BUG: 1023974 Signed-off-by: Krishnan Parthasarathi Reviewed-on: http://review.gluster.org/6155 Reviewed-by: Raghavendra G Tested-by: Gluster Build System Reviewed-by: Vijay Bellur --- tests/bugs/bug-1023974.t | 33 ++++++++++++++++ xlators/features/quota/src/quota.c | 81 ++++++++++++++++++++++++++++++++------ xlators/features/quota/src/quota.h | 3 ++ 3 files changed, 105 insertions(+), 12 deletions(-) create mode 100644 tests/bugs/bug-1023974.t diff --git a/tests/bugs/bug-1023974.t b/tests/bugs/bug-1023974.t new file mode 100644 index 000000000..56766b979 --- /dev/null +++ b/tests/bugs/bug-1023974.t @@ -0,0 +1,33 @@ +#!/bin/bash + +# This regression test tries to ensure renaming a directory with content, and +# no limit set, is accounted properly, when moved into a directory with quota +# limit set. + +. $(dirname $0)/../include.rc + +cleanup; + +TEST glusterd +TEST pidof glusterd; +TEST $CLI volume info; + +TEST $CLI volume create $V0 replica 2 $H0:$B0/${V0}{1,2,3,4,5,6}; +TEST $CLI volume start $V0; + +TEST $CLI volume quota $V0 enable; + +TEST glusterfs --volfile-id=$V0 --volfile-server=$H0 $M0; + +TEST mkdir -p $M0/1/2; +TEST $CLI volume quota $V0 limit-usage /1/2 100MB 70%; + +#The corresponding write(3) should fail with EDQUOT ("Disk quota exceeded") +TEST ! dd if=/dev/urandom of=$M0/1/2/file bs=1M count=102; +TEST mkdir $M0/1/3 -p; +TEST dd if=/dev/urandom of=$M0/1/3/file bs=1M count=102; + +#The corresponding rename(3) should fail with EDQUOT ("Disk quota exceeded") +TEST ! mv $M0/1/3/ $M0/1/2/3_mvd; + +cleanup; diff --git a/xlators/features/quota/src/quota.c b/xlators/features/quota/src/quota.c index d46247241..5cbd9f02d 100644 --- a/xlators/features/quota/src/quota.c +++ b/xlators/features/quota/src/quota.c @@ -879,8 +879,7 @@ quota_fill_inodectx (xlator_t *this, inode_t *inode, dict_t *dict, ctx = (quota_inode_ctx_t *)(unsigned long)value; if ((((ctx == NULL) || (ctx->hard_lim == hard_lim)) - && (hard_lim < 0) && !((IA_ISREG (buf->ia_type)) - || (IA_ISLNK (buf->ia_type))))) { + && (hard_lim < 0) && !QUOTA_REG_OR_LNK_FILE (buf->ia_type))) { ret = 0; goto out; } @@ -902,7 +901,7 @@ quota_fill_inodectx (xlator_t *this, inode_t *inode, dict_t *dict, ctx->buf = *buf; - if (!(IA_ISREG (buf->ia_type) || IA_ISLNK (buf->ia_type))) { + if (!QUOTA_REG_OR_LNK_FILE (buf->ia_type)) { goto unlock; } @@ -1869,8 +1868,7 @@ quota_rename_cbk (call_frame_t *frame, void *cookie, xlator_t *this, goto out; } - if (IA_ISREG (local->oldloc.inode->ia_type) - || IA_ISLNK (local->oldloc.inode->ia_type)) { + if (QUOTA_REG_OR_LNK_FILE (local->oldloc.inode->ia_type)) { size = buf->ia_blocks * 512; } @@ -1881,8 +1879,7 @@ quota_rename_cbk (call_frame_t *frame, void *cookie, xlator_t *this, size); } - if (!(IA_ISREG (local->oldloc.inode->ia_type) - || IA_ISLNK (local->oldloc.inode->ia_type))) { + if (!QUOTA_REG_OR_LNK_FILE (local->oldloc.inode->ia_type)) { goto out; } @@ -1997,6 +1994,46 @@ unwind: } +static int32_t +quota_rename_get_size_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, inode_t *inode, + struct iatt *buf, dict_t *xdata, + struct iatt *postparent) +{ + quota_local_t *local = NULL; + int32_t ret = 0; + int64_t *size = 0; + + GF_ASSERT (frame); + GF_VALIDATE_OR_GOTO_WITH_ERROR ("quota", this, out, op_errno, + EINVAL); + GF_VALIDATE_OR_GOTO_WITH_ERROR (this->name, xdata, out, op_errno, + EINVAL); + local = frame->local; + GF_ASSERT (local); + local->link_count = 1; + + if (op_ret < 0) + goto out; + + + ret = dict_get_bin (xdata, QUOTA_SIZE_KEY, (void **) &size); + if (ret < 0) { + gf_log (this->name, GF_LOG_WARNING, + "size key not present in dict"); + op_errno = EINVAL; + goto out; + } + local->delta = ntoh64 (*size); + quota_check_limit (frame, local->newloc.parent, this, + NULL, NULL); + return 0; + +out: + quota_handle_validate_error (local, -1, op_errno); + return 0; +} + int32_t quota_rename (call_frame_t *frame, xlator_t *this, loc_t *oldloc, loc_t *newloc, dict_t *xdata) @@ -2039,8 +2076,7 @@ quota_rename (call_frame_t *frame, xlator_t *this, loc_t *oldloc, local->link_count = 1; local->stub = stub; - if (IA_ISREG (oldloc->inode->ia_type) - || IA_ISLNK (oldloc->inode->ia_type)) { + if (QUOTA_REG_OR_LNK_FILE (oldloc->inode->ia_type)) { ret = quota_inode_ctx_get (oldloc->inode, this, &ctx, 0); if (ctx == NULL) { gf_log (this->name, GF_LOG_WARNING, @@ -2050,11 +2086,32 @@ quota_rename (call_frame_t *frame, xlator_t *this, loc_t *oldloc, oldloc->inode ? uuid_utoa (oldloc->inode->gfid) : "0"); local->delta = 0; + } else { - local->delta = ctx->buf.ia_blocks * 512; + + /* FIXME: We need to account for the size occupied by this + * inode on the target directory. To avoid double + * accounting, we need to modify enforcer to perform + * quota_check_limit only uptil the least common ancestor + * directory inode*/ + + /* FIXME: The following code assumes that regular files and + *linkfiles are present, in their entirety, in a single + brick. This *assumption is invalid in the case of + stripe.*/ + + local->delta = ctx->buf.ia_blocks * 512; } - } else { - local->delta = 0; + + } else if (IA_ISDIR (oldloc->inode->ia_type)) { + ret = quota_validate (frame, oldloc->inode, this, + quota_rename_get_size_cbk); + if (ret){ + op_errno = -ret; + goto err; + } + + return 0; } quota_check_limit (frame, newloc->parent, this, NULL, NULL); diff --git a/xlators/features/quota/src/quota.h b/xlators/features/quota/src/quota.h index 96c19e77e..02bc0d8b6 100644 --- a/xlators/features/quota/src/quota.h +++ b/xlators/features/quota/src/quota.h @@ -130,6 +130,9 @@ goto label; \ } while (0) +#define QUOTA_REG_OR_LNK_FILE(ia_type) \ + (IA_ISREG (ia_type) || IA_ISLNK (ia_type)) + struct quota_dentry { -- cgit