[sheepdog] [PATCH 1/3] add missing result codes to sd_strerror
MORITA Kazutaka
morita.kazutaka at lab.ntt.co.jp
Wed May 1 18:57:51 CEST 2013
This also uses array to look up the error message for a bit better
performance.
Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
include/sheep.h | 99 ++++++++++++++++++++++++++++++---------------------------
1 file changed, 52 insertions(+), 47 deletions(-)
diff --git a/include/sheep.h b/include/sheep.h
index 72d50a9..8ba4bbb 100644
--- a/include/sheep.h
+++ b/include/sheep.h
@@ -175,56 +175,61 @@ static inline void oid_to_nodes(const struct sd_vnode *entries, int nr_entries,
static inline const char *sd_strerror(int err)
{
- int i;
-
- static const struct {
- int err;
- const char *desc;
- } errors[] = {
- {SD_RES_SUCCESS, "Success"},
- {SD_RES_UNKNOWN, "Unknown error"},
- {SD_RES_NO_OBJ, "No object found"},
- {SD_RES_EIO, "I/O error"},
- {SD_RES_VDI_EXIST, "VDI exists already"},
- {SD_RES_INVALID_PARMS, "Invalid parameters"},
- {SD_RES_SYSTEM_ERROR, "System error"},
- {SD_RES_VDI_LOCKED, "VDI is already locked"},
- {SD_RES_NO_VDI, "No VDI found"},
- {SD_RES_NO_BASE_VDI, "No base VDI found"},
- {SD_RES_VDI_READ, "Failed to read from requested VDI"},
- {SD_RES_VDI_WRITE, "Failed to write to requested VDI"},
- {SD_RES_BASE_VDI_READ, "Failed to read from base VDI"},
- {SD_RES_BASE_VDI_WRITE, "Failed to write to base VDI"},
- {SD_RES_NO_TAG, "Failed to find requested tag"},
- {SD_RES_STARTUP, "System is still booting"},
- {SD_RES_VDI_NOT_LOCKED, "VDI is not locked"},
- {SD_RES_SHUTDOWN, "System is shutting down"},
- {SD_RES_NO_MEM, "Out of memory on server"},
- {SD_RES_FULL_VDI, "Maximum number of VDIs reached"},
- {SD_RES_VER_MISMATCH, "Protocol version mismatch"},
- {SD_RES_NO_SPACE, "Server has no space for new objects"},
- {SD_RES_WAIT_FOR_FORMAT, "Waiting for cluster to be formatted"},
- {SD_RES_WAIT_FOR_JOIN, "Waiting for other nodes to join cluster"},
- {SD_RES_JOIN_FAILED, "Node has failed to join cluster"},
- {SD_RES_HALT, "IO has halted as there are too few living nodes"},
- {SD_RES_READONLY, "Object is read-only"},
- {SD_RES_FORCE_RECOVER, "Cluster is running/halted and cannot be force recovered"},
- {SD_RES_NO_STORE, "Targeted backend store is not found"},
- {SD_RES_NO_SUPPORT, "Operation is not supported"},
- {SD_RES_NODE_IN_RECOVERY, "Targeted node is in recovery"},
-
- {SD_RES_OLD_NODE_VER, "Remote node has an old epoch"},
- {SD_RES_NEW_NODE_VER, "Remote node has a new epoch"},
- {SD_RES_NOT_FORMATTED, "Cluster has not been formatted"},
- {SD_RES_INVALID_CTIME, "Creation times differ"},
- {SD_RES_INVALID_EPOCH, "Invalid epoch"},
+ static const char *descs[256] = {
+ /* from sheepdog_proto.h */
+ [SD_RES_SUCCESS] = "Success",
+ [SD_RES_UNKNOWN] = "Unknown error",
+ [SD_RES_NO_OBJ] = "No object found",
+ [SD_RES_EIO] = "I/O error",
+ [SD_RES_VDI_EXIST] = "VDI exists already",
+ [SD_RES_INVALID_PARMS] = "Invalid parameters",
+ [SD_RES_SYSTEM_ERROR] = "System error",
+ [SD_RES_VDI_LOCKED] = "VDI is already locked",
+ [SD_RES_NO_VDI] = "No VDI found",
+ [SD_RES_NO_BASE_VDI] = "No base VDI found",
+ [SD_RES_VDI_READ] = "Failed to read from requested VDI",
+ [SD_RES_VDI_WRITE] = "Failed to write to requested VDI",
+ [SD_RES_BASE_VDI_READ] = "Failed to read from base VDI",
+ [SD_RES_BASE_VDI_WRITE] = "Failed to write to base VDI",
+ [SD_RES_NO_TAG] = "Failed to find requested tag",
+ [SD_RES_STARTUP] = "System is still booting",
+ [SD_RES_VDI_NOT_LOCKED] = "VDI is not locked",
+ [SD_RES_SHUTDOWN] = "System is shutting down",
+ [SD_RES_NO_MEM] = "Out of memory on server",
+ [SD_RES_FULL_VDI] = "Maximum number of VDIs reached",
+ [SD_RES_VER_MISMATCH] = "Protocol version mismatch",
+ [SD_RES_NO_SPACE] = "Server has no space for new objects",
+ [SD_RES_WAIT_FOR_FORMAT] = "Waiting for cluster to be formatted",
+ [SD_RES_WAIT_FOR_JOIN] = "Waiting for other nodes to join cluster",
+ [SD_RES_JOIN_FAILED] = "Node has failed to join cluster",
+ [SD_RES_HALT] = "IO has halted as there are too few living nodes",
+ [SD_RES_READONLY] = "Object is read-only",
+
+ /* from internal_proto.h */
+ [SD_RES_OLD_NODE_VER] = "Remote node has an old epoch",
+ [SD_RES_NEW_NODE_VER] = "Remote node has a new epoch",
+ [SD_RES_NOT_FORMATTED] = "Cluster has not been formatted",
+ [SD_RES_INVALID_CTIME] = "Creation times differ",
+ [SD_RES_INVALID_EPOCH] = "Invalid epoch",
+ [SD_RES_NETWORK_ERROR] = "Network error between sheep",
+ [SD_RES_NO_CACHE] = "No cache object found",
+ [SD_RES_BUFFER_SMALL] = "The buffer is too small",
+ [SD_RES_FORCE_RECOVER] = "Cluster is running/halted and cannot be force recovered",
+ [SD_RES_NO_STORE] = "Targeted backend store is not found",
+ [SD_RES_NO_SUPPORT] = "Operation is not supported",
+ [SD_RES_NODE_IN_RECOVERY] = "Targeted node is in recovery",
+ [SD_RES_KILLED] = "Node is killed",
+ [SD_RES_OID_EXIST] = "Object ID exists already",
+ [SD_RES_AGAIN] = "Ask to try again",
};
- for (i = 0; i < ARRAY_SIZE(errors); ++i)
- if (errors[i].err == err)
- return errors[i].desc;
+ if (descs[err] == NULL) {
+ static __thread char msg[32];
+ snprintf(msg, sizeof(msg), "Invalid error code %x", err);
+ return msg;
+ }
- return "Invalid error code";
+ return descs[err];
}
static inline int node_id_cmp(const void *a, const void *b)
--
1.8.1.3.566.gaa39828
More information about the sheepdog
mailing list