Blame source/vdo/base/vdoState.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/vdoState.c#1 $
Packit Service d40955
 */
Packit Service d40955
Packit Service d40955
#include "vdoState.h"
Packit Service d40955
Packit Service d40955
#include "permassert.h"
Packit Service d40955
Packit Service d40955
static const char *VDO_STATE_NAMES[] = {
Packit Service d40955
  [VDO_CLEAN]               = "CLEAN",
Packit Service d40955
  [VDO_DIRTY]               = "DIRTY",
Packit Service d40955
  [VDO_FORCE_REBUILD]       = "FORCE_REBUILD",
Packit Service d40955
  [VDO_NEW]                 = "NEW",
Packit Service d40955
  [VDO_READ_ONLY_MODE]      = "READ_ONLY_MODE",
Packit Service d40955
  [VDO_REBUILD_FOR_UPGRADE] = "REBUILD_FOR_UPGRADE",
Packit Service d40955
  [VDO_RECOVERING]          = "RECOVERING",
Packit Service d40955
  [VDO_REPLAYING]           = "REPLAYING",
Packit Service d40955
};
Packit Service d40955
Packit Service d40955
/**********************************************************************/
Packit Service d40955
const char *getVDOStateName(VDOState state)
Packit Service d40955
{
Packit Service d40955
  // Catch if a state has been added without updating the name array.
Packit Service d40955
  STATIC_ASSERT(COUNT_OF(VDO_STATE_NAMES) == VDO_STATE_COUNT);
Packit Service d40955
Packit Service d40955
  int result = ASSERT(state < COUNT_OF(VDO_STATE_NAMES),
Packit Service d40955
                      "VDOState value %u must have a registered name", state);
Packit Service d40955
  if (result != UDS_SUCCESS) {
Packit Service d40955
    return "INVALID VDO STATE CODE";
Packit Service d40955
  }
Packit Service d40955
Packit Service d40955
  return VDO_STATE_NAMES[state];
Packit Service d40955
}
Packit Service d40955
Packit Service d40955
/**********************************************************************/
Packit Service d40955
const char *describeVDOState(VDOState state)
Packit Service d40955
{
Packit Service d40955
  // These strings should all fit in the 15 chars of VDOStatistics.mode.
Packit Service d40955
  switch (state) {
Packit Service d40955
  case VDO_RECOVERING:
Packit Service d40955
    return "recovering";
Packit Service d40955
Packit Service d40955
  case VDO_READ_ONLY_MODE:
Packit Service d40955
    return "read-only";
Packit Service d40955
Packit Service d40955
  default:
Packit Service d40955
    return "normal";
Packit Service d40955
  }
Packit Service d40955
}