summaryrefslogtreecommitdiff
path: root/src/common/common_init.h
blob: 88ef485859a970657d16cd4aceade676c3f2a2ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
/*
 * Ceph - scalable distributed file system
 *
 * Copyright (C) 2009-2011 New Dream Network
 *
 * This is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License version 2.1, as published by the Free Software
 * Foundation.  See file COPYING.
 *
 */

#ifndef CEPH_COMMON_INIT_H
#define CEPH_COMMON_INIT_H

#include <deque>
#include <stdint.h>
#include <string>
#include <vector>

#include "common/code_environment.h"

class CephContext;
class CephInitParameters;

enum common_init_flags_t {
  // Set up defaults that make sense for an unprivileged deamon
  CINIT_FLAG_UNPRIVILEGED_DAEMON_DEFAULTS = 0x1,

  // By default, don't read a configuration file
  CINIT_FLAG_NO_DEFAULT_CONFIG_FILE = 0x2,

  // Don't close stderr (in daemonize)
  CINIT_FLAG_NO_CLOSE_STDERR = 0x4,
};

/*
 * NOTE: If you are writing a Ceph daemon, ignore this function and call
 * global_init instead. It will call common_preinit for you.
 *
 * common_preinit creates the CephContext.
 *
 * After this function gives you a CephContext, you need to set up the
 * Ceph configuration, which lives inside the CephContext as md_config_t.
 * The initial settings are not very useful because they do not reflect what
 * the user asked for.
 *
 * This is usually done by something like this:
 * cct->_conf->parse_env();
 * cct->_conf->apply_changes();
 *
 * Your library may also supply functions to read a configuration file.
 */
CephContext *common_preinit(const CephInitParameters &iparams,
			    enum code_environment_t code_env, int flags);

/* Print out some parse errors. */
void complain_about_parse_errors(CephContext *cct,
				 std::deque<std::string> *parse_errors);

/* This function is called after you have done your last
 * fork. When you make this call, the system will initialize everything that
 * cannot be initialized before a fork.
 *
 * This includes things like starting threads, initializing libraries that
 * can't handle forking, and so forth.
 *
 * If you are writing a Ceph library, you can call this pretty much any time.
 * We do not allow our library users to fork and continue using the Ceph
 * libraries. The most obvious reason for this is that the threads started by
 * the Ceph libraries would be destroyed by a fork().
 */
void common_init_finish(CephContext *cct);

/* This function is called from library code to destroy a context created by
 * the library.
 * You should not call this function if you called global_init.
 */
void common_destroy_context(CephContext *cct);

#endif