Motr  M0
cookie.h
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2019-2020 Seagate Technology LLC and/or its Affiliates
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * For any questions about this software or licensing,
18  * please email opensource@seagate.com or cortx-questions@seagate.com.
19  *
20  */
21 
22 
23 #pragma once
24 
25 #ifndef __MOTR_HA_COOKIE_H__
26 #define __MOTR_HA_COOKIE_H__
27 
28 #include "lib/types.h" /* bool */
29 #include "lib/time.h" /* m0_time_t */
30 
31 #include "lib/types_xc.h" /* m0_uint128_xc for ha/cookie_xc.h */ /* XXX */
32 
40 /*
41  * m0_ha_cookie is used to check if a process at the other end of the connection
42  * is still the same. A combination of PID, start time and OS uptime is used to
43  * determine the process change.
44  *
45  * Reasons why all the fields from the structure are needed:
46  * - hc_pid: it might be 2 processes started simultaneously on different CPU
47  * cores. They may get 2 different PIDs but they still may have the same start
48  * time and OS uptime;
49  * - hc_time_start: after OS reboot a process may get the same PID and it can
50  * start at the same OS uptime. Start time of the process can't simply be the
51  * same after OS restart in this case;
52  * - hc_uptime: if someone wants to play with system time it would be possible
53  * to get the same start time and the same PID (when the PID is reused)
54  * without OS restart. hc_uptime ensures that in this case such processes will
55  * get different m0_ha_cookie.
56  * - hc_uuid: it's still possible to restart a system while playing with system
57  * time to get a process with the same m0_ha_cookie after restart. It's highly
58  * unlikely, but it's still possible. In this case UUID generator should
59  * decrease probability of getting the same m0_ha_cookie even more.
60  *
61  * Anyway, if we still get into the virtually impossible situation when
62  * m0_ha_cookie is the same for different processes, it would either result in a
63  * Motr process panic or it will become stuck. In either case HA is able to
64  * handle such situation.
65  *
66  * TODO implement a function to get OS uptime.
67  */
68 struct m0_ha_cookie {
69  uint64_t hc_pid;
73 };
74 
76  uint64_t hcx_pid;
77  uint64_t hcx_time_start;
78  uint64_t hcx_uptime;
80 } M0_XCA_RECORD M0_XCA_DOMAIN(rpc);
81 
82 extern const struct m0_ha_cookie m0_ha_cookie_no_record;
83 
84 /* XXX M0_BASSERT() doesn't work for _xc.h files, need to investigate why */
85 /*
86 M0_BASSERT(sizeof(((struct m0_ha_cookie_xc *)NULL)->hcx_time_start) ==
87  sizeof(((struct m0_ha_cookie *)NULL)->hc_time_start));
88 M0_BASSERT(sizeof(((struct m0_ha_cookie_xc *)NULL)->hcx_uptime) ==
89  sizeof(((struct m0_ha_cookie *)NULL)->hc_uptime));
90  */
91 
92 M0_INTERNAL void m0_ha_cookie_init(struct m0_ha_cookie *hc);
93 M0_INTERNAL void m0_ha_cookie_fini(struct m0_ha_cookie *hc);
94 
95 M0_INTERNAL void m0_ha_cookie_record(struct m0_ha_cookie *hc);
96 M0_INTERNAL bool m0_ha_cookie_is_eq(const struct m0_ha_cookie *a,
97  const struct m0_ha_cookie *b);
98 
99 M0_INTERNAL void m0_ha_cookie_from_xc(struct m0_ha_cookie *hc,
100  const struct m0_ha_cookie_xc *hc_xc);
101 M0_INTERNAL void m0_ha_cookie_to_xc(const struct m0_ha_cookie *hc,
102  struct m0_ha_cookie_xc *hc_xc);
105 #endif /* __MOTR_HA_COOKIE_H__ */
106 
107 /*
108  * Local variables:
109  * c-indentation-style: "K&R"
110  * c-basic-offset: 8
111  * tab-width: 8
112  * fill-column: 80
113  * scroll-step: 1
114  * End:
115  */
116 /*
117  * vim: tabstop=8 shiftwidth=8 noexpandtab textwidth=80 nowrap
118  */
uint64_t m0_time_t
Definition: time.h:37
struct m0_ha_cookie_xc M0_XCA_DOMAIN(rpc)
M0_INTERNAL void m0_ha_cookie_to_xc(const struct m0_ha_cookie *hc, struct m0_ha_cookie_xc *hc_xc)
Definition: cookie.c:101
M0_INTERNAL void m0_ha_cookie_init(struct m0_ha_cookie *hc)
Definition: cookie.c:55
M0_INTERNAL void m0_ha_cookie_fini(struct m0_ha_cookie *hc)
Definition: cookie.c:62
M0_INTERNAL bool m0_ha_cookie_is_eq(const struct m0_ha_cookie *a, const struct m0_ha_cookie *b)
Definition: cookie.c:79
const struct m0_ha_cookie m0_ha_cookie_no_record
Definition: cookie.c:40
M0_INTERNAL void m0_ha_cookie_record(struct m0_ha_cookie *hc)
Definition: cookie.c:67
M0_INTERNAL void m0_ha_cookie_from_xc(struct m0_ha_cookie *hc, const struct m0_ha_cookie_xc *hc_xc)
Definition: cookie.c:90