Motr  M0
log_sched.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 #define M0_TRACE_SUBSYSTEM M0_TRACE_SUBSYS_BE
24 #include "lib/trace.h"
25 
26 #include "be/log_sched.h"
27 
28 #include "be/io_sched.h" /* m0_be_io_sched */
29 #include "lib/memory.h" /* m0_alloc_aligned */
30 #include "lib/errno.h" /* ENOMEM */
31 
38 M0_INTERNAL int m0_be_log_sched_init(struct m0_be_log_sched *sched,
39  struct m0_be_log_sched_cfg *cfg)
40 {
41  sched->lsh_pos = 0;
43  return m0_be_io_sched_init(&sched->lsh_io_sched,
44  &cfg->lsch_io_sched_cfg);
45 }
46 
47 M0_INTERNAL void m0_be_log_sched_fini(struct m0_be_log_sched *sched)
48 {
50 }
51 
52 M0_INTERNAL void m0_be_log_sched_lock(struct m0_be_log_sched *sched)
53 {
55 }
56 
57 M0_INTERNAL void m0_be_log_sched_unlock(struct m0_be_log_sched *sched)
58 {
60 }
61 
62 M0_INTERNAL bool m0_be_log_sched_is_locked(struct m0_be_log_sched *sched)
63 {
64  return m0_be_io_sched_is_locked(&sched->lsh_io_sched);
65 }
66 
67 M0_INTERNAL void m0_be_log_sched_add(struct m0_be_log_sched *sched,
68  struct m0_be_log_io *lio,
69  struct m0_be_op *op)
70 {
71  struct m0_ext *ext = NULL;
72  struct m0_ext ext2;
73 
74  M0_LOG(M0_DEBUG, "sched=%p lio=%p lio_record=%p op=%p "
75  "m0_be_io_size(&lio->lio_be_io)=%"PRIu64,
76  sched, lio, lio->lio_record, op,
77  m0_be_io_size(&lio->lio_be_io));
78 
81 
82  lio->lio_sched = sched;
84  /*
85  * Note: it makes a simple queue from an ext-based queue.
86  * In the future m0_be_log_sched_add() is going to have
87  * m0_ext parameter.
88  */
89  ext2.e_start = sched->lsh_pos;
90  ext2.e_end = ++sched->lsh_pos;
91  m0_ext_init(&ext2);
92  ext = &ext2;
93  }
94  m0_be_io_sched_add(&sched->lsh_io_sched, &lio->lio_be_io, ext, op);
95 }
96 
97 M0_INTERNAL int m0_be_log_io_init(struct m0_be_log_io *lio)
98 {
99  return 0;
100 }
101 
102 M0_INTERNAL void m0_be_log_io_fini(struct m0_be_log_io *lio)
103 {
104 }
105 
106 M0_INTERNAL void m0_be_log_io_reset(struct m0_be_log_io *lio)
107 {
108  lio->lio_buf_addr = NULL;
109  lio->lio_buf_size = 0;
111  m0_be_io_reset(&lio->lio_be_io);
112 }
113 
114 M0_INTERNAL int m0_be_log_io_allocate(struct m0_be_log_io *lio,
115  struct m0_be_io_credit *iocred,
116  uint32_t log_bshift)
117 {
118  m0_bcount_t size = iocred->bic_reg_size;
119  void *addr;
120  int rc;
121 
122  M0_ENTRY("lio=%p iocred="BE_IOCRED_F" log_bshift=%"PRIu32,
123  lio, BE_IOCRED_P(iocred), log_bshift);
124  M0_PRE(m0_is_aligned(size, 1 << log_bshift));
125 
126  addr = m0_alloc_aligned(size, log_bshift);
127  rc = addr == NULL ? -ENOMEM : 0;
128  if (rc != 0)
129  goto err;
130  rc = m0_be_io_init(&lio->lio_be_io);
131  if (rc != 0)
132  goto err_free;
133  rc = m0_be_io_allocate(&lio->lio_be_io, iocred);
134  if (rc != 0)
135  goto err_lio_fini;
136 
137  lio->lio_buf = M0_BUF_INIT(size, addr);
138  lio->lio_log_bshift = log_bshift;
139 
140  return rc;
141 
142 err_lio_fini:
143  m0_be_io_fini(&lio->lio_be_io);
144 err_free:
145  m0_free_aligned(addr, size, log_bshift);
146 err:
147  return M0_RC(rc);
148 }
149 
150 M0_INTERNAL void m0_be_log_io_deallocate(struct m0_be_log_io *lio)
151 {
152  struct m0_buf *buf = &lio->lio_buf;
153 
155  m0_be_io_fini(&lio->lio_be_io);
156  m0_free_aligned(buf->b_addr, buf->b_nob, lio->lio_log_bshift);
157 }
158 
159 M0_INTERNAL struct m0_bufvec *m0_be_log_io_bufvec(struct m0_be_log_io *lio)
160 {
161  return &lio->lio_bufvec;
162 }
163 
164 M0_INTERNAL struct m0_be_io *m0_be_log_io_be_io(struct m0_be_log_io *lio)
165 {
166  return &lio->lio_be_io;
167 }
168 
169 M0_INTERNAL void m0_be_log_io_user_data_set(struct m0_be_log_io *lio,
170  void *data)
171 {
172  lio->lio_user_data = data;
173 }
174 
175 M0_INTERNAL void *m0_be_log_io_user_data(struct m0_be_log_io *lio)
176 {
177  return lio->lio_user_data;
178 }
179 
180 M0_INTERNAL bool m0_be_log_io_is_empty(struct m0_be_log_io *lio)
181 {
182  return m0_be_io_is_empty(&lio->lio_be_io);
183 }
184 
186 #undef M0_TRACE_SUBSYSTEM
187 
188 /*
189  * Local variables:
190  * c-indentation-style: "K&R"
191  * c-basic-offset: 8
192  * tab-width: 8
193  * fill-column: 80
194  * scroll-step: 1
195  * End:
196  */
197 /*
198  * vim: tabstop=8 shiftwidth=8 noexpandtab textwidth=80 nowrap
199  */
#define M0_BUFVEC_INIT_BUF(addr_ptr, count_ptr)
Definition: vec.h:165
#define M0_PRE(cond)
M0_INTERNAL m0_bcount_t m0_be_io_size(struct m0_be_io *bio)
Definition: io.c:500
m0_bcount_t bisc_pos_start
Definition: io_sched.h:44
m0_bindex_t e_end
Definition: ext.h:40
#define NULL
Definition: misc.h:38
struct m0_be_log_record * lio_record
Definition: log_sched.h:67
uint32_t lio_log_bshift
Definition: log_sched.h:60
#define M0_LOG(level,...)
Definition: trace.h:167
struct m0_bufvec lio_bufvec
Definition: log_sched.h:64
struct m0_bufvec data
Definition: di.c:40
m0_bcount_t lio_buf_size
Definition: log_sched.h:63
M0_INTERNAL void m0_free_aligned(void *data, size_t size, unsigned shift)
Definition: memory.c:192
uint64_t m0_bcount_t
Definition: types.h:77
#define BE_IOCRED_P(iocred)
Definition: io.h:84
m0_bindex_t lsh_pos
Definition: log_sched.h:55
Definition: sock.c:887
return M0_RC(rc)
op
Definition: libdemo.c:64
m0_bcount_t bic_reg_size
Definition: io.h:72
#define M0_ENTRY(...)
Definition: trace.h:170
Definition: buf.h:37
M0_INTERNAL struct m0_be_io * m0_be_log_io_be_io(struct m0_be_log_io *lio)
Definition: log_sched.c:164
static char * addr
Definition: node_k.c:37
#define PRIu64
Definition: types.h:58
M0_INTERNAL void m0_be_io_fini(struct m0_be_io *bio)
Definition: io.c:224
M0_INTERNAL int m0_be_io_sched_init(struct m0_be_io_sched *sched, struct m0_be_io_sched_cfg *cfg)
Definition: io_sched.c:51
M0_INTERNAL bool m0_be_log_sched_is_locked(struct m0_be_log_sched *sched)
Definition: log_sched.c:62
M0_INTERNAL bool m0_be_log_io_is_empty(struct m0_be_log_io *lio)
Definition: log_sched.c:180
void * lio_buf_addr
Definition: log_sched.h:62
M0_INTERNAL bool m0_be_io_sched_is_locked(struct m0_be_io_sched *sched)
Definition: io_sched.c:80
static bool m0_is_aligned(uint64_t val, uint64_t alignment)
Definition: arith.h:179
M0_INTERNAL void m0_ext_init(struct m0_ext *ext)
Definition: ext.c:32
M0_INTERNAL void m0_be_log_sched_add(struct m0_be_log_sched *sched, struct m0_be_log_io *lio, struct m0_be_op *op)
Definition: log_sched.c:67
M0_INTERNAL void * m0_be_log_io_user_data(struct m0_be_log_io *lio)
Definition: log_sched.c:175
M0_INTERNAL void m0_be_log_io_deallocate(struct m0_be_log_io *lio)
Definition: log_sched.c:150
M0_INTERNAL int m0_be_io_init(struct m0_be_io *bio)
Definition: io.c:175
M0_INTERNAL void m0_be_io_sched_lock(struct m0_be_io_sched *sched)
Definition: io_sched.c:70
Definition: xcode.h:73
#define BE_IOCRED_F
Definition: io.h:82
M0_INTERNAL void m0_be_io_sched_fini(struct m0_be_io_sched *sched)
Definition: io_sched.c:64
M0_INTERNAL void m0_be_log_io_user_data_set(struct m0_be_log_io *lio, void *data)
Definition: log_sched.c:169
struct m0_be_io_sched_cfg lsch_io_sched_cfg
Definition: log_sched.h:42
M0_INTERNAL struct m0_bufvec * m0_be_log_io_bufvec(struct m0_be_log_io *lio)
Definition: log_sched.c:159
M0_INTERNAL bool m0_be_io_is_empty(struct m0_be_io *bio)
Definition: io.c:646
M0_INTERNAL int m0_be_log_io_allocate(struct m0_be_log_io *lio, struct m0_be_io_credit *iocred, uint32_t log_bshift)
Definition: log_sched.c:114
M0_INTERNAL int m0_be_log_io_init(struct m0_be_log_io *lio)
Definition: log_sched.c:97
#define PRIu32
Definition: types.h:66
M0_INTERNAL void m0_be_io_sched_unlock(struct m0_be_io_sched *sched)
Definition: io_sched.c:75
Definition: ext.h:37
m0_bindex_t e_start
Definition: ext.h:39
M0_INTERNAL int m0_be_io_allocate(struct m0_be_io *bio, struct m0_be_io_credit *iocred)
Definition: io.c:180
struct m0_be_log_sched * lio_sched
Definition: log_sched.h:66
M0_INTERNAL void m0_be_io_deallocate(struct m0_be_io *bio)
Definition: io.c:215
M0_INTERNAL enum m0_stob_io_opcode m0_be_io_opcode(struct m0_be_io *io)
Definition: io.c:641
m0_bcount_t size
Definition: di.c:39
struct m0_buf lio_buf
Definition: log_sched.h:61
M0_INTERNAL void m0_be_io_sched_add(struct m0_be_io_sched *sched, struct m0_be_io *io, struct m0_ext *ext, struct m0_be_op *op)
Definition: io_sched.c:176
Definition: io.h:87
M0_INTERNAL void m0_be_log_sched_fini(struct m0_be_log_sched *sched)
Definition: log_sched.c:47
struct m0_be_io lio_be_io
Definition: log_sched.h:65
M0_INTERNAL void * m0_alloc_aligned(size_t size, unsigned shift)
Definition: memory.c:168
Definition: io.h:229
M0_INTERNAL void m0_be_log_io_fini(struct m0_be_log_io *lio)
Definition: log_sched.c:102
Definition: op.h:74
M0_INTERNAL void m0_be_log_sched_lock(struct m0_be_log_sched *sched)
Definition: log_sched.c:52
#define M0_BUF_INIT(size, data)
Definition: buf.h:64
M0_INTERNAL void m0_be_io_reset(struct m0_be_io *bio)
Definition: io.c:651
M0_INTERNAL void m0_be_log_sched_unlock(struct m0_be_log_sched *sched)
Definition: log_sched.c:57
int32_t rc
Definition: trigger_fop.h:47
M0_INTERNAL int m0_be_log_sched_init(struct m0_be_log_sched *sched, struct m0_be_log_sched_cfg *cfg)
Definition: log_sched.c:38
void * lio_user_data
Definition: log_sched.h:68
M0_INTERNAL void m0_be_log_io_reset(struct m0_be_log_io *lio)
Definition: log_sched.c:106
Definition: vec.h:145
struct m0_be_io_sched lsh_io_sched
Definition: log_sched.h:54