Lines Matching +full:left +full:- +full:shift

1 // SPDX-License-Identifier: GPL-2.0
5 * See COPYING in top-level directory.
8 #include "orangefs-kernel.h"
9 #include "orangefs-bufmap.h"
19 .c = -1,
23 .c = -1,
30 spin_lock(&m->q.lock); in install()
31 m->c = m->count = count; in install()
32 m->map = map; in install()
33 wake_up_all_locked(&m->q); in install()
34 spin_unlock(&m->q.lock); in install()
39 spin_lock(&m->q.lock); in mark_killed()
40 m->c -= m->count + 1; in mark_killed()
41 spin_unlock(&m->q.lock); in mark_killed()
47 spin_lock(&m->q.lock); in run_down()
48 if (m->c != -1) { in run_down()
51 __add_wait_queue_entry_tail(&m->q, &wait); in run_down()
54 if (m->c == -1) in run_down()
57 spin_unlock(&m->q.lock); in run_down()
59 spin_lock(&m->q.lock); in run_down()
61 __remove_wait_queue(&m->q, &wait); in run_down()
64 m->map = NULL; in run_down()
65 spin_unlock(&m->q.lock); in run_down()
71 spin_lock(&m->q.lock); in put()
72 __clear_bit(slot, m->map); in put()
73 v = ++m->c; in put()
75 wake_up_locked(&m->q); in put()
76 if (unlikely(v == -1)) /* finished dying */ in put()
77 wake_up_all_locked(&m->q); in put()
78 spin_unlock(&m->q.lock); in put()
83 long left = slot_timeout_secs * HZ; in wait_for_free() local
87 long n = left, t; in wait_for_free()
89 __add_wait_queue_entry_tail_exclusive(&m->q, &wait); in wait_for_free()
92 if (m->c > 0) in wait_for_free()
95 if (m->c < 0) { in wait_for_free()
101 spin_unlock(&m->q.lock); in wait_for_free()
103 spin_lock(&m->q.lock); in wait_for_free()
104 if (unlikely(!t) && n != left && m->c < 0) in wait_for_free()
105 left = t; in wait_for_free()
107 left = t + (left - n); in wait_for_free()
109 left = -EINTR; in wait_for_free()
110 } while (left > 0); in wait_for_free()
114 else if (left <= 0 && waitqueue_active(&m->q)) in wait_for_free()
115 __wake_up_locked_key(&m->q, TASK_INTERRUPTIBLE, NULL); in wait_for_free()
118 if (likely(left > 0)) in wait_for_free()
121 return left < 0 ? -EINTR : -ETIMEDOUT; in wait_for_free()
127 spin_lock(&m->q.lock); in get()
128 if (unlikely(m->c <= 0)) in get()
131 m->c--; in get()
132 res = find_first_zero_bit(m->map, m->count); in get()
133 __set_bit(res, m->map); in get()
135 spin_unlock(&m->q.lock); in get()
171 unpin_user_pages(bufmap->page_array, bufmap->page_count); in orangefs_bufmap_unmap()
177 kfree(bufmap->page_array); in orangefs_bufmap_free()
178 kfree(bufmap->desc_array); in orangefs_bufmap_free()
179 bitmap_free(bufmap->buffer_index_array); in orangefs_bufmap_free()
184 * XXX: Can the size and shift change while the caller gives up the
195 size = bufmap->desc_size; in orangefs_bufmap_size_query()
203 int shift = 0; in orangefs_bufmap_shift_query() local
207 shift = bufmap->desc_shift; in orangefs_bufmap_shift_query()
209 return shift; in orangefs_bufmap_shift_query()
224 bufmap->total_size = user_desc->total_size; in orangefs_bufmap_alloc()
225 bufmap->desc_count = user_desc->count; in orangefs_bufmap_alloc()
226 bufmap->desc_size = user_desc->size; in orangefs_bufmap_alloc()
227 bufmap->desc_shift = ilog2(bufmap->desc_size); in orangefs_bufmap_alloc()
229 bufmap->buffer_index_array = bitmap_zalloc(bufmap->desc_count, GFP_KERNEL); in orangefs_bufmap_alloc()
230 if (!bufmap->buffer_index_array) in orangefs_bufmap_alloc()
233 bufmap->desc_array = in orangefs_bufmap_alloc()
234 kcalloc(bufmap->desc_count, sizeof(struct orangefs_bufmap_desc), in orangefs_bufmap_alloc()
236 if (!bufmap->desc_array) in orangefs_bufmap_alloc()
239 bufmap->page_count = bufmap->total_size / PAGE_SIZE; in orangefs_bufmap_alloc()
242 bufmap->page_array = in orangefs_bufmap_alloc()
243 kcalloc(bufmap->page_count, sizeof(struct page *), GFP_KERNEL); in orangefs_bufmap_alloc()
244 if (!bufmap->page_array) in orangefs_bufmap_alloc()
250 kfree(bufmap->desc_array); in orangefs_bufmap_alloc()
252 bitmap_free(bufmap->buffer_index_array); in orangefs_bufmap_alloc()
263 int pages_per_desc = bufmap->desc_size / PAGE_SIZE; in orangefs_bufmap_map()
267 ret = pin_user_pages_fast((unsigned long)user_desc->ptr, in orangefs_bufmap_map()
268 bufmap->page_count, FOLL_WRITE, bufmap->page_array); in orangefs_bufmap_map()
273 if (ret != bufmap->page_count) { in orangefs_bufmap_map()
275 bufmap->page_count, ret); in orangefs_bufmap_map()
278 unpin_user_page(bufmap->page_array[i]); in orangefs_bufmap_map()
279 return -ENOMEM; in orangefs_bufmap_map()
288 for (i = 0; i < bufmap->page_count; i++) in orangefs_bufmap_map()
289 flush_dcache_page(bufmap->page_array[i]); in orangefs_bufmap_map()
292 for (offset = 0, i = 0; i < bufmap->desc_count; i++) { in orangefs_bufmap_map()
293 bufmap->desc_array[i].page_array = &bufmap->page_array[offset]; in orangefs_bufmap_map()
294 bufmap->desc_array[i].array_count = pages_per_desc; in orangefs_bufmap_map()
295 bufmap->desc_array[i].uaddr = in orangefs_bufmap_map()
296 (user_desc->ptr + (i * pages_per_desc * PAGE_SIZE)); in orangefs_bufmap_map()
308 * returns 0 on success, -errno on failure
313 int ret = -EINVAL; in orangefs_bufmap_initialize()
318 user_desc->ptr, in orangefs_bufmap_initialize()
319 user_desc->size, in orangefs_bufmap_initialize()
320 user_desc->count); in orangefs_bufmap_initialize()
322 if (user_desc->total_size < 0 || in orangefs_bufmap_initialize()
323 user_desc->size < 0 || in orangefs_bufmap_initialize()
324 user_desc->count < 0) in orangefs_bufmap_initialize()
331 if (PAGE_ALIGN((unsigned long)user_desc->ptr) != in orangefs_bufmap_initialize()
332 (unsigned long)user_desc->ptr) { in orangefs_bufmap_initialize()
334 user_desc->ptr); in orangefs_bufmap_initialize()
338 if (PAGE_ALIGN(((unsigned long)user_desc->ptr + user_desc->total_size)) in orangefs_bufmap_initialize()
339 != (unsigned long)(user_desc->ptr + user_desc->total_size)) { in orangefs_bufmap_initialize()
341 user_desc->ptr, in orangefs_bufmap_initialize()
342 user_desc->total_size); in orangefs_bufmap_initialize()
346 if (user_desc->total_size != (user_desc->size * user_desc->count)) { in orangefs_bufmap_initialize()
348 user_desc->total_size, in orangefs_bufmap_initialize()
349 user_desc->size, in orangefs_bufmap_initialize()
350 user_desc->count); in orangefs_bufmap_initialize()
354 if ((user_desc->size % PAGE_SIZE) != 0) { in orangefs_bufmap_initialize()
356 user_desc->size); in orangefs_bufmap_initialize()
360 ret = -ENOMEM; in orangefs_bufmap_initialize()
374 ret = -EINVAL; in orangefs_bufmap_initialize()
379 bufmap->desc_count, in orangefs_bufmap_initialize()
380 bufmap->buffer_index_array); in orangefs_bufmap_initialize()
383 bufmap->readdir_index_array); in orangefs_bufmap_initialize()
438 * returns slot on success, -errno on failure
464 * indices are used by the client-core.
466 * returns slot on success, -errno on failure
493 to = &__orangefs_bufmap->desc_array[buffer_index]; in orangefs_bufmap_copy_from_iovec()
495 struct page *page = to->page_array[i]; in orangefs_bufmap_copy_from_iovec()
500 return -EFAULT; in orangefs_bufmap_copy_from_iovec()
501 size -= n; in orangefs_bufmap_copy_from_iovec()
517 from = &__orangefs_bufmap->desc_array[buffer_index]; in orangefs_bufmap_copy_to_iovec()
524 struct page *page = from->page_array[i]; in orangefs_bufmap_copy_to_iovec()
530 return -EFAULT; in orangefs_bufmap_copy_to_iovec()
531 size -= n; in orangefs_bufmap_copy_to_iovec()
543 from = &__orangefs_bufmap->desc_array[buffer_index]; in orangefs_bufmap_page_fill()
544 page_from = kmap_atomic(from->page_array[slot_index]); in orangefs_bufmap_page_fill()