Blame source/vdo/base/statusCodes.c

Packit Service 75d76b
/*
Packit Service 75d76b
 * Copyright (c) 2020 Red Hat, Inc.
Packit Service 75d76b
 *
Packit Service 75d76b
 * This program is free software; you can redistribute it and/or
Packit Service 75d76b
 * modify it under the terms of the GNU General Public License
Packit Service 75d76b
 * as published by the Free Software Foundation; either version 2
Packit Service 75d76b
 * of the License, or (at your option) any later version.
Packit Service 75d76b
 * 
Packit Service 75d76b
 * This program is distributed in the hope that it will be useful,
Packit Service 75d76b
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 75d76b
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Service 75d76b
 * GNU General Public License for more details.
Packit Service 75d76b
 * 
Packit Service 75d76b
 * You should have received a copy of the GNU General Public License
Packit Service 75d76b
 * along with this program; if not, write to the Free Software
Packit Service 75d76b
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
Packit Service 75d76b
 * 02110-1301, USA. 
Packit Service 75d76b
 *
Packit Service 75d76b
 * $Id: //eng/vdo-releases/aluminum/src/c++/vdo/base/statusCodes.c#3 $
Packit Service 75d76b
 */
Packit Service 75d76b
Packit Service 75d76b
#include "statusCodes.h"
Packit Service 75d76b
Packit Service 75d76b
#include "errors.h"
Packit Service 75d76b
#include "permassert.h"
Packit Service 75d76b
#include "threadOnce.h"
Packit Service 75d76b
Packit Service 75d76b
const struct errorInfo vdoStatusList[] = {
Packit Service 75d76b
  { "VDO_NOT_IMPLEMENTED",       "Not implemented"                           },
Packit Service 75d76b
  { "VDO_OUT_OF_RANGE",          "Out of range"                              },
Packit Service 75d76b
  { "VDO_REF_COUNT_INVALID",     "Reference count would become invalid"      },
Packit Service 75d76b
  { "VDO_NO_SPACE",              "Out of space"                              },
Packit Service 75d76b
  { "VDO_UNEXPECTED_EOF",        "Unexpected EOF on block read"              },
Packit Service 75d76b
  { "VDO_BAD_CONFIGURATION",     "Bad configuration option"                  },
Packit Service 75d76b
  { "VDO_SOCKET_ERROR",          "Socket error"                              },
Packit Service 75d76b
  { "VDO_BAD_ALIGNMENT",         "Mis-aligned block reference"               },
Packit Service 75d76b
  { "VDO_COMPONENT_BUSY",        "Prior operation still in progress"         },
Packit Service 75d76b
  { "VDO_BAD_PAGE",              "Corrupt or incorrect page"                 },
Packit Service 75d76b
  { "VDO_UNSUPPORTED_VERSION",   "Unsupported component version"             },
Packit Service 75d76b
  { "VDO_INCORRECT_COMPONENT",   "Component id mismatch in decoder"          },
Packit Service 75d76b
  { "VDO_PARAMETER_MISMATCH",    "Parameters have conflicting values"        },
Packit Service 75d76b
  { "VDO_BLOCK_SIZE_TOO_SMALL",  "The block size is too small"               },
Packit Service 75d76b
  { "VDO_UNKNOWN_PARTITION",     "No partition exists with a given id"       },
Packit Service 75d76b
  { "VDO_PARTITION_EXISTS",      "A partition already exists with a given id"},
Packit Service 75d76b
  { "VDO_NOT_READ_ONLY",         "The device is not in read-only mode"       },
Packit Service 75d76b
  { "VDO_INCREMENT_TOO_SMALL",   "Physical block growth of too few blocks"   },
Packit Service 75d76b
  { "VDO_CHECKSUM_MISMATCH",     "Incorrect checksum"                        },
Packit Service 75d76b
  { "VDO_RECOVERY_JOURNAL_FULL", "The recovery journal is full"              },
Packit Service 75d76b
  { "VDO_LOCK_ERROR",            "A lock is held incorrectly"                },
Packit Service 75d76b
  { "VDO_READ_ONLY",             "The device is in read-only mode"           },
Packit Service 75d76b
  { "VDO_SHUTTING_DOWN",         "The device is shutting down"               },
Packit Service 75d76b
  { "VDO_CORRUPT_JOURNAL",       "Recovery journal entries corrupted"        },
Packit Service 75d76b
  { "VDO_TOO_MANY_SLABS",        "Exceeds maximum number of slabs supported" },
Packit Service 75d76b
  { "VDO_INVALID_FRAGMENT",      "Compressed block fragment is invalid"      },
Packit Service 75d76b
  { "VDO_RETRY_AFTER_REBUILD",   "Retry operation after rebuilding finishes" },
Packit Service 75d76b
  { "VDO_UNKNOWN_COMMAND",       "The extended command is not known"         },
Packit Service 75d76b
  { "VDO_COMMAND_ERROR",         "Bad extended command parameters"           },
Packit Service 75d76b
  { "VDO_CANNOT_DETERMINE_SIZE", "Cannot determine config sizes to fit"      },
Packit Service 75d76b
  { "VDO_BAD_MAPPING",           "Invalid page mapping"                      },
Packit Service 75d76b
  { "VDO_READ_CACHE_BUSY",       "Read cache has no free slots"              },
Packit Service 75d76b
  { "VDO_BIO_CREATION_FAILED",   "Bio creation failed"                       },
Packit Service 75d76b
  { "VDO_BAD_MAGIC",             "Bad magic number"                          },
Packit Service 75d76b
  { "VDO_BAD_NONCE",             "Bad nonce"                                 },
Packit Service 75d76b
  { "VDO_JOURNAL_OVERFLOW",      "Journal sequence number overflow"          },
Packit Service 75d76b
  { "VDO_INVALID_ADMIN_STATE",   "Invalid operation for current state"       },
Packit Service 75d76b
};
Packit Service 75d76b
Packit Service 75d76b
#ifndef __KERNEL__
Packit Service 75d76b
static OnceState vdoStatusCodesRegistered = ONCE_STATE_INITIALIZER;
Packit Service 75d76b
static int       statusCodeRegistrationResult;
Packit Service 75d76b
Packit Service 75d76b
/**********************************************************************/
Packit Service 75d76b
static void doStatusCodeRegistration(void)
Packit Service 75d76b
{
Packit Service 75d76b
  STATIC_ASSERT((VDO_STATUS_CODE_LAST - VDO_STATUS_CODE_BASE)
Packit Service 75d76b
                == COUNT_OF(vdoStatusList));
Packit Service 75d76b
Packit Service 75d76b
  int result = registerErrorBlock("VDO Status",
Packit Service 75d76b
                                  VDO_STATUS_CODE_BASE,
Packit Service 75d76b
                                  VDO_STATUS_CODE_BLOCK_END,
Packit Service 75d76b
                                  vdoStatusList,
Packit Service 75d76b
                                  sizeof(vdoStatusList));
Packit Service 75d76b
  /*
Packit Service 75d76b
   *  The following test handles cases where libvdo is statically linked
Packit Service 75d76b
   *  against both the test modules and the test driver (because multiple
Packit Service 75d76b
   *  instances of this module call their own copy of this function
Packit Service 75d76b
   *  once each, resulting in multiple calls to registerErrorBlock which
Packit Service 75d76b
   *  is shared in libuds).
Packit Service 75d76b
   */
Packit Service 75d76b
  if (result == UDS_DUPLICATE_NAME) {
Packit Service 75d76b
    result = UDS_SUCCESS;
Packit Service 75d76b
  }
Packit Service 75d76b
Packit Service 75d76b
  statusCodeRegistrationResult
Packit Service 75d76b
    = (result == UDS_SUCCESS) ? VDO_SUCCESS : result;
Packit Service 75d76b
}
Packit Service 75d76b
#endif
Packit Service 75d76b
Packit Service 75d76b
/**********************************************************************/
Packit Service 75d76b
int registerStatusCodes(void)
Packit Service 75d76b
{
Packit Service 75d76b
#ifdef __KERNEL__
Packit Service 75d76b
  return VDO_SUCCESS;
Packit Service 75d76b
#else
Packit Service 75d76b
  performOnce(&vdoStatusCodesRegistered, doStatusCodeRegistration);
Packit Service 75d76b
  return statusCodeRegistrationResult;
Packit Service 75d76b
#endif
Packit Service 75d76b
}