From 2d1249ff41af03acc58d12709d6910313979cd43 Mon Sep 17 00:00:00 2001 From: Andrew Deason Date: Thu, 29 Sep 2011 15:22:35 -0500 Subject: [PATCH] DAFS: Add explicit 'valid' field for index maps The CB, FE, and host serialization structures were just using the relevant indices to determine whether or not an entry mapping and old index to a new index was populated with actual data. For host structures, this really isn't sufficient, since our index can be 0, and the structure is calloc'd, so the index in the structure could also be 0. Add a flag explicitly stating whether or not the structure has been filled in, to make this unambiguous. Reviewed-on: http://gerrit.openafs.org/5526 Tested-by: BuildBot Reviewed-by: Derrick Brashear (cherry picked from commit d54a9994d362ce3f287fe786839ec72f6d94806c) Change-Id: I0bd3e50dec4e686acc3e9cda3eef7b7909266f27 Reviewed-on: http://gerrit.openafs.org/5544 Tested-by: BuildBot Reviewed-by: Derrick Brashear --- src/tviced/serialize_state.h | 4 ++++ src/viced/callback.c | 8 ++++++-- src/viced/host.c | 4 +++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/tviced/serialize_state.h b/src/tviced/serialize_state.h index b213518bb..6478e714e 100644 --- a/src/tviced/serialize_state.h +++ b/src/tviced/serialize_state.h @@ -39,6 +39,9 @@ #define HOST_STATE_VALID_WINDOW 1800 /* 30 minutes */ +/* values for the 'valid' field in idx_map_entry_t */ +#define FS_STATE_IDX_VALID 1 + /* * on-disk structures */ @@ -205,6 +208,7 @@ struct AVDiskEntry { * dump runtime state */ struct idx_map_entry_t { + byte valid; /* whether or not this entry has been populated */ afs_uint32 old_idx; /* host hash id from last runtime */ afs_uint32 new_idx; /* host hash id for this runtime */ }; diff --git a/src/viced/callback.c b/src/viced/callback.c index e7d85fa8c..8e2d2ad75 100644 --- a/src/viced/callback.c +++ b/src/viced/callback.c @@ -2526,6 +2526,7 @@ cb_stateDiskEntryToFE(struct fs_dump_state * state, ret = 1; goto done; } + state->fe_map.entries[in->index].valid = FS_STATE_IDX_VALID; state->fe_map.entries[in->index].old_idx = in->index; state->fe_map.entries[in->index].new_idx = fetoi(out); @@ -2556,6 +2557,7 @@ cb_stateDiskEntryToCB(struct fs_dump_state * state, ret = 1; goto done; } + state->cb_map.entries[in->index].valid = FS_STATE_IDX_VALID; state->cb_map.entries[in->index].old_idx = in->index; state->cb_map.entries[in->index].new_idx = cbtoi(out); @@ -2590,7 +2592,8 @@ fe_OldToNew(struct fs_dump_state * state, afs_uint32 old, afs_uint32 * new) if (old >= state->fe_map.len) { ViceLog(0, ("fe_OldToNew: index %d is out of range\n", old)); ret = 1; - } else if (state->fe_map.entries[old].old_idx != old) { /* sanity check */ + } else if (state->fe_map.entries[old].valid != FS_STATE_IDX_VALID || + state->fe_map.entries[old].old_idx != old) { /* sanity check */ ViceLog(0, ("fe_OldToNew: index %d points to an invalid FileEntry record\n", old)); ret = 1; } else { @@ -2615,7 +2618,8 @@ cb_OldToNew(struct fs_dump_state * state, afs_uint32 old, afs_uint32 * new) if (old >= state->cb_map.len) { ViceLog(0, ("cb_OldToNew: index %d is out of range\n", old)); ret = 1; - } else if (state->cb_map.entries[old].old_idx != old) { /* sanity check */ + } else if (state->cb_map.entries[old].valid != FS_STATE_IDX_VALID || + state->cb_map.entries[old].old_idx != old) { /* sanity check */ ViceLog(0, ("cb_OldToNew: index %d points to an invalid CallBack record\n", old)); ret = 1; } else { diff --git a/src/viced/host.c b/src/viced/host.c index 6897a8768..65e54d321 100644 --- a/src/viced/host.c +++ b/src/viced/host.c @@ -3416,6 +3416,7 @@ h_stateRestoreHost(struct fs_dump_state * state) h_InsertList_r(host); /* setup host id map entry */ + state->h_map.entries[hdsk.index].valid = FS_STATE_IDX_VALID; state->h_map.entries[hdsk.index].old_idx = hdsk.index; state->h_map.entries[hdsk.index].new_idx = host->index; @@ -3481,7 +3482,8 @@ h_OldToNew(struct fs_dump_state * state, afs_uint32 old, afs_uint32 * new) if (old >= state->h_map.len) { ViceLog(0, ("h_OldToNew: index %d is out of range\n", old)); ret = 1; - } else if (state->h_map.entries[old].old_idx != old) { /* sanity check */ + } else if (state->h_map.entries[old].valid != FS_STATE_IDX_VALID || + state->h_map.entries[old].old_idx != old) { /* sanity check */ ViceLog(0, ("h_OldToNew: index %d points to an invalid host record\n", old)); ret = 1; } else { -- 2.39.5