Motr  M0
elevator.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2020 Seagate Technology LLC and/or its Affiliates
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * For any questions about this software or licensing,
17  * please email opensource@seagate.com or cortx-questions@seagate.com.
18  *
19  */
20 
21 
22 #include <string.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 
26 #include "lib/assert.h"
27 #include "motr/magic.h"
28 #include "desim/elevator.h"
29 
35 /*
36  * Simple FIFO elevator.
37  */
38 
39 struct io_req {
41  uint64_t ir_magic;
42 };
43 
44 M0_TL_DESCR_DEFINE(req, "io requests", static, struct io_req,
45  ir_linkage, ir_magic, M0_DESIM_IO_REQ_MAGIC,
47 M0_TL_DEFINE(req, static, struct io_req);
48 
49 static void elevator_submit(struct elevator *el,
51  sector_t sector, unsigned long count)
52 {
53  el->e_idle = 0;
54  el->e_dev->sd_submit(el->e_dev, type, sector, count);
55 }
56 
57 /*
58  * submit asynchronous requests.
59  */
60 static void elevator_go(struct elevator *el)
61 {
62  /* impossible for now */
63  M0_IMPOSSIBLE("Elevator is not yet implemented");
64 }
65 
66 M0_INTERNAL void el_end_io(struct storage_dev *dev)
67 {
68  struct elevator *el;
69 
70  el = dev->sd_el;
71  el->e_idle = 1;
72  if (!req_tlist_is_empty(&el->e_queue))
73  elevator_go(el);
75 }
76 
77 M0_INTERNAL void elevator_init(struct elevator *el, struct storage_dev *dev)
78 {
79  el->e_dev = dev;
80  el->e_idle = 1;
81  dev->sd_end_io = el_end_io;
82  dev->sd_el = el;
83  req_tlist_init(&el->e_queue);
84  sim_chan_init(&el->e_wait, "xfer-queue@%s", dev->sd_name);
85 }
86 
87 M0_INTERNAL void elevator_fini(struct elevator *el)
88 {
89  req_tlist_fini(&el->e_queue);
91 }
92 
93 M0_INTERNAL void elevator_io(struct elevator *el, enum storage_req_type type,
94  sector_t sector, unsigned long count)
95 {
96  while (!el->e_idle)
98  elevator_submit(el, type, sector, count);
99 }
100 
103 /*
104  * Local variables:
105  * c-indentation-style: "K&R"
106  * c-basic-offset: 8
107  * tab-width: 8
108  * fill-column: 80
109  * scroll-step: 1
110  * End:
111  */
int e_idle
Definition: elevator.h:38
static void elevator_submit(struct elevator *el, enum storage_req_type type, sector_t sector, unsigned long count)
Definition: elevator.c:49
static struct io_request req
Definition: file.c:100
M0_INTERNAL void sim_chan_fini(struct sim_chan *chan)
Definition: sim.c:400
M0_INTERNAL struct sim_thread * sim_thread_current(void)
Definition: sim.c:465
Definition: io_req.py:1
M0_INTERNAL void elevator_init(struct elevator *el, struct storage_dev *dev)
Definition: elevator.c:77
M0_INTERNAL void sim_chan_broadcast(struct sim_chan *chan)
Definition: sim.c:456
static m0_bcount_t count
Definition: xcode.c:167
M0_INTERNAL void sim_chan_init(struct sim_chan *chan, char *format,...)
Definition: sim.c:385
M0_TL_DESCR_DEFINE(req, "io requests", static, struct io_req, ir_linkage, ir_magic, M0_DESIM_IO_REQ_MAGIC, M0_DESIM_IO_REQ_HEAD_MAGIC)
unsigned long long sector_t
Definition: storage.h:34
struct sim_chan e_wait
Definition: elevator.h:40
char * sd_name
Definition: storage.h:59
storage_req_type
Definition: storage.h:42
M0_INTERNAL void el_end_io(struct storage_dev *dev)
Definition: elevator.c:66
M0_INTERNAL void sim_chan_wait(struct sim_chan *chan, struct sim_thread *thread)
Definition: sim.c:411
M0_INTERNAL void elevator_io(struct elevator *el, enum storage_req_type type, sector_t sector, unsigned long count)
Definition: elevator.c:93
uint64_t ir_magic
Definition: elevator.c:41
struct storage_dev * e_dev
Definition: elevator.h:37
storage_end_io_t sd_end_io
Definition: storage.h:56
M0_INTERNAL void elevator_fini(struct elevator *el)
Definition: elevator.c:87
struct elevator * sd_el
Definition: storage.h:58
static struct elevator el
Definition: chs_test.c:102
int type
Definition: dir.c:1031
struct m0_tl e_queue
Definition: elevator.h:39
struct m0_tlink ir_linkage
Definition: elevator.c:40
static void elevator_go(struct elevator *el)
Definition: elevator.c:60
storage_submit_t sd_submit
Definition: storage.h:57
#define M0_IMPOSSIBLE(fmt,...)
M0_TL_DEFINE(req, static, struct io_req)