From 33939dcde38389373e7ed8b12c6e9916b39411d0 Mon Sep 17 00:00:00 2001 From: Jeff Darcy Date: Wed, 5 Feb 2014 19:01:23 +0000 Subject: Example of how to add extra info to changelog records. This is a bit hacky so far, but this is the direction we need to go for all fops that take extra data like modes, uids, times, or keys. Change-Id: I02968611bc46beda108b4caf65cd6a8928679e16 Signed-off-by: Jeff Darcy --- xlators/cluster/nsr-recon/src/recon_driver.c | 4 +++- xlators/cluster/nsr-recon/src/recon_driver.h | 1 + xlators/cluster/nsr-recon/src/recon_xlator.c | 32 ++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) (limited to 'xlators/cluster') diff --git a/xlators/cluster/nsr-recon/src/recon_driver.c b/xlators/cluster/nsr-recon/src/recon_driver.c index 00e79b9d3..778f59413 100644 --- a/xlators/cluster/nsr-recon/src/recon_driver.c +++ b/xlators/cluster/nsr-recon/src/recon_driver.c @@ -1535,7 +1535,9 @@ apply_record(nsr_per_node_worker_t *ctx, uuid_parse(ri->rec.gfid, gfid); if ((obj = create_obj(ctx, ri->rec.pargfid)) == NULL) return; - if (glfs_h_creat_with_xdata(ctx->fs, obj, ri->rec.entry, O_RDWR, 0777, NULL, gfid, dict) == NULL) { + 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", diff --git a/xlators/cluster/nsr-recon/src/recon_driver.h b/xlators/cluster/nsr-recon/src/recon_driver.h index 47852f225..096ca88b5 100644 --- a/xlators/cluster/nsr-recon/src/recon_driver.h +++ b/xlators/cluster/nsr-recon/src/recon_driver.h @@ -166,6 +166,7 @@ typedef struct nsr_recon_record_details_s { uint32_t len; char entry[128]; char newloc[128]; // for rename. can you overload link_path for this? TBD + mode_t mode; } nsr_recon_record_details_t; #pragma pack(pop) diff --git a/xlators/cluster/nsr-recon/src/recon_xlator.c b/xlators/cluster/nsr-recon/src/recon_xlator.c index da14aab93..0c140d8d6 100644 --- a/xlators/cluster/nsr-recon/src/recon_xlator.c +++ b/xlators/cluster/nsr-recon/src/recon_xlator.c @@ -272,6 +272,23 @@ get_link_using_gfid(nsr_recon_private_t *priv, char *gfid, char *path) } // Get the list of changelog records given a term , first and last index. +// +// TBD: rewrite this hideous ball of mud in at least the following ways: +// +// (1) Break out the code for handling a single record into a separate +// function, to make error handling easier and reduce "indentation +// creep" so the code's readable. +// +// (2) Change all of the fop_xxx_yyy nonsense to OR together values +// like FOP_HAS_FIELD_XXX and FOP_HAS_FIELD_YYY, to reduce code +// duplication and facilitate the addition of new fields. +// +// (3) Stop making so many assumptions about the underlying formats. +// The code as it is won't even work for the existing binary format, +// let alone as changelog evolves over time. +// +// Really, 90% of this code should just GO AWAY in favor of using +// libgfchangelog, enhanced as necessary to support our needs. void nsr_recon_libchangelog_get_records(xlator_t *this, char *bp, int32_t term, uint32_t first, uint32_t last, void *buf) { // do a mmap; seek into the first and read all records till last. @@ -438,6 +455,21 @@ void nsr_recon_libchangelog_get_records(xlator_t *this, char *bp, int32_t term, rec->entry[i] = '\0'; // get over the 0 start++; + /* + * Having to add this as a special case + * is awful. See the function header + * comment for the real solution. + */ + if (opcode == GF_FOP_CREATE) { + rec->mode = 0; + while (*start != '\0') { + rec->mode *= 10; + rec->mode += *start + - '0'; + ++start; + } + ++start; + } recon_main_log (this->name, GF_LOG_ERROR, "libchangelog_get_records:got entry %s @index %d \n", rec->entry, index); -- cgit