blob: f647e2cceaa673f8098fce058832a3cc55ce23c4 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Copyright (C) 2003 Sistina Software
3 *
4 * This file is released under the GPL.
5 */
6
7#ifndef _DM_IO_H
8#define _DM_IO_H
9
10#include "dm.h"
11
Linus Torvalds1da177e2005-04-16 15:20:36 -070012struct io_region {
13 struct block_device *bdev;
14 sector_t sector;
Milan Brozbf17ce32007-05-09 02:33:05 -070015 sector_t count; /* If this is zero the region is ignored. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070016};
17
18struct page_list {
19 struct page_list *next;
20 struct page *page;
21};
22
Linus Torvalds1da177e2005-04-16 15:20:36 -070023typedef void (*io_notify_fn)(unsigned long error, void *context);
24
Heinz Mauelshagenc8b03af2007-05-09 02:33:01 -070025enum dm_io_mem_type {
26 DM_IO_PAGE_LIST,/* Page list */
27 DM_IO_BVEC, /* Bio vector */
28 DM_IO_VMA, /* Virtual memory area */
29 DM_IO_KMEM, /* Kernel memory */
30};
31
32struct dm_io_memory {
33 enum dm_io_mem_type type;
34
35 union {
36 struct page_list *pl;
37 struct bio_vec *bvec;
38 void *vma;
39 void *addr;
40 } ptr;
41
42 unsigned offset;
43};
44
45struct dm_io_notify {
46 io_notify_fn fn; /* Callback for asynchronous requests */
47 void *context; /* Passed to callback */
48};
49
50/*
51 * IO request structure
52 */
53struct dm_io_client;
54struct dm_io_request {
55 int bi_rw; /* READ|WRITE - not READA */
56 struct dm_io_memory mem; /* Memory to use for io */
57 struct dm_io_notify notify; /* Synchronous if notify.fn is NULL */
58 struct dm_io_client *client; /* Client memory handler */
59};
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
61/*
Heinz Mauelshagenc8b03af2007-05-09 02:33:01 -070062 * For async io calls, users can alternatively use the dm_io() function below
63 * and dm_io_client_create() to create private mempools for the client.
64 *
65 * Create/destroy may block.
66 */
67struct dm_io_client *dm_io_client_create(unsigned num_pages);
68int dm_io_client_resize(unsigned num_pages, struct dm_io_client *client);
69void dm_io_client_destroy(struct dm_io_client *client);
70
71/*
Heinz Mauelshagenc8b03af2007-05-09 02:33:01 -070072 * IO interface using private per-client pools.
Milan Brozbf17ce32007-05-09 02:33:05 -070073 * Each bit in the optional 'sync_error_bits' bitset indicates whether an
74 * error occurred doing io to the corresponding region.
Heinz Mauelshagenc8b03af2007-05-09 02:33:01 -070075 */
76int dm_io(struct dm_io_request *io_req, unsigned num_regions,
77 struct io_region *region, unsigned long *sync_error_bits);
78
Linus Torvalds1da177e2005-04-16 15:20:36 -070079#endif