From 2775959b47c15e597a7974bbafa79e0882452952 Mon Sep 17 00:00:00 2001 From: Jeff Darcy Date: Tue, 4 Mar 2014 15:35:13 +0000 Subject: nsr: add mem_acct_init functions It's not clear why this started failing after the last merge, since the mem_acct code hasn't changed for a while, but it did and having those functions is good form anyway. Also removed a bunch of GF_ASSERT(0) calls that made (and will continue to make) debugging unnecessarily painful. Change-Id: Icd89f2e23f1eaafc79cb9af06c3c9c8d2fdeec14 Signed-off-by: Jeff Darcy --- api/src/glfs-fops.c | 3 +- xlators/cluster/nsr-client/src/nsrc.c | 23 ++++++++++++++- xlators/cluster/nsr-recon/src/recon_driver.c | 43 +++------------------------- xlators/cluster/nsr-recon/src/recon_xlator.c | 20 +++++++++++++ xlators/cluster/nsr-recon/src/recon_xlator.h | 1 + xlators/cluster/nsr-server/src/nsr.c | 19 ++++++++++++ 6 files changed, 68 insertions(+), 41 deletions(-) diff --git a/api/src/glfs-fops.c b/api/src/glfs-fops.c index 05f0997a8..326530578 100644 --- a/api/src/glfs-fops.c +++ b/api/src/glfs-fops.c @@ -2767,7 +2767,8 @@ glfs_llistxattr (struct glfs *fs, const char *path, void *value, size_t size) ssize_t -glfs_flistxattr_with_xdata (struct glfs_fd *glfd, void *value, size_t size,dict_t *dict) +glfs_flistxattr_with_xdata (struct glfs_fd *glfd, void *value, size_t size, + dict_t *dict) { int ret = -1; xlator_t *subvol = NULL; diff --git a/xlators/cluster/nsr-client/src/nsrc.c b/xlators/cluster/nsr-client/src/nsrc.c index eed824599..4551a1432 100644 --- a/xlators/cluster/nsr-client/src/nsrc.c +++ b/xlators/cluster/nsr-client/src/nsrc.c @@ -27,6 +27,7 @@ enum gf_dht_mem_types_ { gf_mt_nsrc_private_t = gf_common_mt_end + 1, + gf_mt_nsrc_end }; typedef struct { @@ -150,6 +151,26 @@ struct xlator_fops fops = { struct xlator_cbks cbks = { }; + +int32_t +mem_acct_init (xlator_t *this) +{ + int ret = -1; + + GF_VALIDATE_OR_GOTO ("nsrc", this, out); + + ret = xlator_mem_acct_init (this, gf_mt_nsrc_end + 1); + + if (ret != 0) { + gf_log (this->name, GF_LOG_ERROR, + "Memory accounting init" "failed"); + return ret; + } +out: + return ret; +} + + int32_t nsrc_init (xlator_t *this) { @@ -185,7 +206,7 @@ nsrc_fini (xlator_t *this) } int32_t -nsrc_notify (xlator_t *this, int32_t event, void *data, void *data2) +nsrc_notify (xlator_t *this, int32_t event, void *data, ...) { int32_t ret = 0; diff --git a/xlators/cluster/nsr-recon/src/recon_driver.c b/xlators/cluster/nsr-recon/src/recon_driver.c index 49ee465c5..1e68414ee 100644 --- a/xlators/cluster/nsr-recon/src/recon_driver.c +++ b/xlators/cluster/nsr-recon/src/recon_driver.c @@ -213,16 +213,18 @@ get_xattr_total_size( struct glfs_fd *fd, // First get the size of the keys s = glfs_flistxattr_with_xdata(fd, NULL,0, dict); - if (s == -1) + if (s == -1) { goto out; + } *key_size = s; // TBD - use the regular calloc (*b) = c = calloc(s+1,1); // get the keys themselves - if (glfs_flistxattr_with_xdata(fd, c, s+1, dict) == -1) + if (glfs_flistxattr_with_xdata(fd, c, s+1, dict) == -1) { goto out; + } do { int32_t r; uint32_t len = 0; @@ -1502,28 +1504,24 @@ apply_record(nsr_per_node_worker_t *ctx, fd = glfs_h_open_with_xdata(ctx->fs, obj, O_RDWR, dict); if (fd == NULL) { - GF_ASSERT(0); nsr_worker_log(this->name, GF_LOG_ERROR, "open for file %s failed\n", ri->rec.gfid); return _gf_false; } if (glfs_lseek_with_xdata(fd, ri->rec.offset, SEEK_SET, dict) != ri->rec.offset) { - GF_ASSERT(0); nsr_worker_log(this->name, GF_LOG_ERROR, "lseek for file %s failed at offset %d\n", ri->rec.gfid, ri->rec.offset); return _gf_false; } if (glfs_write_with_xdata(fd, ri->work.data, ri->rec.len, 0, dict) != ri->rec.len) { - GF_ASSERT(0); nsr_worker_log(this->name, GF_LOG_ERROR, "write for file %s failed for bytes %d\n", ri->rec.gfid, ri->rec.len); return _gf_false; } if (glfs_close_with_xdata(fd, dict) == -1) { - GF_ASSERT(0); nsr_worker_log(this->name, GF_LOG_ERROR, "close failed\n"); return _gf_false; @@ -1543,21 +1541,18 @@ apply_record(nsr_per_node_worker_t *ctx, fd = glfs_h_open_with_xdata(ctx->fs, obj, O_RDWR, dict); if (fd == NULL) { - GF_ASSERT(0); nsr_worker_log(this->name, GF_LOG_ERROR, "open for file %s failed\n", ri->rec.gfid); return _gf_false; } if (glfs_ftruncate_with_xdata(fd, ri->rec.offset, dict) == -1) { - GF_ASSERT(0); nsr_worker_log(this->name, GF_LOG_ERROR, "trunctae for file %s failed @offset %d\n", ri->rec.gfid,ri->rec.offset ); return _gf_false; } if (glfs_close_with_xdata(fd, dict) == -1) { - GF_ASSERT(0); nsr_worker_log(this->name, GF_LOG_ERROR, "close failed\n"); return _gf_false; @@ -1594,7 +1589,6 @@ apply_record(nsr_per_node_worker_t *ctx, else fd = glfs_h_open_with_xdata(ctx->fs, obj, O_RDWR, dict); if (fd == NULL) { - GF_ASSERT(0); nsr_worker_log(this->name, GF_LOG_ERROR, "open for file %s failed\n", ri->rec.gfid); @@ -1603,14 +1597,12 @@ apply_record(nsr_per_node_worker_t *ctx, if(get_xattr_total_size(fd, &t_b, &k_s, &v_s, &num, dict) == -1) { if (t_b) free(t_b); - GF_ASSERT(0); nsr_worker_log(this->name, GF_LOG_ERROR, "list of xattr of %s failed\n", ri->rec.gfid); return _gf_false; } if (delete_xattr(fd, dict, t_b, num) == -1) { - GF_ASSERT(0); nsr_worker_log(this->name, GF_LOG_ERROR, "deleting xattrs failed\n"); return _gf_false; @@ -1619,21 +1611,18 @@ apply_record(nsr_per_node_worker_t *ctx, // Set one special dict flag to indicate the opcode so that // the opcode gets set to this if (dict_set_int32(dict,"recon-xattr-opcode",ri->rec.op)) { - GF_ASSERT(0); nsr_worker_log(this->name, GF_LOG_ERROR, "setting opcode to %d failed\n",ri->rec.op); return _gf_false; } if (fill_xattr(fd, dict, ri->work.data, ri->work.num) == -1) { - GF_ASSERT(0); nsr_worker_log(this->name, GF_LOG_ERROR, "filling xattrs failed\n"); return _gf_false; } if (glfs_close_with_xdata(fd, dict) == -1) { - GF_ASSERT(0); nsr_worker_log(this->name, GF_LOG_ERROR, "close failed\n"); return _gf_false; @@ -1658,7 +1647,6 @@ apply_record(nsr_per_node_worker_t *ctx, nsr_worker_log (this->name, GF_LOG_INFO, "creating with mode 0%o", ri->rec.mode); if (glfs_h_creat_with_xdata(ctx->fs, obj, ri->rec.entry, O_RDWR, ri->rec.mode, NULL, gfid, dict) == NULL) { - GF_ASSERT(0); nsr_worker_log(this->name, GF_LOG_ERROR, "Failure for Doing create for file %s\n", ri->rec.entry); @@ -1682,7 +1670,6 @@ apply_record(nsr_per_node_worker_t *ctx, if ((obj = create_obj(ctx, ri->rec.pargfid)) == NULL) return _gf_false; if (glfs_h_mknod_with_xdata(ctx->fs, obj, ri->rec.entry, O_RDWR, 0777, NULL, gfid, dict) == NULL) { - GF_ASSERT(0); nsr_worker_log(this->name, GF_LOG_ERROR, "Failure for Doing mknod for file %s\n", ri->rec.entry); @@ -1706,7 +1693,6 @@ apply_record(nsr_per_node_worker_t *ctx, if ((obj = create_obj(ctx, ri->rec.pargfid)) == NULL) return _gf_false; if (glfs_h_mkdir_with_xdata(ctx->fs, obj, ri->rec.entry, 0777, NULL, gfid, dict) != 0) { - GF_ASSERT(0); nsr_worker_log(this->name, GF_LOG_ERROR, "Failure for Doing mkdir for file %s\n", ri->rec.entry); @@ -1725,7 +1711,6 @@ apply_record(nsr_per_node_worker_t *ctx, if ((obj = create_obj(ctx, ri->rec.pargfid)) == NULL) return _gf_false; if (glfs_h_unlink_with_xdata(ctx->fs, obj, ri->rec.entry, dict) != 0) { - GF_ASSERT(0); nsr_worker_log(this->name, GF_LOG_ERROR, "Failure for Doing rmdir/unlink for file %s\n", ri->rec.entry); @@ -1748,7 +1733,6 @@ apply_record(nsr_per_node_worker_t *ctx, uuid_parse(ri->rec.gfid, gfid); if (glfs_h_symlink_with_xdata(ctx->fs, obj, ri->rec.entry, ri->rec.link_path, NULL, gfid, dict) == NULL) { - GF_ASSERT(0); nsr_worker_log(this->name, GF_LOG_ERROR, "Failed to Doing symlink for file %s to file %s \n", ri->rec.entry, ri->rec.link_path); @@ -1771,7 +1755,6 @@ apply_record(nsr_per_node_worker_t *ctx, if ((to_obj = create_obj(ctx, ri->rec.gfid)) == NULL) return _gf_false; if (glfs_h_link_with_xdata(ctx->fs, to_obj, obj, ri->rec.entry, dict) == -1) { - GF_ASSERT(0); nsr_worker_log(this->name, GF_LOG_ERROR, "Failed to Doing hard link for file %s to file %s \n", ri->rec.entry, ri->rec.gfid); @@ -1794,7 +1777,6 @@ apply_record(nsr_per_node_worker_t *ctx, if ((to_obj = create_obj(ctx, ri->rec.gfid)) == NULL) return _gf_false; if (glfs_h_rename_with_xdata(ctx->fs, obj, ri->rec.entry, to_obj, ri->rec.newloc, dict) == -1) { - GF_ASSERT(0); nsr_worker_log(this->name, GF_LOG_ERROR, "Failed to Doing rename for file %s to file %s \n", ri->rec.entry, ri->rec.newloc); @@ -1826,7 +1808,6 @@ apply_record(nsr_per_node_worker_t *ctx, else fd = glfs_h_open_with_xdata(ctx->fs, obj, O_RDWR, dict); if (fd == NULL) { - GF_ASSERT(0); nsr_worker_log(this->name, GF_LOG_ERROR, "open for file %s failed\n", ri->rec.gfid); @@ -1840,7 +1821,6 @@ apply_record(nsr_per_node_worker_t *ctx, // Set one special dict flag to indicate the opcode so that // the opcode gets set to this if (dict_set_int32(dict,"recon-attr-opcode",ri->rec.op)) { - GF_ASSERT(0); nsr_worker_log(this->name, GF_LOG_ERROR, "setting opcode to %d failed\n",ri->rec.op); return _gf_false; @@ -1848,7 +1828,6 @@ apply_record(nsr_per_node_worker_t *ctx, ret = glfs_fsetattr_with_xdata(fd, &iatt, valid, dict); if (ret == -1) { - GF_ASSERT(0); nsr_worker_log(this->name, GF_LOG_INFO, "failed Doing attr for file %s \n", ri->rec.gfid); @@ -1856,7 +1835,6 @@ apply_record(nsr_per_node_worker_t *ctx, } if (glfs_close_with_xdata(fd, dict) == -1) { - GF_ASSERT(0); nsr_worker_log(this->name, GF_LOG_ERROR, "close failed\n"); return _gf_false; @@ -1950,21 +1928,18 @@ data_worker_func(nsr_per_node_worker_t *ctx, dict = dict_new (); if (!dict) { ctx->result = -1; - GF_ASSERT(0); nsr_worker_log(this->name, GF_LOG_ERROR, "failed allocating for dictionary\n"); break; } if (dict_set_int32(dict,RECON_TERM_XATTR,ri->work.term)) { ctx->result = -1; - GF_ASSERT(0); nsr_worker_log(this->name, GF_LOG_ERROR, "error setting term in dict\n"); break; } if (dict_set_int32(dict,RECON_INDEX_XATTR,ri->work.index)) { ctx->result = -1; - GF_ASSERT(0); nsr_worker_log(this->name, GF_LOG_ERROR, "error setting term in dict\n"); break; @@ -2004,7 +1979,6 @@ data_worker_func(nsr_per_node_worker_t *ctx, if (glfs_lseek_with_xdata (fd, rd->offset, SEEK_SET, dict) != rd->offset) { - GF_ASSERT(0); nsr_worker_log(this->name, GF_LOG_ERROR, "lseek of file failed to offset %d\n", rd->offset); @@ -2015,7 +1989,6 @@ data_worker_func(nsr_per_node_worker_t *ctx, gf_mt_recon_private_t); if (glfs_read_with_xdata (fd, ri->work.data, rd->len, 0, dict) != rd->len) { - GF_ASSERT(0); nsr_worker_log(this->name, GF_LOG_ERROR, "read of file failed to offset %d for bytes %d\n", rd->offset, rd->len); @@ -2084,7 +2057,6 @@ data_worker_func(nsr_per_node_worker_t *ctx, if (get_xattr_total_size (fd, &t_b, &k_s, &v_s, &num, dict) == -1) { if (t_b) free(t_b); - GF_ASSERT(0); nsr_worker_log(this->name, GF_LOG_ERROR, "list of xattr of gfid %s failed\n", rd->gfid); @@ -2093,7 +2065,6 @@ data_worker_func(nsr_per_node_worker_t *ctx, ri->work.data = GF_CALLOC ((k_s + v_s) , sizeof(char), gf_mt_recon_private_t); if (get_xattr(fd, t_b, ri->work.data, v_s, num, dict) == -1) { - GF_ASSERT(0); nsr_worker_log(this->name, GF_LOG_ERROR, "get xattr of gfid %s failed\n", rd->gfid); break; @@ -2134,21 +2105,18 @@ data_worker_func(nsr_per_node_worker_t *ctx, dict = dict_new (); if (!dict) { ctx->result = -1; - GF_ASSERT(0); nsr_worker_log(this->name, GF_LOG_ERROR, "failed allocating for dictionary\n"); break; } if (dict_set_int32(dict,RECON_TERM_XATTR,ri->work.term)) { ctx->result = -1; - GF_ASSERT(0); nsr_worker_log(this->name, GF_LOG_ERROR, "error setting term in dict\n"); break; } if (dict_set_int32(dict,RECON_INDEX_XATTR,ri->work.index)) { ctx->result = -1; - GF_ASSERT(0); nsr_worker_log(this->name, GF_LOG_ERROR, "error setting term in dict\n"); break; @@ -2167,21 +2135,18 @@ data_worker_func(nsr_per_node_worker_t *ctx, dict = dict_new (); if (!dict) { ctx->result = -1; - GF_ASSERT(0); nsr_worker_log(this->name, GF_LOG_ERROR, "failed allocating for dictionary\n"); break; } if (dict_set_int32(dict,RECON_TERM_XATTR,ri->work.term)) { ctx->result = -1; - GF_ASSERT(0); nsr_worker_log(this->name, GF_LOG_ERROR, "error setting term in dict\n"); break; } if (dict_set_int32(dict,RECON_INDEX_XATTR,ri->work.index)) { ctx->result = -1; - GF_ASSERT(0); nsr_worker_log(this->name, GF_LOG_ERROR, "error setting term in dict\n"); break; diff --git a/xlators/cluster/nsr-recon/src/recon_xlator.c b/xlators/cluster/nsr-recon/src/recon_xlator.c index 868377bd2..c58260cf0 100644 --- a/xlators/cluster/nsr-recon/src/recon_xlator.c +++ b/xlators/cluster/nsr-recon/src/recon_xlator.c @@ -807,6 +807,26 @@ nsr_recon_flush (call_frame_t *frame, xlator_t *this, return 0; } + +int32_t +mem_acct_init (xlator_t *this) +{ + int ret = -1; + + GF_VALIDATE_OR_GOTO ("recon", this, out); + + ret = xlator_mem_acct_init (this, gf_mt_recon_end + 1); + + if (ret != 0) { + gf_log (this->name, GF_LOG_ERROR, + "Memory accounting init" "failed"); + return ret; + } +out: + return ret; +} + + int32_t init (xlator_t *this) { diff --git a/xlators/cluster/nsr-recon/src/recon_xlator.h b/xlators/cluster/nsr-recon/src/recon_xlator.h index c92489db1..57c44cca2 100644 --- a/xlators/cluster/nsr-recon/src/recon_xlator.h +++ b/xlators/cluster/nsr-recon/src/recon_xlator.h @@ -16,6 +16,7 @@ enum gf_dht_mem_types_ { gf_mt_recon_private_t = gf_common_mt_end + 1, + gf_mt_recon_end, }; enum nsr_recon_xlator_sector_t { diff --git a/xlators/cluster/nsr-server/src/nsr.c b/xlators/cluster/nsr-server/src/nsr.c index 9f2338148..a60589959 100644 --- a/xlators/cluster/nsr-server/src/nsr.c +++ b/xlators/cluster/nsr-server/src/nsr.c @@ -479,6 +479,25 @@ nsr_notify (xlator_t *this, int event, void *data, ...) } +int32_t +mem_acct_init (xlator_t *this) +{ + int ret = -1; + + GF_VALIDATE_OR_GOTO ("nsr", this, out); + + ret = xlator_mem_acct_init (this, gf_mt_nsr_end + 1); + + if (ret != 0) { + gf_log (this->name, GF_LOG_ERROR, + "Memory accounting init" "failed"); + return ret; + } +out: + return ret; +} + + extern void *nsr_leader_thread (void *); int32_t -- cgit