blob: f4b0aa3126f5deae8ff8908375a9da1eca790ecf [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Copyright (C) 2003 Sistina Software
Heinz Mauelshagen22a1ceb2008-04-24 21:43:17 +01003 * Copyright (C) 2004 - 2008 Red Hat, Inc. All rights reserved.
4 *
5 * Device-Mapper low-level I/O.
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 *
7 * This file is released under the GPL.
8 */
9
Heinz Mauelshagen22a1ceb2008-04-24 21:43:17 +010010#ifndef _LINUX_DM_IO_H
11#define _LINUX_DM_IO_H
Linus Torvalds1da177e2005-04-16 15:20:36 -070012
Heinz Mauelshagen22a1ceb2008-04-24 21:43:17 +010013#ifdef __KERNEL__
Linus Torvalds1da177e2005-04-16 15:20:36 -070014
Heinz Mauelshagen22a1ceb2008-04-24 21:43:17 +010015#include <linux/types.h>
16
17struct dm_io_region {
Linus Torvalds1da177e2005-04-16 15:20:36 -070018 struct block_device *bdev;
19 sector_t sector;
Milan Brozbf17ce32007-05-09 02:33:05 -070020 sector_t count; /* If this is zero the region is ignored. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070021};
22
23struct page_list {
24 struct page_list *next;
25 struct page *page;
26};
27
Linus Torvalds1da177e2005-04-16 15:20:36 -070028typedef void (*io_notify_fn)(unsigned long error, void *context);
29
Heinz Mauelshagenc8b03af2007-05-09 02:33:01 -070030enum dm_io_mem_type {
31 DM_IO_PAGE_LIST,/* Page list */
32 DM_IO_BVEC, /* Bio vector */
33 DM_IO_VMA, /* Virtual memory area */
34 DM_IO_KMEM, /* Kernel memory */
35};
36
37struct dm_io_memory {
38 enum dm_io_mem_type type;
39
Mike Snitzer924e6002010-03-06 02:32:33 +000040 unsigned offset;
41
Heinz Mauelshagenc8b03af2007-05-09 02:33:01 -070042 union {
43 struct page_list *pl;
44 struct bio_vec *bvec;
45 void *vma;
46 void *addr;
47 } ptr;
Heinz Mauelshagenc8b03af2007-05-09 02:33:01 -070048};
49
50struct dm_io_notify {
51 io_notify_fn fn; /* Callback for asynchronous requests */
52 void *context; /* Passed to callback */
53};
54
55/*
56 * IO request structure
57 */
58struct dm_io_client;
59struct dm_io_request {
60 int bi_rw; /* READ|WRITE - not READA */
61 struct dm_io_memory mem; /* Memory to use for io */
62 struct dm_io_notify notify; /* Synchronous if notify.fn is NULL */
63 struct dm_io_client *client; /* Client memory handler */
64};
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
66/*
Heinz Mauelshagenc8b03af2007-05-09 02:33:01 -070067 * For async io calls, users can alternatively use the dm_io() function below
68 * and dm_io_client_create() to create private mempools for the client.
69 *
70 * Create/destroy may block.
71 */
Mikulas Patockabda8efe2011-05-29 13:03:09 +010072struct dm_io_client *dm_io_client_create(void);
Heinz Mauelshagenc8b03af2007-05-09 02:33:01 -070073void dm_io_client_destroy(struct dm_io_client *client);
74
75/*
Heinz Mauelshagenc8b03af2007-05-09 02:33:01 -070076 * IO interface using private per-client pools.
Milan Brozbf17ce32007-05-09 02:33:05 -070077 * Each bit in the optional 'sync_error_bits' bitset indicates whether an
78 * error occurred doing io to the corresponding region.
Heinz Mauelshagenc8b03af2007-05-09 02:33:01 -070079 */
80int dm_io(struct dm_io_request *io_req, unsigned num_regions,
Heinz Mauelshagen22a1ceb2008-04-24 21:43:17 +010081 struct dm_io_region *region, unsigned long *sync_error_bits);
Heinz Mauelshagenc8b03af2007-05-09 02:33:01 -070082
Heinz Mauelshagen22a1ceb2008-04-24 21:43:17 +010083#endif /* __KERNEL__ */
84#endif /* _LINUX_DM_IO_H */