Blame source/vdo/base/statusCodes.c

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