2015-07-17 14:38:13 +00:00
|
|
|
/*
|
|
|
|
* (C) 2001 Clemson University and The University of Chicago
|
|
|
|
*
|
|
|
|
* See COPYING in top-level directory.
|
|
|
|
*/
|
|
|
|
#include "protocol.h"
|
2015-12-04 17:56:14 +00:00
|
|
|
#include "orangefs-kernel.h"
|
|
|
|
#include "orangefs-bufmap.h"
|
2015-07-17 14:38:13 +00:00
|
|
|
|
2015-11-24 20:12:14 +00:00
|
|
|
DECLARE_WAIT_QUEUE_HEAD(orangefs_bufmap_init_waitq);
|
2015-07-17 14:38:13 +00:00
|
|
|
|
2015-12-15 19:45:12 +00:00
|
|
|
/* used to describe mapped buffers */
|
|
|
|
struct orangefs_bufmap_desc {
|
|
|
|
void *uaddr; /* user space address pointer */
|
|
|
|
struct page **page_array; /* array of mapped pages */
|
|
|
|
int array_count; /* size of above arrays */
|
|
|
|
struct list_head list_link;
|
|
|
|
};
|
|
|
|
|
2015-11-24 20:12:14 +00:00
|
|
|
static struct orangefs_bufmap {
|
2015-07-17 14:38:13 +00:00
|
|
|
atomic_t refcnt;
|
|
|
|
|
|
|
|
int desc_size;
|
|
|
|
int desc_shift;
|
|
|
|
int desc_count;
|
|
|
|
int total_size;
|
|
|
|
int page_count;
|
|
|
|
|
|
|
|
struct page **page_array;
|
2015-11-24 20:12:14 +00:00
|
|
|
struct orangefs_bufmap_desc *desc_array;
|
2015-07-17 14:38:13 +00:00
|
|
|
|
|
|
|
/* array to track usage of buffer descriptors */
|
|
|
|
int *buffer_index_array;
|
|
|
|
spinlock_t buffer_index_lock;
|
|
|
|
|
|
|
|
/* array to track usage of buffer descriptors for readdir */
|
2015-11-24 20:12:14 +00:00
|
|
|
int readdir_index_array[ORANGEFS_READDIR_DEFAULT_DESC_COUNT];
|
2015-07-17 14:38:13 +00:00
|
|
|
spinlock_t readdir_index_lock;
|
2015-11-24 20:12:14 +00:00
|
|
|
} *__orangefs_bufmap;
|
2015-07-17 14:38:13 +00:00
|
|
|
|
2015-11-24 20:12:14 +00:00
|
|
|
static DEFINE_SPINLOCK(orangefs_bufmap_lock);
|
2015-07-17 14:38:13 +00:00
|
|
|
|
|
|
|
static void
|
2015-11-24 20:12:14 +00:00
|
|
|
orangefs_bufmap_unmap(struct orangefs_bufmap *bufmap)
|
2015-07-17 14:38:13 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < bufmap->page_count; i++)
|
|
|
|
page_cache_release(bufmap->page_array[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-11-24 20:12:14 +00:00
|
|
|
orangefs_bufmap_free(struct orangefs_bufmap *bufmap)
|
2015-07-17 14:38:13 +00:00
|
|
|
{
|
|
|
|
kfree(bufmap->page_array);
|
|
|
|
kfree(bufmap->desc_array);
|
|
|
|
kfree(bufmap->buffer_index_array);
|
|
|
|
kfree(bufmap);
|
|
|
|
}
|
|
|
|
|
2015-12-15 19:45:12 +00:00
|
|
|
static struct orangefs_bufmap *orangefs_bufmap_ref(void)
|
2015-07-17 14:38:13 +00:00
|
|
|
{
|
2015-11-24 20:12:14 +00:00
|
|
|
struct orangefs_bufmap *bufmap = NULL;
|
2015-07-17 14:38:13 +00:00
|
|
|
|
2015-11-24 20:12:14 +00:00
|
|
|
spin_lock(&orangefs_bufmap_lock);
|
|
|
|
if (__orangefs_bufmap) {
|
|
|
|
bufmap = __orangefs_bufmap;
|
2015-07-17 14:38:13 +00:00
|
|
|
atomic_inc(&bufmap->refcnt);
|
|
|
|
}
|
2015-11-24 20:12:14 +00:00
|
|
|
spin_unlock(&orangefs_bufmap_lock);
|
2015-07-17 14:38:13 +00:00
|
|
|
return bufmap;
|
|
|
|
}
|
|
|
|
|
2015-12-15 19:45:12 +00:00
|
|
|
static void orangefs_bufmap_unref(struct orangefs_bufmap *bufmap)
|
2015-07-17 14:38:13 +00:00
|
|
|
{
|
2015-11-24 20:12:14 +00:00
|
|
|
if (atomic_dec_and_lock(&bufmap->refcnt, &orangefs_bufmap_lock)) {
|
|
|
|
__orangefs_bufmap = NULL;
|
|
|
|
spin_unlock(&orangefs_bufmap_lock);
|
2015-07-17 14:38:13 +00:00
|
|
|
|
2015-11-24 20:12:14 +00:00
|
|
|
orangefs_bufmap_unmap(bufmap);
|
|
|
|
orangefs_bufmap_free(bufmap);
|
2015-07-17 14:38:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-15 19:54:27 +00:00
|
|
|
/*
|
|
|
|
* XXX: Can the size and shift change while the caller gives up the
|
|
|
|
* XXX: lock between calling this and doing something useful?
|
|
|
|
*/
|
|
|
|
|
2015-12-15 19:48:17 +00:00
|
|
|
int orangefs_bufmap_size_query(void)
|
2015-07-17 14:38:13 +00:00
|
|
|
{
|
2015-12-15 19:54:27 +00:00
|
|
|
struct orangefs_bufmap *bufmap;
|
|
|
|
int size = 0;
|
|
|
|
bufmap = orangefs_bufmap_ref();
|
|
|
|
if (bufmap) {
|
|
|
|
size = bufmap->desc_size;
|
|
|
|
orangefs_bufmap_unref(bufmap);
|
|
|
|
}
|
2015-07-17 14:38:13 +00:00
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2015-12-15 19:48:17 +00:00
|
|
|
int orangefs_bufmap_shift_query(void)
|
2015-07-17 14:38:13 +00:00
|
|
|
{
|
2015-12-15 19:54:27 +00:00
|
|
|
struct orangefs_bufmap *bufmap;
|
|
|
|
int shift = 0;
|
|
|
|
bufmap = orangefs_bufmap_ref();
|
|
|
|
if (bufmap) {
|
|
|
|
shift = bufmap->desc_shift;
|
|
|
|
orangefs_bufmap_unref(bufmap);
|
|
|
|
}
|
2015-07-17 14:38:13 +00:00
|
|
|
return shift;
|
|
|
|
}
|
|
|
|
|
|
|
|
static DECLARE_WAIT_QUEUE_HEAD(bufmap_waitq);
|
|
|
|
static DECLARE_WAIT_QUEUE_HEAD(readdir_waitq);
|
|
|
|
|
|
|
|
/*
|
2016-01-04 20:05:28 +00:00
|
|
|
* orangefs_get_bufmap_init
|
2015-07-17 14:38:13 +00:00
|
|
|
*
|
|
|
|
* If bufmap_init is 1, then the shared memory system, including the
|
|
|
|
* buffer_index_array, is available. Otherwise, it is not.
|
|
|
|
*
|
|
|
|
* returns the value of bufmap_init
|
|
|
|
*/
|
2016-01-04 20:05:28 +00:00
|
|
|
int orangefs_get_bufmap_init(void)
|
2015-07-17 14:38:13 +00:00
|
|
|
{
|
2015-11-24 20:12:14 +00:00
|
|
|
return __orangefs_bufmap ? 1 : 0;
|
2015-07-17 14:38:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-11-24 20:12:14 +00:00
|
|
|
static struct orangefs_bufmap *
|
|
|
|
orangefs_bufmap_alloc(struct ORANGEFS_dev_map_desc *user_desc)
|
2015-07-17 14:38:13 +00:00
|
|
|
{
|
2015-11-24 20:12:14 +00:00
|
|
|
struct orangefs_bufmap *bufmap;
|
2015-07-17 14:38:13 +00:00
|
|
|
|
|
|
|
bufmap = kzalloc(sizeof(*bufmap), GFP_KERNEL);
|
|
|
|
if (!bufmap)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
atomic_set(&bufmap->refcnt, 1);
|
|
|
|
bufmap->total_size = user_desc->total_size;
|
|
|
|
bufmap->desc_count = user_desc->count;
|
|
|
|
bufmap->desc_size = user_desc->size;
|
|
|
|
bufmap->desc_shift = ilog2(bufmap->desc_size);
|
|
|
|
|
|
|
|
spin_lock_init(&bufmap->buffer_index_lock);
|
|
|
|
bufmap->buffer_index_array =
|
|
|
|
kcalloc(bufmap->desc_count, sizeof(int), GFP_KERNEL);
|
|
|
|
if (!bufmap->buffer_index_array) {
|
2015-11-24 20:12:14 +00:00
|
|
|
gossip_err("orangefs: could not allocate %d buffer indices\n",
|
2015-07-17 14:38:13 +00:00
|
|
|
bufmap->desc_count);
|
|
|
|
goto out_free_bufmap;
|
|
|
|
}
|
|
|
|
spin_lock_init(&bufmap->readdir_index_lock);
|
|
|
|
|
|
|
|
bufmap->desc_array =
|
2015-11-24 20:12:14 +00:00
|
|
|
kcalloc(bufmap->desc_count, sizeof(struct orangefs_bufmap_desc),
|
2015-07-17 14:38:13 +00:00
|
|
|
GFP_KERNEL);
|
|
|
|
if (!bufmap->desc_array) {
|
2015-11-24 20:12:14 +00:00
|
|
|
gossip_err("orangefs: could not allocate %d descriptors\n",
|
2015-07-17 14:38:13 +00:00
|
|
|
bufmap->desc_count);
|
|
|
|
goto out_free_index_array;
|
|
|
|
}
|
|
|
|
|
|
|
|
bufmap->page_count = bufmap->total_size / PAGE_SIZE;
|
|
|
|
|
|
|
|
/* allocate storage to track our page mappings */
|
|
|
|
bufmap->page_array =
|
|
|
|
kcalloc(bufmap->page_count, sizeof(struct page *), GFP_KERNEL);
|
|
|
|
if (!bufmap->page_array)
|
|
|
|
goto out_free_desc_array;
|
|
|
|
|
|
|
|
return bufmap;
|
|
|
|
|
|
|
|
out_free_desc_array:
|
|
|
|
kfree(bufmap->desc_array);
|
|
|
|
out_free_index_array:
|
|
|
|
kfree(bufmap->buffer_index_array);
|
|
|
|
out_free_bufmap:
|
|
|
|
kfree(bufmap);
|
|
|
|
out:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2015-11-24 20:12:14 +00:00
|
|
|
orangefs_bufmap_map(struct orangefs_bufmap *bufmap,
|
|
|
|
struct ORANGEFS_dev_map_desc *user_desc)
|
2015-07-17 14:38:13 +00:00
|
|
|
{
|
|
|
|
int pages_per_desc = bufmap->desc_size / PAGE_SIZE;
|
|
|
|
int offset = 0, ret, i;
|
|
|
|
|
|
|
|
/* map the pages */
|
2015-10-09 00:10:00 +00:00
|
|
|
ret = get_user_pages_fast((unsigned long)user_desc->ptr,
|
|
|
|
bufmap->page_count, 1, bufmap->page_array);
|
2015-07-17 14:38:13 +00:00
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
if (ret != bufmap->page_count) {
|
2015-11-24 20:12:14 +00:00
|
|
|
gossip_err("orangefs error: asked for %d pages, only got %d.\n",
|
2015-07-17 14:38:13 +00:00
|
|
|
bufmap->page_count, ret);
|
|
|
|
|
|
|
|
for (i = 0; i < ret; i++) {
|
|
|
|
SetPageError(bufmap->page_array[i]);
|
|
|
|
page_cache_release(bufmap->page_array[i]);
|
|
|
|
}
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ideally we want to get kernel space pointers for each page, but
|
|
|
|
* we can't kmap that many pages at once if highmem is being used.
|
|
|
|
* so instead, we just kmap/kunmap the page address each time the
|
|
|
|
* kaddr is needed.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < bufmap->page_count; i++)
|
|
|
|
flush_dcache_page(bufmap->page_array[i]);
|
|
|
|
|
|
|
|
/* build a list of available descriptors */
|
|
|
|
for (offset = 0, i = 0; i < bufmap->desc_count; i++) {
|
|
|
|
bufmap->desc_array[i].page_array = &bufmap->page_array[offset];
|
|
|
|
bufmap->desc_array[i].array_count = pages_per_desc;
|
|
|
|
bufmap->desc_array[i].uaddr =
|
|
|
|
(user_desc->ptr + (i * pages_per_desc * PAGE_SIZE));
|
|
|
|
offset += pages_per_desc;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2015-11-24 20:12:14 +00:00
|
|
|
* orangefs_bufmap_initialize()
|
2015-07-17 14:38:13 +00:00
|
|
|
*
|
|
|
|
* initializes the mapped buffer interface
|
|
|
|
*
|
|
|
|
* returns 0 on success, -errno on failure
|
|
|
|
*/
|
2015-11-24 20:12:14 +00:00
|
|
|
int orangefs_bufmap_initialize(struct ORANGEFS_dev_map_desc *user_desc)
|
2015-07-17 14:38:13 +00:00
|
|
|
{
|
2015-11-24 20:12:14 +00:00
|
|
|
struct orangefs_bufmap *bufmap;
|
2015-07-17 14:38:13 +00:00
|
|
|
int ret = -EINVAL;
|
|
|
|
|
|
|
|
gossip_debug(GOSSIP_BUFMAP_DEBUG,
|
2015-11-24 20:12:14 +00:00
|
|
|
"orangefs_bufmap_initialize: called (ptr ("
|
2015-07-17 14:38:13 +00:00
|
|
|
"%p) sz (%d) cnt(%d).\n",
|
|
|
|
user_desc->ptr,
|
|
|
|
user_desc->size,
|
|
|
|
user_desc->count);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* sanity check alignment and size of buffer that caller wants to
|
|
|
|
* work with
|
|
|
|
*/
|
|
|
|
if (PAGE_ALIGN((unsigned long)user_desc->ptr) !=
|
|
|
|
(unsigned long)user_desc->ptr) {
|
2015-11-24 20:12:14 +00:00
|
|
|
gossip_err("orangefs error: memory alignment (front). %p\n",
|
2015-07-17 14:38:13 +00:00
|
|
|
user_desc->ptr);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PAGE_ALIGN(((unsigned long)user_desc->ptr + user_desc->total_size))
|
|
|
|
!= (unsigned long)(user_desc->ptr + user_desc->total_size)) {
|
2015-11-24 20:12:14 +00:00
|
|
|
gossip_err("orangefs error: memory alignment (back).(%p + %d)\n",
|
2015-07-17 14:38:13 +00:00
|
|
|
user_desc->ptr,
|
|
|
|
user_desc->total_size);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (user_desc->total_size != (user_desc->size * user_desc->count)) {
|
2015-11-24 20:12:14 +00:00
|
|
|
gossip_err("orangefs error: user provided an oddly sized buffer: (%d, %d, %d)\n",
|
2015-07-17 14:38:13 +00:00
|
|
|
user_desc->total_size,
|
|
|
|
user_desc->size,
|
|
|
|
user_desc->count);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((user_desc->size % PAGE_SIZE) != 0) {
|
2015-11-24 20:12:14 +00:00
|
|
|
gossip_err("orangefs error: bufmap size not page size divisible (%d).\n",
|
2015-07-17 14:38:13 +00:00
|
|
|
user_desc->size);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = -ENOMEM;
|
2015-11-24 20:12:14 +00:00
|
|
|
bufmap = orangefs_bufmap_alloc(user_desc);
|
2015-07-17 14:38:13 +00:00
|
|
|
if (!bufmap)
|
|
|
|
goto out;
|
|
|
|
|
2015-11-24 20:12:14 +00:00
|
|
|
ret = orangefs_bufmap_map(bufmap, user_desc);
|
2015-07-17 14:38:13 +00:00
|
|
|
if (ret)
|
|
|
|
goto out_free_bufmap;
|
|
|
|
|
|
|
|
|
2015-11-24 20:12:14 +00:00
|
|
|
spin_lock(&orangefs_bufmap_lock);
|
|
|
|
if (__orangefs_bufmap) {
|
|
|
|
spin_unlock(&orangefs_bufmap_lock);
|
|
|
|
gossip_err("orangefs: error: bufmap already initialized.\n");
|
2015-07-17 14:38:13 +00:00
|
|
|
ret = -EALREADY;
|
|
|
|
goto out_unmap_bufmap;
|
|
|
|
}
|
2015-11-24 20:12:14 +00:00
|
|
|
__orangefs_bufmap = bufmap;
|
|
|
|
spin_unlock(&orangefs_bufmap_lock);
|
2015-07-17 14:38:13 +00:00
|
|
|
|
|
|
|
/*
|
2015-11-24 20:12:14 +00:00
|
|
|
* If there are operations in orangefs_bufmap_init_waitq, wake them up.
|
2015-07-17 14:38:13 +00:00
|
|
|
* This scenario occurs when the client-core is restarted and I/O
|
|
|
|
* requests in the in-progress or waiting tables are restarted. I/O
|
|
|
|
* requests cannot be restarted until the shared memory system is
|
|
|
|
* completely re-initialized, so we put the I/O requests in this
|
|
|
|
* waitq until initialization has completed. NOTE: the I/O requests
|
|
|
|
* are also on a timer, so they don't wait forever just in case the
|
|
|
|
* client-core doesn't come back up.
|
|
|
|
*/
|
2015-11-24 20:12:14 +00:00
|
|
|
wake_up_interruptible(&orangefs_bufmap_init_waitq);
|
2015-07-17 14:38:13 +00:00
|
|
|
|
|
|
|
gossip_debug(GOSSIP_BUFMAP_DEBUG,
|
2015-11-24 20:12:14 +00:00
|
|
|
"orangefs_bufmap_initialize: exiting normally\n");
|
2015-07-17 14:38:13 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
out_unmap_bufmap:
|
2015-11-24 20:12:14 +00:00
|
|
|
orangefs_bufmap_unmap(bufmap);
|
2015-07-17 14:38:13 +00:00
|
|
|
out_free_bufmap:
|
2015-11-24 20:12:14 +00:00
|
|
|
orangefs_bufmap_free(bufmap);
|
2015-07-17 14:38:13 +00:00
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2015-11-24 20:12:14 +00:00
|
|
|
* orangefs_bufmap_finalize()
|
2015-07-17 14:38:13 +00:00
|
|
|
*
|
|
|
|
* shuts down the mapped buffer interface and releases any resources
|
|
|
|
* associated with it
|
|
|
|
*
|
|
|
|
* no return value
|
|
|
|
*/
|
2015-11-24 20:12:14 +00:00
|
|
|
void orangefs_bufmap_finalize(void)
|
2015-07-17 14:38:13 +00:00
|
|
|
{
|
2015-11-24 20:12:14 +00:00
|
|
|
gossip_debug(GOSSIP_BUFMAP_DEBUG, "orangefs_bufmap_finalize: called\n");
|
|
|
|
BUG_ON(!__orangefs_bufmap);
|
|
|
|
orangefs_bufmap_unref(__orangefs_bufmap);
|
2015-07-17 14:38:13 +00:00
|
|
|
gossip_debug(GOSSIP_BUFMAP_DEBUG,
|
2015-11-24 20:12:14 +00:00
|
|
|
"orangefs_bufmap_finalize: exiting normally\n");
|
2015-07-17 14:38:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct slot_args {
|
|
|
|
int slot_count;
|
|
|
|
int *slot_array;
|
|
|
|
spinlock_t *slot_lock;
|
|
|
|
wait_queue_head_t *slot_wq;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int wait_for_a_slot(struct slot_args *slargs, int *buffer_index)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
int i = 0;
|
2015-12-14 19:54:46 +00:00
|
|
|
DEFINE_WAIT(wait_entry);
|
2015-07-17 14:38:13 +00:00
|
|
|
|
|
|
|
while (1) {
|
|
|
|
/*
|
|
|
|
* check for available desc, slot_lock is the appropriate
|
|
|
|
* index_lock
|
|
|
|
*/
|
|
|
|
spin_lock(slargs->slot_lock);
|
2015-12-14 19:54:46 +00:00
|
|
|
prepare_to_wait_exclusive(slargs->slot_wq,
|
|
|
|
&wait_entry,
|
|
|
|
TASK_INTERRUPTIBLE);
|
2015-07-17 14:38:13 +00:00
|
|
|
for (i = 0; i < slargs->slot_count; i++)
|
|
|
|
if (slargs->slot_array[i] == 0) {
|
|
|
|
slargs->slot_array[i] = 1;
|
|
|
|
*buffer_index = i;
|
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
spin_unlock(slargs->slot_lock);
|
|
|
|
|
|
|
|
/* if we acquired a buffer, then break out of while */
|
|
|
|
if (ret == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (!signal_pending(current)) {
|
|
|
|
gossip_debug(GOSSIP_BUFMAP_DEBUG,
|
|
|
|
"[BUFMAP]: waiting %d "
|
|
|
|
"seconds for a slot\n",
|
|
|
|
slot_timeout_secs);
|
2016-01-23 18:17:55 +00:00
|
|
|
if (!schedule_timeout(slot_timeout_secs * HZ)) {
|
2015-07-17 14:38:13 +00:00
|
|
|
gossip_debug(GOSSIP_BUFMAP_DEBUG,
|
|
|
|
"*** wait_for_a_slot timed out\n");
|
|
|
|
ret = -ETIMEDOUT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
gossip_debug(GOSSIP_BUFMAP_DEBUG,
|
|
|
|
"[BUFMAP]: woken up by a slot becoming available.\n");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-11-24 20:12:14 +00:00
|
|
|
gossip_debug(GOSSIP_BUFMAP_DEBUG, "orangefs: %s interrupted.\n",
|
2015-07-17 14:38:13 +00:00
|
|
|
__func__);
|
|
|
|
ret = -EINTR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-12-14 19:54:46 +00:00
|
|
|
spin_lock(slargs->slot_lock);
|
|
|
|
finish_wait(slargs->slot_wq, &wait_entry);
|
|
|
|
spin_unlock(slargs->slot_lock);
|
2015-07-17 14:38:13 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void put_back_slot(struct slot_args *slargs, int buffer_index)
|
|
|
|
{
|
|
|
|
/* slot_lock is the appropriate index_lock */
|
|
|
|
spin_lock(slargs->slot_lock);
|
|
|
|
if (buffer_index < 0 || buffer_index >= slargs->slot_count) {
|
|
|
|
spin_unlock(slargs->slot_lock);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* put the desc back on the queue */
|
|
|
|
slargs->slot_array[buffer_index] = 0;
|
|
|
|
spin_unlock(slargs->slot_lock);
|
|
|
|
|
|
|
|
/* wake up anyone who may be sleeping on the queue */
|
|
|
|
wake_up_interruptible(slargs->slot_wq);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2015-11-24 20:12:14 +00:00
|
|
|
* orangefs_bufmap_get()
|
2015-07-17 14:38:13 +00:00
|
|
|
*
|
|
|
|
* gets a free mapped buffer descriptor, will sleep until one becomes
|
|
|
|
* available if necessary
|
|
|
|
*
|
|
|
|
* returns 0 on success, -errno on failure
|
|
|
|
*/
|
2015-11-24 20:12:14 +00:00
|
|
|
int orangefs_bufmap_get(struct orangefs_bufmap **mapp, int *buffer_index)
|
2015-07-17 14:38:13 +00:00
|
|
|
{
|
2015-11-24 20:12:14 +00:00
|
|
|
struct orangefs_bufmap *bufmap = orangefs_bufmap_ref();
|
2015-07-17 14:38:13 +00:00
|
|
|
struct slot_args slargs;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!bufmap) {
|
2015-11-24 20:12:14 +00:00
|
|
|
gossip_err("orangefs: please confirm that pvfs2-client daemon is running.\n");
|
2015-07-17 14:38:13 +00:00
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
slargs.slot_count = bufmap->desc_count;
|
|
|
|
slargs.slot_array = bufmap->buffer_index_array;
|
|
|
|
slargs.slot_lock = &bufmap->buffer_index_lock;
|
|
|
|
slargs.slot_wq = &bufmap_waitq;
|
|
|
|
ret = wait_for_a_slot(&slargs, buffer_index);
|
|
|
|
if (ret)
|
2015-11-24 20:12:14 +00:00
|
|
|
orangefs_bufmap_unref(bufmap);
|
2015-07-17 14:38:13 +00:00
|
|
|
*mapp = bufmap;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2015-11-24 20:12:14 +00:00
|
|
|
* orangefs_bufmap_put()
|
2015-07-17 14:38:13 +00:00
|
|
|
*
|
|
|
|
* returns a mapped buffer descriptor to the collection
|
|
|
|
*
|
|
|
|
* no return value
|
|
|
|
*/
|
2016-02-12 02:34:52 +00:00
|
|
|
void orangefs_bufmap_put(int buffer_index)
|
2015-07-17 14:38:13 +00:00
|
|
|
{
|
|
|
|
struct slot_args slargs;
|
2016-02-12 02:34:52 +00:00
|
|
|
struct orangefs_bufmap *bufmap = __orangefs_bufmap;
|
2015-07-17 14:38:13 +00:00
|
|
|
|
|
|
|
slargs.slot_count = bufmap->desc_count;
|
|
|
|
slargs.slot_array = bufmap->buffer_index_array;
|
|
|
|
slargs.slot_lock = &bufmap->buffer_index_lock;
|
|
|
|
slargs.slot_wq = &bufmap_waitq;
|
|
|
|
put_back_slot(&slargs, buffer_index);
|
2015-11-24 20:12:14 +00:00
|
|
|
orangefs_bufmap_unref(bufmap);
|
2015-07-17 14:38:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2016-01-04 20:05:28 +00:00
|
|
|
* orangefs_readdir_index_get()
|
2015-07-17 14:38:13 +00:00
|
|
|
*
|
|
|
|
* gets a free descriptor, will sleep until one becomes
|
|
|
|
* available if necessary.
|
|
|
|
* Although the readdir buffers are not mapped into kernel space
|
|
|
|
* we could do that at a later point of time. Regardless, these
|
|
|
|
* indices are used by the client-core.
|
|
|
|
*
|
|
|
|
* returns 0 on success, -errno on failure
|
|
|
|
*/
|
2016-01-04 20:05:28 +00:00
|
|
|
int orangefs_readdir_index_get(struct orangefs_bufmap **mapp, int *buffer_index)
|
2015-07-17 14:38:13 +00:00
|
|
|
{
|
2015-11-24 20:12:14 +00:00
|
|
|
struct orangefs_bufmap *bufmap = orangefs_bufmap_ref();
|
2015-07-17 14:38:13 +00:00
|
|
|
struct slot_args slargs;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!bufmap) {
|
2015-11-24 20:12:14 +00:00
|
|
|
gossip_err("orangefs: please confirm that pvfs2-client daemon is running.\n");
|
2015-07-17 14:38:13 +00:00
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
2015-11-24 20:12:14 +00:00
|
|
|
slargs.slot_count = ORANGEFS_READDIR_DEFAULT_DESC_COUNT;
|
2015-07-17 14:38:13 +00:00
|
|
|
slargs.slot_array = bufmap->readdir_index_array;
|
|
|
|
slargs.slot_lock = &bufmap->readdir_index_lock;
|
|
|
|
slargs.slot_wq = &readdir_waitq;
|
|
|
|
ret = wait_for_a_slot(&slargs, buffer_index);
|
|
|
|
if (ret)
|
2015-11-24 20:12:14 +00:00
|
|
|
orangefs_bufmap_unref(bufmap);
|
2015-07-17 14:38:13 +00:00
|
|
|
*mapp = bufmap;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-01-04 20:05:28 +00:00
|
|
|
void orangefs_readdir_index_put(struct orangefs_bufmap *bufmap, int buffer_index)
|
2015-07-17 14:38:13 +00:00
|
|
|
{
|
|
|
|
struct slot_args slargs;
|
|
|
|
|
2015-11-24 20:12:14 +00:00
|
|
|
slargs.slot_count = ORANGEFS_READDIR_DEFAULT_DESC_COUNT;
|
2015-07-17 14:38:13 +00:00
|
|
|
slargs.slot_array = bufmap->readdir_index_array;
|
|
|
|
slargs.slot_lock = &bufmap->readdir_index_lock;
|
|
|
|
slargs.slot_wq = &readdir_waitq;
|
|
|
|
put_back_slot(&slargs, buffer_index);
|
2015-11-24 20:12:14 +00:00
|
|
|
orangefs_bufmap_unref(bufmap);
|
2015-07-17 14:38:13 +00:00
|
|
|
}
|
|
|
|
|
2015-12-11 15:50:42 +00:00
|
|
|
/*
|
|
|
|
* we've been handed an iovec, we need to copy it to
|
|
|
|
* the shared memory descriptor at "buffer_index".
|
|
|
|
*/
|
2015-11-24 20:12:14 +00:00
|
|
|
int orangefs_bufmap_copy_from_iovec(struct orangefs_bufmap *bufmap,
|
2015-10-05 17:44:24 +00:00
|
|
|
struct iov_iter *iter,
|
|
|
|
int buffer_index,
|
|
|
|
size_t size)
|
2015-07-17 14:38:13 +00:00
|
|
|
{
|
2015-11-24 20:12:14 +00:00
|
|
|
struct orangefs_bufmap_desc *to = &bufmap->desc_array[buffer_index];
|
2015-09-04 14:31:16 +00:00
|
|
|
int i;
|
2015-07-17 14:38:13 +00:00
|
|
|
|
|
|
|
gossip_debug(GOSSIP_BUFMAP_DEBUG,
|
2015-10-08 21:47:44 +00:00
|
|
|
"%s: buffer_index:%d: size:%zu:\n",
|
2015-09-04 14:31:16 +00:00
|
|
|
__func__, buffer_index, size);
|
2015-07-17 14:38:13 +00:00
|
|
|
|
|
|
|
|
2015-09-04 14:31:16 +00:00
|
|
|
for (i = 0; size; i++) {
|
2015-10-08 21:47:44 +00:00
|
|
|
struct page *page = to->page_array[i];
|
|
|
|
size_t n = size;
|
|
|
|
if (n > PAGE_SIZE)
|
|
|
|
n = PAGE_SIZE;
|
|
|
|
n = copy_page_from_iter(page, 0, n, iter);
|
|
|
|
if (!n)
|
|
|
|
return -EFAULT;
|
|
|
|
size -= n;
|
2015-07-17 14:38:13 +00:00
|
|
|
}
|
2015-10-08 21:47:44 +00:00
|
|
|
return 0;
|
2015-07-17 14:38:13 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2015-12-11 15:50:42 +00:00
|
|
|
* we've been handed an iovec, we need to fill it from
|
|
|
|
* the shared memory descriptor at "buffer_index".
|
2015-07-17 14:38:13 +00:00
|
|
|
*/
|
2015-11-24 20:12:14 +00:00
|
|
|
int orangefs_bufmap_copy_to_iovec(struct orangefs_bufmap *bufmap,
|
2015-09-04 14:31:16 +00:00
|
|
|
struct iov_iter *iter,
|
2015-10-08 21:43:58 +00:00
|
|
|
int buffer_index,
|
|
|
|
size_t size)
|
2015-07-17 14:38:13 +00:00
|
|
|
{
|
2015-11-24 20:12:14 +00:00
|
|
|
struct orangefs_bufmap_desc *from = &bufmap->desc_array[buffer_index];
|
2015-09-04 14:31:16 +00:00
|
|
|
int i;
|
2015-07-17 14:38:13 +00:00
|
|
|
|
|
|
|
gossip_debug(GOSSIP_BUFMAP_DEBUG,
|
2015-10-08 21:43:58 +00:00
|
|
|
"%s: buffer_index:%d: size:%zu:\n",
|
|
|
|
__func__, buffer_index, size);
|
2015-07-17 14:38:13 +00:00
|
|
|
|
|
|
|
|
2015-10-08 21:43:58 +00:00
|
|
|
for (i = 0; size; i++) {
|
|
|
|
struct page *page = from->page_array[i];
|
|
|
|
size_t n = size;
|
|
|
|
if (n > PAGE_SIZE)
|
|
|
|
n = PAGE_SIZE;
|
|
|
|
n = copy_page_to_iter(page, 0, n, iter);
|
|
|
|
if (!n)
|
|
|
|
return -EFAULT;
|
|
|
|
size -= n;
|
2015-07-17 14:38:13 +00:00
|
|
|
}
|
2015-10-08 21:43:58 +00:00
|
|
|
return 0;
|
2015-07-17 14:38:13 +00:00
|
|
|
}
|