xref: /OK3568_Linux_fs/kernel/Documentation/admin-guide/device-mapper/dm-io.rst (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun=====
2*4882a593Smuzhiyundm-io
3*4882a593Smuzhiyun=====
4*4882a593Smuzhiyun
5*4882a593SmuzhiyunDm-io provides synchronous and asynchronous I/O services. There are three
6*4882a593Smuzhiyuntypes of I/O services available, and each type has a sync and an async
7*4882a593Smuzhiyunversion.
8*4882a593Smuzhiyun
9*4882a593SmuzhiyunThe user must set up an io_region structure to describe the desired location
10*4882a593Smuzhiyunof the I/O. Each io_region indicates a block-device along with the starting
11*4882a593Smuzhiyunsector and size of the region::
12*4882a593Smuzhiyun
13*4882a593Smuzhiyun   struct io_region {
14*4882a593Smuzhiyun      struct block_device *bdev;
15*4882a593Smuzhiyun      sector_t sector;
16*4882a593Smuzhiyun      sector_t count;
17*4882a593Smuzhiyun   };
18*4882a593Smuzhiyun
19*4882a593SmuzhiyunDm-io can read from one io_region or write to one or more io_regions. Writes
20*4882a593Smuzhiyunto multiple regions are specified by an array of io_region structures.
21*4882a593Smuzhiyun
22*4882a593SmuzhiyunThe first I/O service type takes a list of memory pages as the data buffer for
23*4882a593Smuzhiyunthe I/O, along with an offset into the first page::
24*4882a593Smuzhiyun
25*4882a593Smuzhiyun   struct page_list {
26*4882a593Smuzhiyun      struct page_list *next;
27*4882a593Smuzhiyun      struct page *page;
28*4882a593Smuzhiyun   };
29*4882a593Smuzhiyun
30*4882a593Smuzhiyun   int dm_io_sync(unsigned int num_regions, struct io_region *where, int rw,
31*4882a593Smuzhiyun                  struct page_list *pl, unsigned int offset,
32*4882a593Smuzhiyun                  unsigned long *error_bits);
33*4882a593Smuzhiyun   int dm_io_async(unsigned int num_regions, struct io_region *where, int rw,
34*4882a593Smuzhiyun                   struct page_list *pl, unsigned int offset,
35*4882a593Smuzhiyun                   io_notify_fn fn, void *context);
36*4882a593Smuzhiyun
37*4882a593SmuzhiyunThe second I/O service type takes an array of bio vectors as the data buffer
38*4882a593Smuzhiyunfor the I/O. This service can be handy if the caller has a pre-assembled bio,
39*4882a593Smuzhiyunbut wants to direct different portions of the bio to different devices::
40*4882a593Smuzhiyun
41*4882a593Smuzhiyun   int dm_io_sync_bvec(unsigned int num_regions, struct io_region *where,
42*4882a593Smuzhiyun                       int rw, struct bio_vec *bvec,
43*4882a593Smuzhiyun                       unsigned long *error_bits);
44*4882a593Smuzhiyun   int dm_io_async_bvec(unsigned int num_regions, struct io_region *where,
45*4882a593Smuzhiyun                        int rw, struct bio_vec *bvec,
46*4882a593Smuzhiyun                        io_notify_fn fn, void *context);
47*4882a593Smuzhiyun
48*4882a593SmuzhiyunThe third I/O service type takes a pointer to a vmalloc'd memory buffer as the
49*4882a593Smuzhiyundata buffer for the I/O. This service can be handy if the caller needs to do
50*4882a593SmuzhiyunI/O to a large region but doesn't want to allocate a large number of individual
51*4882a593Smuzhiyunmemory pages::
52*4882a593Smuzhiyun
53*4882a593Smuzhiyun   int dm_io_sync_vm(unsigned int num_regions, struct io_region *where, int rw,
54*4882a593Smuzhiyun                     void *data, unsigned long *error_bits);
55*4882a593Smuzhiyun   int dm_io_async_vm(unsigned int num_regions, struct io_region *where, int rw,
56*4882a593Smuzhiyun                      void *data, io_notify_fn fn, void *context);
57*4882a593Smuzhiyun
58*4882a593SmuzhiyunCallers of the asynchronous I/O services must include the name of a completion
59*4882a593Smuzhiyuncallback routine and a pointer to some context data for the I/O::
60*4882a593Smuzhiyun
61*4882a593Smuzhiyun   typedef void (*io_notify_fn)(unsigned long error, void *context);
62*4882a593Smuzhiyun
63*4882a593SmuzhiyunThe "error" parameter in this callback, as well as the `*error` parameter in
64*4882a593Smuzhiyunall of the synchronous versions, is a bitset (instead of a simple error value).
65*4882a593SmuzhiyunIn the case of an write-I/O to multiple regions, this bitset allows dm-io to
66*4882a593Smuzhiyunindicate success or failure on each individual region.
67*4882a593Smuzhiyun
68*4882a593SmuzhiyunBefore using any of the dm-io services, the user should call dm_io_get()
69*4882a593Smuzhiyunand specify the number of pages they expect to perform I/O on concurrently.
70*4882a593SmuzhiyunDm-io will attempt to resize its mempool to make sure enough pages are
71*4882a593Smuzhiyunalways available in order to avoid unnecessary waiting while performing I/O.
72*4882a593Smuzhiyun
73*4882a593SmuzhiyunWhen the user is finished using the dm-io services, they should call
74*4882a593Smuzhiyundm_io_put() and specify the same number of pages that were given on the
75*4882a593Smuzhiyundm_io_get() call.
76