ia64/linux-2.6.18-xen.hg

view drivers/xen/blkback/blkback-pagemap.c @ 894:4e5cd2fc45a7

linux: fix blkback/blktap2 interaction

blkback's page map code needs to be accessible to both blkback and
blktap2, irrespective of whether either or both are modules. The
most immediate solution is to break it out into a separate, library-
like component that doesn't need building if either of the two
consumers is configured off, and that gets built as a module if both
consumers are modules.

Also fix the dummy implementation of blkback_pagemap_read(), since
using BUG() there doesn't compile.

Signed-off-by: Jan Beulich <jbeulich@novell.com>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Jun 04 10:33:52 2009 +0100 (2009-06-04)
parents eba6fe6d8d53
children
line source
1 #include <linux/module.h>
2 #include "blkback-pagemap.h"
4 static int blkback_pagemap_size;
5 static struct blkback_pagemap *blkback_pagemap;
7 static inline int
8 blkback_pagemap_entry_clear(struct blkback_pagemap *map)
9 {
10 static struct blkback_pagemap zero;
11 return !memcmp(map, &zero, sizeof(zero));
12 }
14 int
15 blkback_pagemap_init(int pages)
16 {
17 blkback_pagemap = kzalloc(pages * sizeof(struct blkback_pagemap),
18 GFP_KERNEL);
19 if (!blkback_pagemap)
20 return -ENOMEM;
22 blkback_pagemap_size = pages;
23 return 0;
24 }
25 EXPORT_SYMBOL_GPL(blkback_pagemap_init);
27 void
28 blkback_pagemap_set(int idx, struct page *page,
29 domid_t domid, busid_t busid, grant_ref_t gref)
30 {
31 struct blkback_pagemap *entry;
33 BUG_ON(!blkback_pagemap);
34 BUG_ON(idx >= blkback_pagemap_size);
36 SetPageBlkback(page);
37 set_page_private(page, idx);
39 entry = blkback_pagemap + idx;
40 if (!blkback_pagemap_entry_clear(entry)) {
41 printk("overwriting pagemap %d: d %u b %u g %u\n",
42 idx, entry->domid, entry->busid, entry->gref);
43 BUG();
44 }
46 entry->domid = domid;
47 entry->busid = busid;
48 entry->gref = gref;
49 }
50 EXPORT_SYMBOL_GPL(blkback_pagemap_set);
52 void
53 blkback_pagemap_clear(struct page *page)
54 {
55 int idx;
56 struct blkback_pagemap *entry;
58 idx = (int)page_private(page);
60 BUG_ON(!blkback_pagemap);
61 BUG_ON(!PageBlkback(page));
62 BUG_ON(idx >= blkback_pagemap_size);
64 entry = blkback_pagemap + idx;
65 if (blkback_pagemap_entry_clear(entry)) {
66 printk("clearing empty pagemap %d\n", idx);
67 BUG();
68 }
70 memset(entry, 0, sizeof(*entry));
71 }
72 EXPORT_SYMBOL_GPL(blkback_pagemap_clear);
74 struct blkback_pagemap
75 blkback_pagemap_read(struct page *page)
76 {
77 int idx;
78 struct blkback_pagemap *entry;
80 idx = (int)page_private(page);
82 BUG_ON(!blkback_pagemap);
83 BUG_ON(!PageBlkback(page));
84 BUG_ON(idx >= blkback_pagemap_size);
86 entry = blkback_pagemap + idx;
87 if (blkback_pagemap_entry_clear(entry)) {
88 printk("reading empty pagemap %d\n", idx);
89 BUG();
90 }
92 return *entry;
93 }
94 EXPORT_SYMBOL(blkback_pagemap_read);
96 MODULE_LICENSE("Dual BSD/GPL");