From d54a9994d362ce3f287fe786839ec72f6d94806c 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. Change-Id: Ia69e25fa73e10dc10cf3ddf08bb4feb2c9958674 Reviewed-on: http://gerrit.openafs.org/5526 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 b213518bb2..6478e714ea 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 d9b9b18667..4da7d73edf 100644 --- a/src/viced/callback.c +++ b/src/viced/callback.c @@ -2522,6 +2522,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); @@ -2552,6 +2553,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); @@ -2586,7 +2588,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 { @@ -2611,7 +2614,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 3d864a3031..7f94344193 100644 --- a/src/viced/host.c +++ b/src/viced/host.c @@ -3399,6 +3399,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; @@ -3464,7 +3465,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 {