Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
trans_common.c
Go to the documentation of this file.
1 /*
2  * Copyright IBM Corporation, 2010
3  * Author Venkateswararao Jujjuri <[email protected]>
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 
25 void p9_release_pages(struct page **pages, int nr_pages)
26 {
27  int i = 0;
28  while (pages[i] && nr_pages--) {
29  put_page(pages[i]);
30  i++;
31  }
32 }
34 
38 int p9_nr_pages(char *data, int len)
39 {
40  unsigned long start_page, end_page;
41  start_page = (unsigned long)data >> PAGE_SHIFT;
42  end_page = ((unsigned long)data + len + PAGE_SIZE - 1) >> PAGE_SHIFT;
43  return end_page - start_page;
44 }
46 
57 int p9_payload_gup(char *data, int *nr_pages, struct page **pages, int write)
58 {
59  int nr_mapped_pages;
60 
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;
65 
66  *nr_pages = nr_mapped_pages;
67  return 0;
68 }