mirror of
https://github.com/tbsdtv/linux_media.git
synced 2025-07-23 12:43:29 +02:00
sunrpc: clean-up cache downcall
We can simplify code around cache_downcall unifying memory allocations using kvmalloc. This has the benefit of getting rid of cache_slow_downcall (and queue_io_mutex), and also matches userland allocation size and limits. Signed-off-by: Roberto Bergantinos Corpas <rbergant@redhat.com> Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
This commit is contained in:
committed by
Chuck Lever
parent
4420440c57
commit
4b5cff7ed8
@@ -778,7 +778,6 @@ void cache_clean_deferred(void *owner)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
static DEFINE_SPINLOCK(queue_lock);
|
static DEFINE_SPINLOCK(queue_lock);
|
||||||
static DEFINE_MUTEX(queue_io_mutex);
|
|
||||||
|
|
||||||
struct cache_queue {
|
struct cache_queue {
|
||||||
struct list_head list;
|
struct list_head list;
|
||||||
@@ -906,44 +905,26 @@ static ssize_t cache_do_downcall(char *kaddr, const char __user *buf,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t cache_slow_downcall(const char __user *buf,
|
|
||||||
size_t count, struct cache_detail *cd)
|
|
||||||
{
|
|
||||||
static char write_buf[32768]; /* protected by queue_io_mutex */
|
|
||||||
ssize_t ret = -EINVAL;
|
|
||||||
|
|
||||||
if (count >= sizeof(write_buf))
|
|
||||||
goto out;
|
|
||||||
mutex_lock(&queue_io_mutex);
|
|
||||||
ret = cache_do_downcall(write_buf, buf, count, cd);
|
|
||||||
mutex_unlock(&queue_io_mutex);
|
|
||||||
out:
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static ssize_t cache_downcall(struct address_space *mapping,
|
static ssize_t cache_downcall(struct address_space *mapping,
|
||||||
const char __user *buf,
|
const char __user *buf,
|
||||||
size_t count, struct cache_detail *cd)
|
size_t count, struct cache_detail *cd)
|
||||||
{
|
{
|
||||||
struct page *page;
|
char *write_buf;
|
||||||
char *kaddr;
|
|
||||||
ssize_t ret = -ENOMEM;
|
ssize_t ret = -ENOMEM;
|
||||||
|
|
||||||
if (count >= PAGE_SIZE)
|
if (count >= 32768) { /* 32k is max userland buffer, lets check anyway */
|
||||||
goto out_slow;
|
ret = -EINVAL;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
page = find_or_create_page(mapping, 0, GFP_KERNEL);
|
write_buf = kvmalloc(count + 1, GFP_KERNEL);
|
||||||
if (!page)
|
if (!write_buf)
|
||||||
goto out_slow;
|
goto out;
|
||||||
|
|
||||||
kaddr = kmap(page);
|
ret = cache_do_downcall(write_buf, buf, count, cd);
|
||||||
ret = cache_do_downcall(kaddr, buf, count, cd);
|
kvfree(write_buf);
|
||||||
kunmap(page);
|
out:
|
||||||
unlock_page(page);
|
|
||||||
put_page(page);
|
|
||||||
return ret;
|
return ret;
|
||||||
out_slow:
|
|
||||||
return cache_slow_downcall(buf, count, cd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t cache_write(struct file *filp, const char __user *buf,
|
static ssize_t cache_write(struct file *filp, const char __user *buf,
|
||||||
|
Reference in New Issue
Block a user