Lines Matching defs:hpio
28 /* store all inflight hpio in iotab */
36 static struct hpio *__iotab_search_get(struct hp_iotab *iotab, u32 eid)
38 struct hpio *hpio = NULL;
40 list_for_each_entry(hpio, &iotab->io_list, list)
41 if (hpio->eid == eid && kref_get_unless_zero(&hpio->refcnt))
42 return hpio;
47 static struct hpio *iotab_search_get(struct hp_iotab *iotab, u32 eid)
49 struct hpio *hpio = NULL;
53 hpio = __iotab_search_get(iotab, eid);
56 pr_info("find hpio %p for eid %u.\n", hpio, eid);
58 return hpio;
62 * insert @hpio into @iotab, cancel insertion if there is a hpio of the same
63 * @eid, inc the refcnt of duplicated hpio and return it
65 static struct hpio *iotab_insert(struct hp_iotab *iotab, struct hpio *hpio)
67 struct hpio *dup = NULL;
71 dup = __iotab_search_get(iotab, hpio->eid);
73 pr_info("find exist hpio %p for eid %u, insert hpio %p failed.\n",
74 dup, hpio->eid, hpio);
77 list_add(&hpio->list, &iotab->io_list);
79 pr_info("insert new hpio %p for eid %u.\n", hpio, hpio->eid);
86 static void iotab_delete(struct hp_iotab *iotab, struct hpio *hpio)
91 list_del(&hpio->list);
97 pr_info("delete hpio %p for eid %u from iotab.\n", hpio, hpio->eid);
100 static void hpio_clear_pages(struct hpio *hpio)
104 if (!hpio->pages)
107 for (i = 0; i < hpio->nr_page; i++)
108 if (hpio->pages[i]) {
109 put_page(hpio->pages[i]);
112 kfree(hpio->pages);
113 atomic64_sub(sizeof(struct page *) * hpio->nr_page, &hpio_mem);
114 hpio->nr_page = 0;
115 hpio->pages = NULL;
119 * alloc pages array for @hpio, fill in new alloced pages if @new_page
121 static bool hpio_fill_pages(struct hpio *hpio, u32 nr_page, gfp_t gfp, bool new_page)
125 BUG_ON(hpio->pages);
126 hpio->nr_page = nr_page;
127 hpio->pages = kcalloc(hpio->nr_page, sizeof(struct page *), gfp);
128 if (!hpio->pages)
130 atomic64_add(sizeof(struct page *) * hpio->nr_page, &hpio_mem);
134 for (i = 0; i < hpio->nr_page; i++) {
135 hpio->pages[i] = alloc_page(gfp);
136 if (!hpio->pages[i])
143 hpio_clear_pages(hpio);
148 void hpio_free(struct hpio *hpio)
150 if (!hpio)
153 pr_info("free hpio = %p.\n", hpio);
155 hpio_clear_pages(hpio);
156 kfree(hpio);
157 atomic64_sub(sizeof(struct hpio), &hpio_mem);
160 struct hpio *hpio_alloc(u32 nr_page, gfp_t gfp, unsigned int op, bool new_page)
162 struct hpio *hpio = NULL;
164 hpio = kzalloc(sizeof(struct hpio), gfp);
165 if (!hpio)
167 atomic64_add(sizeof(struct hpio), &hpio_mem);
168 if (!hpio_fill_pages(hpio, nr_page, gfp, new_page))
170 hpio->op = op;
171 atomic_set(&hpio->state, HPIO_INIT);
172 kref_init(&hpio->refcnt);
173 init_completion(&hpio->wait);
175 return hpio;
177 hpio_free(hpio);
182 struct hpio *hpio_get(u32 eid)
187 struct hpio *hpio_get_alloc(u32 eid, u32 nr_page, gfp_t gfp, unsigned int op)
189 struct hpio *hpio = NULL;
190 struct hpio *dup = NULL;
192 hpio = iotab_search_get(&iotab, eid);
193 if (hpio) {
194 pr_info("find exist hpio %p for eid %u.\n", hpio, eid);
197 hpio = hpio_alloc(nr_page, gfp, op, true);
198 if (!hpio)
200 hpio->eid = eid;
202 pr_info("alloc hpio %p for eid %u.\n", hpio, eid);
204 dup = iotab_insert(&iotab, hpio);
206 hpio_free(hpio);
207 hpio = dup;
210 return hpio;
215 struct hpio *hpio = container_of(kref, struct hpio, refcnt);
217 iotab_delete(&iotab, hpio);
218 if (hpio->free_extent)
219 hpio->free_extent(hpio->eid);
220 hpio_free(hpio);
223 bool hpio_put(struct hpio *hpio)
225 pr_info("put hpio %p for eid %u, ref = %u.\n", hpio, hpio->eid, kref_read(&hpio->refcnt));
226 return kref_put(&hpio->refcnt, hpio_release);
229 void hpio_complete(struct hpio *hpio)
231 pr_info("complete hpio %p for eid %u.\n", hpio, hpio->eid);
232 complete_all(&hpio->wait);
235 void hpio_wait(struct hpio *hpio)
237 wait_for_completion(&hpio->wait);
240 enum hpio_state hpio_get_state(struct hpio *hpio)
242 return atomic_read(&hpio->state);
245 void hpio_set_state(struct hpio *hpio, enum hpio_state state)
247 atomic_set(&hpio->state, state);
250 bool hpio_change_state(struct hpio *hpio, enum hpio_state from, enum hpio_state to)
252 return atomic_cmpxchg(&hpio->state, from, to) == from;
257 struct hpio *hpio = NULL;
260 pr_info("dump inflight hpio in iotab.\n");
262 list_for_each_entry(hpio, &iotab->io_list, list)
263 pr_info("hpio %p for eid %u is inflight.\n", hpio, hpio->eid);