18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci  drbd.h
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci  This file is part of DRBD by Philipp Reisner and Lars Ellenberg.
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci  Copyright (C) 2003-2008, LINBIT Information Technologies GmbH.
88c2ecf20Sopenharmony_ci  Copyright (C) 2003-2008, Philipp Reisner <philipp.reisner@linbit.com>.
98c2ecf20Sopenharmony_ci  Copyright (C) 2003-2008, Lars Ellenberg <lars.ellenberg@linbit.com>.
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci*/
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci#include <linux/drbd.h>
158c2ecf20Sopenharmony_ci#include "drbd_strings.h"
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_cistatic const char * const drbd_conn_s_names[] = {
188c2ecf20Sopenharmony_ci	[C_STANDALONE]       = "StandAlone",
198c2ecf20Sopenharmony_ci	[C_DISCONNECTING]    = "Disconnecting",
208c2ecf20Sopenharmony_ci	[C_UNCONNECTED]      = "Unconnected",
218c2ecf20Sopenharmony_ci	[C_TIMEOUT]          = "Timeout",
228c2ecf20Sopenharmony_ci	[C_BROKEN_PIPE]      = "BrokenPipe",
238c2ecf20Sopenharmony_ci	[C_NETWORK_FAILURE]  = "NetworkFailure",
248c2ecf20Sopenharmony_ci	[C_PROTOCOL_ERROR]   = "ProtocolError",
258c2ecf20Sopenharmony_ci	[C_WF_CONNECTION]    = "WFConnection",
268c2ecf20Sopenharmony_ci	[C_WF_REPORT_PARAMS] = "WFReportParams",
278c2ecf20Sopenharmony_ci	[C_TEAR_DOWN]        = "TearDown",
288c2ecf20Sopenharmony_ci	[C_CONNECTED]        = "Connected",
298c2ecf20Sopenharmony_ci	[C_STARTING_SYNC_S]  = "StartingSyncS",
308c2ecf20Sopenharmony_ci	[C_STARTING_SYNC_T]  = "StartingSyncT",
318c2ecf20Sopenharmony_ci	[C_WF_BITMAP_S]      = "WFBitMapS",
328c2ecf20Sopenharmony_ci	[C_WF_BITMAP_T]      = "WFBitMapT",
338c2ecf20Sopenharmony_ci	[C_WF_SYNC_UUID]     = "WFSyncUUID",
348c2ecf20Sopenharmony_ci	[C_SYNC_SOURCE]      = "SyncSource",
358c2ecf20Sopenharmony_ci	[C_SYNC_TARGET]      = "SyncTarget",
368c2ecf20Sopenharmony_ci	[C_PAUSED_SYNC_S]    = "PausedSyncS",
378c2ecf20Sopenharmony_ci	[C_PAUSED_SYNC_T]    = "PausedSyncT",
388c2ecf20Sopenharmony_ci	[C_VERIFY_S]         = "VerifyS",
398c2ecf20Sopenharmony_ci	[C_VERIFY_T]         = "VerifyT",
408c2ecf20Sopenharmony_ci	[C_AHEAD]            = "Ahead",
418c2ecf20Sopenharmony_ci	[C_BEHIND]           = "Behind",
428c2ecf20Sopenharmony_ci};
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_cistatic const char * const drbd_role_s_names[] = {
458c2ecf20Sopenharmony_ci	[R_PRIMARY]   = "Primary",
468c2ecf20Sopenharmony_ci	[R_SECONDARY] = "Secondary",
478c2ecf20Sopenharmony_ci	[R_UNKNOWN]   = "Unknown"
488c2ecf20Sopenharmony_ci};
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_cistatic const char * const drbd_disk_s_names[] = {
518c2ecf20Sopenharmony_ci	[D_DISKLESS]     = "Diskless",
528c2ecf20Sopenharmony_ci	[D_ATTACHING]    = "Attaching",
538c2ecf20Sopenharmony_ci	[D_FAILED]       = "Failed",
548c2ecf20Sopenharmony_ci	[D_NEGOTIATING]  = "Negotiating",
558c2ecf20Sopenharmony_ci	[D_INCONSISTENT] = "Inconsistent",
568c2ecf20Sopenharmony_ci	[D_OUTDATED]     = "Outdated",
578c2ecf20Sopenharmony_ci	[D_UNKNOWN]      = "DUnknown",
588c2ecf20Sopenharmony_ci	[D_CONSISTENT]   = "Consistent",
598c2ecf20Sopenharmony_ci	[D_UP_TO_DATE]   = "UpToDate",
608c2ecf20Sopenharmony_ci};
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_cistatic const char * const drbd_state_sw_errors[] = {
638c2ecf20Sopenharmony_ci	[-SS_TWO_PRIMARIES] = "Multiple primaries not allowed by config",
648c2ecf20Sopenharmony_ci	[-SS_NO_UP_TO_DATE_DISK] = "Need access to UpToDate data",
658c2ecf20Sopenharmony_ci	[-SS_NO_LOCAL_DISK] = "Can not resync without local disk",
668c2ecf20Sopenharmony_ci	[-SS_NO_REMOTE_DISK] = "Can not resync without remote disk",
678c2ecf20Sopenharmony_ci	[-SS_CONNECTED_OUTDATES] = "Refusing to be Outdated while Connected",
688c2ecf20Sopenharmony_ci	[-SS_PRIMARY_NOP] = "Refusing to be Primary while peer is not outdated",
698c2ecf20Sopenharmony_ci	[-SS_RESYNC_RUNNING] = "Can not start OV/resync since it is already active",
708c2ecf20Sopenharmony_ci	[-SS_ALREADY_STANDALONE] = "Can not disconnect a StandAlone device",
718c2ecf20Sopenharmony_ci	[-SS_CW_FAILED_BY_PEER] = "State change was refused by peer node",
728c2ecf20Sopenharmony_ci	[-SS_IS_DISKLESS] = "Device is diskless, the requested operation requires a disk",
738c2ecf20Sopenharmony_ci	[-SS_DEVICE_IN_USE] = "Device is held open by someone",
748c2ecf20Sopenharmony_ci	[-SS_NO_NET_CONFIG] = "Have no net/connection configuration",
758c2ecf20Sopenharmony_ci	[-SS_NO_VERIFY_ALG] = "Need a verify algorithm to start online verify",
768c2ecf20Sopenharmony_ci	[-SS_NEED_CONNECTION] = "Need a connection to start verify or resync",
778c2ecf20Sopenharmony_ci	[-SS_NOT_SUPPORTED] = "Peer does not support protocol",
788c2ecf20Sopenharmony_ci	[-SS_LOWER_THAN_OUTDATED] = "Disk state is lower than outdated",
798c2ecf20Sopenharmony_ci	[-SS_IN_TRANSIENT_STATE] = "In transient state, retry after next state change",
808c2ecf20Sopenharmony_ci	[-SS_CONCURRENT_ST_CHG] = "Concurrent state changes detected and aborted",
818c2ecf20Sopenharmony_ci	[-SS_OUTDATE_WO_CONN] = "Need a connection for a graceful disconnect/outdate peer",
828c2ecf20Sopenharmony_ci	[-SS_O_VOL_PEER_PRI] = "Other vol primary on peer not allowed by config",
838c2ecf20Sopenharmony_ci};
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_ciconst char *drbd_conn_str(enum drbd_conns s)
868c2ecf20Sopenharmony_ci{
878c2ecf20Sopenharmony_ci	/* enums are unsigned... */
888c2ecf20Sopenharmony_ci	return s > C_BEHIND ? "TOO_LARGE" : drbd_conn_s_names[s];
898c2ecf20Sopenharmony_ci}
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ciconst char *drbd_role_str(enum drbd_role s)
928c2ecf20Sopenharmony_ci{
938c2ecf20Sopenharmony_ci	return s > R_SECONDARY   ? "TOO_LARGE" : drbd_role_s_names[s];
948c2ecf20Sopenharmony_ci}
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_ciconst char *drbd_disk_str(enum drbd_disk_state s)
978c2ecf20Sopenharmony_ci{
988c2ecf20Sopenharmony_ci	return s > D_UP_TO_DATE    ? "TOO_LARGE" : drbd_disk_s_names[s];
998c2ecf20Sopenharmony_ci}
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_ciconst char *drbd_set_st_err_str(enum drbd_state_rv err)
1028c2ecf20Sopenharmony_ci{
1038c2ecf20Sopenharmony_ci	return err <= SS_AFTER_LAST_ERROR ? "TOO_SMALL" :
1048c2ecf20Sopenharmony_ci	       err > SS_TWO_PRIMARIES ? "TOO_LARGE"
1058c2ecf20Sopenharmony_ci			: drbd_state_sw_errors[-err];
1068c2ecf20Sopenharmony_ci}
107