PostgreSQL Source Code  git master
basebackup_target.c File Reference
#include "postgres.h"
#include "backup/basebackup_target.h"
#include "utils/memutils.h"
Include dependency graph for basebackup_target.c:

Go to the source code of this file.

Data Structures

struct  BaseBackupTargetType
 
struct  BaseBackupTargetHandle
 

Typedefs

typedef struct BaseBackupTargetType BaseBackupTargetType
 

Functions

static void initialize_target_list (void)
 
static bbsinkblackhole_get_sink (bbsink *next_sink, void *detail_arg)
 
static bbsinkserver_get_sink (bbsink *next_sink, void *detail_arg)
 
static void * reject_target_detail (char *target, char *target_detail)
 
static void * server_check_detail (char *target, char *target_detail)
 
void BaseBackupAddTarget (char *name, void *(*check_detail)(char *, char *), bbsink *(*get_sink)(bbsink *, void *))
 
BaseBackupTargetHandleBaseBackupGetTargetHandle (char *target, char *target_detail)
 
bbsinkBaseBackupGetSink (BaseBackupTargetHandle *handle, bbsink *next_sink)
 

Variables

static BaseBackupTargetType builtin_backup_targets []
 
static ListBaseBackupTargetTypeList = NIL
 

Typedef Documentation

◆ BaseBackupTargetType

Function Documentation

◆ BaseBackupAddTarget()

void BaseBackupAddTarget ( char *  name,
void *(*)(char *, char *)  check_detail,
bbsink *(*)(bbsink *, void *)  get_sink 
)

Definition at line 61 of file basebackup_target.c.

64 {
65  BaseBackupTargetType *newtype;
66  MemoryContext oldcontext;
67  ListCell *lc;
68 
69  /* If the target list is not yet initialized, do that first. */
72 
73  /* Search the target type list for an existing entry with this name. */
74  foreach(lc, BaseBackupTargetTypeList)
75  {
76  BaseBackupTargetType *ttype = lfirst(lc);
77 
78  if (strcmp(ttype->name, name) == 0)
79  {
80  /*
81  * We found one, so update it.
82  *
83  * It is probably not a great idea to call BaseBackupAddTarget for
84  * the same name multiple times, but if it happens, this seems
85  * like the sanest behavior.
86  */
87  ttype->check_detail = check_detail;
88  ttype->get_sink = get_sink;
89  return;
90  }
91  }
92 
93  /*
94  * We use TopMemoryContext for allocations here to make sure that the data
95  * we need doesn't vanish under us; that's also why we copy the target
96  * name into a newly-allocated chunk of memory.
97  */
99  newtype = palloc(sizeof(BaseBackupTargetType));
100  newtype->name = pstrdup(name);
101  newtype->check_detail = check_detail;
102  newtype->get_sink = get_sink;
104  MemoryContextSwitchTo(oldcontext);
105 }
static List * BaseBackupTargetTypeList
static void initialize_target_list(void)
const char * name
Definition: encode.c:571
List * lappend(List *list, void *datum)
Definition: list.c:338
char * pstrdup(const char *in)
Definition: mcxt.c:1624
MemoryContext TopMemoryContext
Definition: mcxt.c:141
void * palloc(Size size)
Definition: mcxt.c:1210
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:138
#define lfirst(lc)
Definition: pg_list.h:172
#define NIL
Definition: pg_list.h:68
void *(* check_detail)(char *, char *)
bbsink *(* get_sink)(bbsink *, void *)

References BaseBackupTargetTypeList, BaseBackupTargetType::check_detail, BaseBackupTargetType::get_sink, initialize_target_list(), lappend(), lfirst, MemoryContextSwitchTo(), BaseBackupTargetType::name, name, NIL, palloc(), pstrdup(), and TopMemoryContext.

Referenced by _PG_init().

◆ BaseBackupGetSink()

bbsink* BaseBackupGetSink ( BaseBackupTargetHandle handle,
bbsink next_sink 
)

Definition at line 163 of file basebackup_target.c.

164 {
165  return handle->type->get_sink(next_sink, handle->detail_arg);
166 }
BaseBackupTargetType * type

References BaseBackupTargetHandle::detail_arg, BaseBackupTargetType::get_sink, and BaseBackupTargetHandle::type.

Referenced by SendBaseBackup().

◆ BaseBackupGetTargetHandle()

BaseBackupTargetHandle* BaseBackupGetTargetHandle ( char *  target,
char *  target_detail 
)

Definition at line 117 of file basebackup_target.c.

118 {
119  ListCell *lc;
120 
121  /* If the target list is not yet initialized, do that first. */
124 
125  /* Search the target type list for a match. */
126  foreach(lc, BaseBackupTargetTypeList)
127  {
128  BaseBackupTargetType *ttype = lfirst(lc);
129 
130  if (strcmp(ttype->name, target) == 0)
131  {
132  BaseBackupTargetHandle *handle;
133 
134  /* Found the target. */
135  handle = palloc(sizeof(BaseBackupTargetHandle));
136  handle->type = ttype;
137  handle->detail_arg = ttype->check_detail(target, target_detail);
138 
139  return handle;
140  }
141  }
142 
143  /* Did not find the target. */
144  ereport(ERROR,
145  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
146  errmsg("unrecognized target: \"%s\"", target)));
147 
148  /* keep compiler quiet */
149  return NULL;
150 }
int errcode(int sqlerrcode)
Definition: elog.c:858
int errmsg(const char *fmt,...)
Definition: elog.c:1069
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:149

References BaseBackupTargetTypeList, BaseBackupTargetType::check_detail, BaseBackupTargetHandle::detail_arg, ereport, errcode(), errmsg(), ERROR, initialize_target_list(), lfirst, BaseBackupTargetType::name, NIL, palloc(), and BaseBackupTargetHandle::type.

Referenced by parse_basebackup_options().

◆ blackhole_get_sink()

static bbsink * blackhole_get_sink ( bbsink next_sink,
void *  detail_arg 
)
static

Definition at line 194 of file basebackup_target.c.

195 {
196  return next_sink;
197 }

◆ initialize_target_list()

static void initialize_target_list ( void  )
static

Definition at line 172 of file basebackup_target.c.

173 {
175  MemoryContext oldcontext;
176 
178  while (ttype->name != NULL)
179  {
181  ++ttype;
182  }
183  MemoryContextSwitchTo(oldcontext);
184 }
static BaseBackupTargetType builtin_backup_targets[]

References BaseBackupTargetTypeList, builtin_backup_targets, lappend(), MemoryContextSwitchTo(), BaseBackupTargetType::name, and TopMemoryContext.

Referenced by BaseBackupAddTarget(), and BaseBackupGetTargetHandle().

◆ reject_target_detail()

static void * reject_target_detail ( char *  target,
char *  target_detail 
)
static

Definition at line 213 of file basebackup_target.c.

214 {
215  if (target_detail != NULL)
216  ereport(ERROR,
217  (errcode(ERRCODE_SYNTAX_ERROR),
218  errmsg("target \"%s\" does not accept a target detail",
219  target)));
220 
221  return NULL;
222 }

References ereport, errcode(), errmsg(), and ERROR.

◆ server_check_detail()

static void * server_check_detail ( char *  target,
char *  target_detail 
)
static

Definition at line 232 of file basebackup_target.c.

233 {
234  if (target_detail == NULL)
235  ereport(ERROR,
236  (errcode(ERRCODE_SYNTAX_ERROR),
237  errmsg("target \"%s\" requires a target detail",
238  target)));
239 
240  return target_detail;
241 }

References ereport, errcode(), errmsg(), and ERROR.

◆ server_get_sink()

static bbsink * server_get_sink ( bbsink next_sink,
void *  detail_arg 
)
static

Definition at line 203 of file basebackup_target.c.

204 {
205  return bbsink_server_new(next_sink, detail_arg);
206 }
bbsink * bbsink_server_new(bbsink *next, char *pathname)

References bbsink_server_new().

Variable Documentation

◆ BaseBackupTargetTypeList

List* BaseBackupTargetTypeList = NIL
static

◆ builtin_backup_targets

BaseBackupTargetType builtin_backup_targets[]
static
Initial value:
=
{
{
},
{
},
{
NULL
}
}
static void * reject_target_detail(char *target, char *target_detail)
static bbsink * server_get_sink(bbsink *next_sink, void *detail_arg)
static bbsink * blackhole_get_sink(bbsink *next_sink, void *detail_arg)
static void * server_check_detail(char *target, char *target_detail)

Definition at line 40 of file basebackup_target.c.

Referenced by initialize_target_list().