Motr  M0
fid_convert.c
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2015-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 #include "ioservice/fid_convert.h"
24 
25 #include "cob/cob.h" /* m0_cob_fid_type */
26 
27 #include "stob/type.h" /* m0_stob_type */
28 #include "stob/ad.h" /* m0_stob_ad_type */
29 #include "stob/linux.h" /* m0_stob_linux_type */
30 #include "module/instance.h" /* m0_get */
31 
38 M0_INTERNAL void m0_fid_convert_cob2adstob(const struct m0_fid *cob_fid,
39  struct m0_stob_id *stob_id)
40 {
41  uint32_t device_id;
42 
44 
46  stob_id->si_fid = *cob_fid;
49  0, device_id);
50 
52 }
53 
54 M0_INTERNAL void m0_fid_convert_adstob2cob(const struct m0_stob_id *stob_id,
55  struct m0_fid *cob_fid)
56 {
58 
59  *cob_fid = stob_id->si_fid;
61 
63 }
64 
65 M0_INTERNAL void
66 m0_fid_convert_bstore2adstob(const struct m0_fid *bstore_fid,
67  struct m0_fid *stob_domain_fid)
68 {
69  M0_PRE(m0_fid_validate_bstore(bstore_fid));
70 
71  *stob_domain_fid = *bstore_fid;
72  m0_fid_tassume(stob_domain_fid, &m0_stob_ad_type.st_fidt);
73 }
74 
75 M0_INTERNAL void
76 m0_fid_convert_adstob2bstore(const struct m0_fid *stob_domain_fid,
77  struct m0_fid *bstore_fid)
78 {
79  M0_PRE(m0_fid_tget(stob_domain_fid) == m0_stob_ad_type.st_fidt.ft_id);
80 
81  *bstore_fid = *stob_domain_fid;
83 
84  M0_POST(m0_fid_validate_bstore(bstore_fid));
85 }
86 
87 M0_INTERNAL bool m0_fid_validate_adstob(const struct m0_stob_id *stob_id)
88 {
89  return m0_fid_tget(&stob_id->si_fid) == m0_stob_ad_type.st_fidt.ft_id &&
90  m0_fid_tget(&stob_id->si_domain_fid) ==
92  m0_fid__device_id_extract(&stob_id->si_fid) ==
93  stob_id->si_domain_fid.f_key &&
94  (stob_id->si_domain_fid.f_container & M0_FID_TYPE_MASK) == 0;
95 
96 }
97 
98 M0_INTERNAL bool m0_fid_validate_bstore(const struct m0_fid *bstore_fid)
99 {
100  return m0_fid_tget(bstore_fid) == m0_stob_linux_type.st_fidt.ft_id;
101 }
102 
103 M0_INTERNAL bool m0_fid_validate_linuxstob(const struct m0_stob_id *stob_id)
104 {
105  return m0_fid_tget(&stob_id->si_fid) ==
107  m0_fid_tget(&stob_id->si_domain_fid) ==
109  (stob_id->si_domain_fid.f_container & M0_FID_TYPE_MASK) == 0;
110 
111 }
112 
113 M0_INTERNAL void m0_fid_convert_cob2linuxstob(const struct m0_fid *cob_fid,
114  struct m0_stob_id *stob_id)
115 {
116  uint32_t device_id;
117 
119 
120  device_id = m0_get()->i_storage_is_fake ? M0_SDEV_CID_DEFAULT :
122  stob_id->si_fid = *cob_fid;
125  0, device_id);
126 
128 }
129 
130 M0_INTERNAL void m0_fid_convert_linuxstob2cob(const struct m0_stob_id *stob_id,
131  struct m0_fid *cob_fid)
132 {
134 
135  *cob_fid = stob_id->si_fid;
137 
139 }
140 
141 M0_INTERNAL void m0_fid_convert_cob2stob(const struct m0_fid *cob_fid,
142  struct m0_stob_id *stob_id)
143 {
144  bool stob_ad = m0_get()->i_reqh_uses_ad_stob;
145 
146  if (stob_ad)
148  else
150 }
151 
152 M0_INTERNAL void m0_fid_convert_stob2cob(const struct m0_stob_id *stob_id,
153  struct m0_fid *cob_fid)
154 {
155  bool stob_ad = m0_get()->i_reqh_uses_ad_stob;
156 
157  if (stob_ad)
159  else
161 }
162 
165 /*
166  * Local variables:
167  * c-indentation-style: "K&R"
168  * c-basic-offset: 8
169  * tab-width: 8
170  * fill-column: 80
171  * scroll-step: 1
172  * End:
173  */
174 /*
175  * vim: tabstop=8 shiftwidth=8 noexpandtab textwidth=80 nowrap
176  */
#define M0_PRE(cond)
M0_INTERNAL void m0_fid_tset(struct m0_fid *fid, uint8_t tid, uint64_t container, uint64_t key)
Definition: fid.c:126
struct m0_fid si_domain_fid
Definition: stob.h:103
uint8_t ft_id
Definition: fid.h:101
M0_INTERNAL void m0_fid_convert_cob2adstob(const struct m0_fid *cob_fid, struct m0_stob_id *stob_id)
Definition: fid_convert.c:38
const struct m0_fid_type m0_cob_fid_type
Definition: cob.c:117
const struct m0_stob_type m0_stob_ad_type
Definition: ad.c:1003
M0_INTERNAL uint8_t m0_fid_tget(const struct m0_fid *fid)
Definition: fid.c:133
M0_INTERNAL void m0_fid_convert_adstob2bstore(const struct m0_fid *stob_domain_fid, struct m0_fid *bstore_fid)
Definition: fid_convert.c:76
M0_INTERNAL bool m0_fid_validate_linuxstob(const struct m0_stob_id *stob_id)
Definition: fid_convert.c:103
M0_INTERNAL struct m0 * m0_get(void)
Definition: instance.c:41
M0_INTERNAL void m0_fid_convert_cob2linuxstob(const struct m0_fid *cob_fid, struct m0_stob_id *stob_id)
Definition: fid_convert.c:113
bool i_storage_is_fake
Definition: instance.h:131
M0_INTERNAL uint32_t m0_fid__device_id_extract(const struct m0_fid *fid)
Definition: fid_convert.c:40
M0_INTERNAL bool m0_fid_validate_adstob(const struct m0_stob_id *stob_id)
Definition: fid_convert.c:87
bool i_reqh_uses_ad_stob
Definition: instance.h:132
M0_INTERNAL void m0_fid_convert_cob2stob(const struct m0_fid *cob_fid, struct m0_stob_id *stob_id)
Definition: fid_convert.c:141
static struct m0_fid cob_fid
Definition: net.c:116
struct m0_fid si_fid
Definition: stob.h:105
uint64_t f_container
Definition: fid.h:39
#define M0_POST(cond)
M0_INTERNAL bool m0_fid_validate_bstore(const struct m0_fid *bstore_fid)
Definition: fid_convert.c:98
M0_INTERNAL void m0_fid_convert_linuxstob2cob(const struct m0_stob_id *stob_id, struct m0_fid *cob_fid)
Definition: fid_convert.c:130
Definition: fid.h:38
uint64_t f_key
Definition: fid.h:40
M0_INTERNAL void m0_fid_convert_adstob2cob(const struct m0_stob_id *stob_id, struct m0_fid *cob_fid)
Definition: fid_convert.c:54
M0_INTERNAL bool m0_fid_validate_cob(const struct m0_fid *cob_fid)
Definition: fid_convert.c:99
M0_INTERNAL void m0_fid_convert_stob2cob(const struct m0_stob_id *stob_id, struct m0_fid *cob_fid)
Definition: fid_convert.c:152
const struct m0_stob_type m0_stob_linux_type
Definition: linux.c:86
M0_INTERNAL void m0_fid_convert_bstore2adstob(const struct m0_fid *bstore_fid, struct m0_fid *stob_domain_fid)
Definition: fid_convert.c:66
struct m0_fid_type st_fidt
Definition: type.h:61
M0_INTERNAL void m0_fid_tassume(struct m0_fid *fid, const struct m0_fid_type *ft)
Definition: fid.c:146