summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Darcy <jdarcy@redhat.com>2014-02-05 19:01:23 +0000
committerJeff Darcy <jdarcy@redhat.com>2014-02-11 13:59:54 +0000
commit33939dcde38389373e7ed8b12c6e9916b39411d0 (patch)
tree86d6e0207f2cf3419bb7ab0820a5cfed39683360
parent6f9bec28ea3a488111cda974ee6959bd86094f31 (diff)
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 <jdarcy@redhat.com>
-rw-r--r--xlators/cluster/nsr-recon/src/recon_driver.c4
-rw-r--r--xlators/cluster/nsr-recon/src/recon_driver.h1
-rw-r--r--xlators/cluster/nsr-recon/src/recon_xlator.c32
-rw-r--r--xlators/features/changelog/src/policy/changelog-policy-replication.c10
4 files changed, 45 insertions, 2 deletions
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);
diff --git a/xlators/features/changelog/src/policy/changelog-policy-replication.c b/xlators/features/changelog/src/policy/changelog-policy-replication.c
index 1f6a6140e..19492e2c6 100644
--- a/xlators/features/changelog/src/policy/changelog-policy-replication.c
+++ b/xlators/features/changelog/src/policy/changelog-policy-replication.c
@@ -500,8 +500,16 @@ changelog_replication_create (call_frame_t *frame, xlator_t *this,
CHANGELOG_FILL_ENTRY (co, loc->pargfid, loc->name,
entry_fn, entry_free_fn, xtra_len, out);
+ co++;
- changelog_set_usable_record_and_length (local, xtra_len, 4);
+ /*
+ * This isn't really kosher (we should have a similar but separate
+ * mode_fn) but it should do for now.
+ */
+ CHANGELOG_FILL_FOP_NUMBER (co, mode, fop_fn, xtra_len);
+ co++;
+
+ changelog_set_usable_record_and_length (local, xtra_len, 5);
frame->local = local;
ret = 0;