| Venkateswararao Jujjuri (JV) | 022cae3 | 2011-01-28 14:11:13 -0800 | [diff] [blame] | 1 | /* | 
 | 2 |  * Copyright IBM Corporation, 2010 | 
 | 3 |  * Author Venkateswararao Jujjuri <jvrao@linux.vnet.ibm.com> | 
 | 4 |  * | 
 | 5 |  * This program is free software; you can redistribute it and/or modify it | 
 | 6 |  * under the terms of version 2.1 of the GNU Lesser General Public License | 
 | 7 |  * as published by the Free Software Foundation. | 
 | 8 |  * | 
 | 9 |  * This program is distributed in the hope that it would be useful, but | 
 | 10 |  * WITHOUT ANY WARRANTY; without even the implied warranty of | 
 | 11 |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | 
 | 12 |  * | 
 | 13 |  */ | 
 | 14 |  | 
 | 15 | #include <linux/slab.h> | 
 | 16 | #include <linux/module.h> | 
 | 17 | #include <net/9p/9p.h> | 
 | 18 | #include <net/9p/client.h> | 
 | 19 | #include <linux/scatterlist.h> | 
 | 20 | #include "trans_common.h" | 
 | 21 |  | 
 | 22 | /** | 
 | 23 |  *  p9_release_req_pages - Release pages after the transaction. | 
| Venkateswararao Jujjuri (JV) | 022cae3 | 2011-01-28 14:11:13 -0800 | [diff] [blame] | 24 |  */ | 
| Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame] | 25 | void p9_release_pages(struct page **pages, int nr_pages) | 
| Venkateswararao Jujjuri (JV) | 022cae3 | 2011-01-28 14:11:13 -0800 | [diff] [blame] | 26 | { | 
 | 27 | 	int i = 0; | 
| Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame] | 28 | 	while (pages[i] && nr_pages--) { | 
 | 29 | 		put_page(pages[i]); | 
| Venkateswararao Jujjuri (JV) | 022cae3 | 2011-01-28 14:11:13 -0800 | [diff] [blame] | 30 | 		i++; | 
 | 31 | 	} | 
 | 32 | } | 
| Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame] | 33 | EXPORT_SYMBOL(p9_release_pages); | 
| Venkateswararao Jujjuri (JV) | 022cae3 | 2011-01-28 14:11:13 -0800 | [diff] [blame] | 34 |  | 
 | 35 | /** | 
| Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 36 |  * p9_nr_pages - Return number of pages needed to accommodate the payload. | 
| Venkateswararao Jujjuri (JV) | 022cae3 | 2011-01-28 14:11:13 -0800 | [diff] [blame] | 37 |  */ | 
| Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame] | 38 | int p9_nr_pages(char *data, int len) | 
| Venkateswararao Jujjuri (JV) | 022cae3 | 2011-01-28 14:11:13 -0800 | [diff] [blame] | 39 | { | 
| Aneesh Kumar K.V | 472e7f9 | 2011-03-08 16:39:47 +0530 | [diff] [blame] | 40 | 	unsigned long start_page, end_page; | 
| Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame] | 41 | 	start_page =  (unsigned long)data >> PAGE_SHIFT; | 
 | 42 | 	end_page = ((unsigned long)data + len + PAGE_SIZE - 1) >> PAGE_SHIFT; | 
| Venkateswararao Jujjuri (JV) | 022cae3 | 2011-01-28 14:11:13 -0800 | [diff] [blame] | 43 | 	return end_page - start_page; | 
 | 44 | } | 
 | 45 | EXPORT_SYMBOL(p9_nr_pages); | 
 | 46 |  | 
 | 47 | /** | 
 | 48 |  * payload_gup - Translates user buffer into kernel pages and | 
 | 49 |  * pins them either for read/write through get_user_pages_fast(). | 
 | 50 |  * @req: Request to be sent to server. | 
 | 51 |  * @pdata_off: data offset into the first page after translation (gup). | 
 | 52 |  * @pdata_len: Total length of the IO. gup may not return requested # of pages. | 
| Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 53 |  * @nr_pages: number of pages to accommodate the payload | 
| Venkateswararao Jujjuri (JV) | 022cae3 | 2011-01-28 14:11:13 -0800 | [diff] [blame] | 54 |  * @rw: Indicates if the pages are for read or write. | 
 | 55 |  */ | 
| Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame] | 56 |  | 
 | 57 | int p9_payload_gup(char *data, int *nr_pages, struct page **pages, int write) | 
| Venkateswararao Jujjuri (JV) | 022cae3 | 2011-01-28 14:11:13 -0800 | [diff] [blame] | 58 | { | 
| Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame] | 59 | 	int nr_mapped_pages; | 
| Venkateswararao Jujjuri (JV) | 022cae3 | 2011-01-28 14:11:13 -0800 | [diff] [blame] | 60 |  | 
| Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame] | 61 | 	nr_mapped_pages = get_user_pages_fast((unsigned long)data, | 
 | 62 | 					      *nr_pages, write, pages); | 
 | 63 | 	if (nr_mapped_pages <= 0) | 
 | 64 | 		return nr_mapped_pages; | 
| Venkateswararao Jujjuri (JV) | 022cae3 | 2011-01-28 14:11:13 -0800 | [diff] [blame] | 65 |  | 
| Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame] | 66 | 	*nr_pages = nr_mapped_pages; | 
| Venkateswararao Jujjuri (JV) | 022cae3 | 2011-01-28 14:11:13 -0800 | [diff] [blame] | 67 | 	return 0; | 
 | 68 | } | 
 | 69 | EXPORT_SYMBOL(p9_payload_gup); |