3 # The MIT License (MIT)
5 # Copyright (C) 2015 - Julien Desfossez <jdesfossez@efficios.com>
6 # 2015 - Antoine Busque <abusque@efficios.com>
8 # Permission is hereby granted, free of charge, to any person obtaining a copy
9 # of this software and associated documentation files (the "Software"), to deal
10 # in the Software without restriction, including without limitation the rights
11 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 # copies of the Software, and to permit persons to whom the Software is
13 # furnished to do so, subject to the following conditions:
15 # The above copyright notice and this permission notice shall be included in
16 # all copies or substantial portions of the Software.
18 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 from linuxautomaton
import sp
, sv
29 class BlockStateProvider(sp
.StateProvider
):
30 def __init__(self
, state
):
32 'block_rq_complete': self
._process
_block
_rq
_complete
,
33 'block_rq_issue': self
._process
_block
_rq
_issue
,
34 'block_bio_remap': self
._process
_block
_bio
_remap
,
35 'block_bio_backmerge': self
._process
_block
_bio
_backmerge
,
39 self
._remap
_requests
= []
40 self
._register
_cbs
(cbs
)
42 def process_event(self
, ev
):
43 self
._process
_event
_cb
(ev
)
45 def _process_block_bio_remap(self
, event
):
47 sector
= event
['sector']
48 old_dev
= event
['old_dev']
49 old_sector
= event
['old_sector']
51 for req
in self
._remap
_requests
:
52 if req
.dev
== old_dev
and req
.sector
== old_sector
:
57 req
= sv
.BlockRemapRequest(dev
, sector
, old_dev
, old_sector
)
58 self
._remap
_requests
.append(req
)
60 # For backmerge requests, just remove the request from the
61 # _remap_requests queue, because we rely later on the nr_sector
62 # which has all the info we need
63 def _process_block_bio_backmerge(self
, event
):
65 sector
= event
['sector']
66 for remap_req
in self
._remap
_requests
:
67 if remap_req
.dev
== dev
and remap_req
.sector
== sector
:
68 self
._remap
_requests
.remove(remap_req
)
70 def _process_block_rq_issue(self
, event
):
72 sector
= event
['sector']
73 nr_sector
= event
['nr_sector']
78 req
= sv
.BlockIORequest
.new_from_rq_issue(event
)
80 for remap_req
in self
._remap
_requests
:
81 if remap_req
.dev
== dev
and remap_req
.sector
== sector
:
82 dev
= remap_req
.old_dev
85 if dev
not in self
._state
.disks
:
86 self
._state
.disks
[dev
] = sv
.Disk()
88 self
._state
.disks
[dev
].pending_requests
[sector
] = req
90 def _process_block_rq_complete(self
, event
):
92 sector
= event
['sector']
93 nr_sector
= event
['nr_sector']
98 for remap_req
in self
._remap
_requests
:
99 if remap_req
.dev
== dev
and remap_req
.sector
== sector
:
100 dev
= remap_req
.old_dev
101 self
._remap
_requests
.remove(remap_req
)
104 if dev
not in self
._state
.disks
:
105 self
._state
.disks
[dev
] = sv
.Disk()
107 disk
= self
._state
.disks
[dev
]
109 # Ignore rq_complete without matching rq_issue
110 if sector
not in disk
.pending_requests
:
113 req
= disk
.pending_requests
[sector
]
114 # Ignore rq_complete if nr_sector does not match rq_issue's
115 if req
.nr_sector
!= nr_sector
:
118 req
.update_from_rq_complete(event
)
119 proc
= self
._state
.tids
[req
.tid
]
120 self
._state
.send_notification_cb('block_rq_complete', req
=req
,
122 del disk
.pending_requests
[sector
]
This page took 0.038566 seconds and 5 git commands to generate.