Motr  M0
catalogue.c
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2013-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 
30 #define M0_TRACE_SUBSYSTEM M0_TRACE_SUBSYS_DTM
31 #include "lib/trace.h"
32 #include "lib/assert.h"
33 #include "lib/errno.h" /* ENOENT */
34 #include "motr/magic.h"
35 
36 #include "dtm/history.h"
37 #include "dtm/catalogue.h"
38 
39 M0_TL_DESCR_DEFINE(cat, "catalogue", M0_INTERNAL,
40  struct m0_dtm_history, h_catlink,
41  h_hi.hi_ups.t_magic, M0_DTM_HI_MAGIX, M0_DTM_CAT_MAGIX);
42 M0_TL_DEFINE(cat, M0_INTERNAL, struct m0_dtm_history);
43 
44 M0_INTERNAL void m0_dtm_catalogue_init(struct m0_dtm_catalogue *cat)
45 {
46  cat_tlist_init(&cat->ca_el);
47 }
48 
49 M0_INTERNAL void m0_dtm_catalogue_fini(struct m0_dtm_catalogue *cat)
50 {
51  struct m0_dtm_history *history;
52 
53  m0_tl_for(cat, &cat->ca_el, history) {
54  cat_tlist_del(history);
55  } m0_tl_endfor;
56  cat_tlist_fini(&cat->ca_el);
57 }
58 
59 M0_INTERNAL int m0_dtm_catalogue_create(struct m0_dtm_catalogue *cat)
60 {
61  return 0;
62 }
63 
64 M0_INTERNAL int m0_dtm_catalogue_delete(struct m0_dtm_catalogue *cat)
65 {
66  return 0;
67 }
68 
69 M0_INTERNAL int m0_dtm_catalogue_lookup(struct m0_dtm_catalogue *cat,
70  const struct m0_uint128 *id,
71  struct m0_dtm_history **out)
72 {
73  *out = m0_tl_find(cat, history, &cat->ca_el,
74  m0_uint128_eq(history->h_ops->hio_id(history), id));
75  return *out != NULL ? 0 : -ENOENT;
76 }
77 
78 M0_INTERNAL int m0_dtm_catalogue_add(struct m0_dtm_catalogue *cat,
79  struct m0_dtm_history *history)
80 {
81  cat_tlist_add(&cat->ca_el, history);
82  return 0;
83 }
84 
85 M0_INTERNAL int m0_dtm_catalogue_del(struct m0_dtm_catalogue *cat,
86  struct m0_dtm_history *history)
87 {
88  cat_tlist_del(history);
89  return 0;
90 }
91 
92 M0_INTERNAL int m0_dtm_catalogue_find(struct m0_dtm_catalogue *cat,
93  struct m0_dtm *dtm,
94  const struct m0_uint128 *id,
96  void *datum,
97  struct m0_dtm_history **out)
98 {
99  int result;
100 
101  result = m0_dtm_catalogue_lookup(cat, id, out);
102  if (result == -ENOENT) {
103  *out = alloc(dtm, id, datum);
104  if (*out != NULL) {
105  m0_dtm_catalogue_add(cat, *out);
106  result = 0;
107  } else
108  result = M0_ERR(-ENOMEM);
109  }
110  return result;
111 }
112 
115 /*
116  * Local variables:
117  * c-indentation-style: "K&R"
118  * c-basic-offset: 8
119  * tab-width: 8
120  * fill-column: 80
121  * scroll-step: 1
122  * End:
123  */
124 /*
125  * vim: tabstop=8 shiftwidth=8 noexpandtab textwidth=80 nowrap
126  */
uint64_t id
Definition: cob.h:2380
#define NULL
Definition: misc.h:38
M0_INTERNAL bool m0_uint128_eq(const struct m0_uint128 *u0, const struct m0_uint128 *u1)
Definition: misc.c:39
M0_INTERNAL void m0_dtm_catalogue_init(struct m0_dtm_catalogue *cat)
Definition: catalogue.c:44
M0_TL_DESCR_DEFINE(cat, "catalogue", M0_INTERNAL, struct m0_dtm_history, h_catlink, h_hi.hi_ups.t_magic, M0_DTM_HI_MAGIX, M0_DTM_CAT_MAGIX)
struct m0_tl ca_el
Definition: catalogue.h:46
#define m0_tl_endfor
Definition: tlist.h:700
return M0_ERR(-EOPNOTSUPP)
M0_INTERNAL int m0_dtm_catalogue_find(struct m0_dtm_catalogue *cat, struct m0_dtm *dtm, const struct m0_uint128 *id, m0_dtm_catalogue_alloc_t *alloc, void *datum, struct m0_dtm_history **out)
Definition: catalogue.c:92
M0_INTERNAL int m0_dtm_catalogue_add(struct m0_dtm_catalogue *cat, struct m0_dtm_history *history)
Definition: catalogue.c:78
static struct ff2c_term * alloc(void)
Definition: parser.c:37
M0_INTERNAL void m0_dtm_catalogue_fini(struct m0_dtm_catalogue *cat)
Definition: catalogue.c:49
M0_TL_DEFINE(cat, M0_INTERNAL, struct m0_dtm_history)
struct m0_dtm_history * m0_dtm_catalogue_alloc_t(struct m0_dtm *, const struct m0_uint128 *, void *)
Definition: catalogue.h:61
Definition: dtm.h:529
#define out(...)
Definition: gen.c:41
M0_INTERNAL int m0_dtm_catalogue_create(struct m0_dtm_catalogue *cat)
Definition: catalogue.c:59
#define m0_tl_find(name, var, head,...)
Definition: tlist.h:757
#define m0_tl_for(name, head, obj)
Definition: tlist.h:695
M0_INTERNAL int m0_dtm_catalogue_lookup(struct m0_dtm_catalogue *cat, const struct m0_uint128 *id, struct m0_dtm_history **out)
Definition: catalogue.c:69
M0_INTERNAL int m0_dtm_catalogue_delete(struct m0_dtm_catalogue *cat)
Definition: catalogue.c:64
M0_INTERNAL int m0_dtm_catalogue_del(struct m0_dtm_catalogue *cat, struct m0_dtm_history *history)
Definition: catalogue.c:85