xref: /linux/Documentation/admin-guide/device-mapper/dm-io.rst (revision 6cf2a73cb2bc422a03984b285a63632c27f8c4e4)
1*f0ba4377SMauro Carvalho Chehab=====
21da177e4SLinus Torvaldsdm-io
31da177e4SLinus Torvalds=====
41da177e4SLinus Torvalds
51da177e4SLinus TorvaldsDm-io provides synchronous and asynchronous I/O services. There are three
61da177e4SLinus Torvaldstypes of I/O services available, and each type has a sync and an async
71da177e4SLinus Torvaldsversion.
81da177e4SLinus Torvalds
91da177e4SLinus TorvaldsThe user must set up an io_region structure to describe the desired location
101da177e4SLinus Torvaldsof the I/O. Each io_region indicates a block-device along with the starting
11*f0ba4377SMauro Carvalho Chehabsector and size of the region::
121da177e4SLinus Torvalds
131da177e4SLinus Torvalds   struct io_region {
141da177e4SLinus Torvalds      struct block_device *bdev;
151da177e4SLinus Torvalds      sector_t sector;
161da177e4SLinus Torvalds      sector_t count;
171da177e4SLinus Torvalds   };
181da177e4SLinus Torvalds
191da177e4SLinus TorvaldsDm-io can read from one io_region or write to one or more io_regions. Writes
201da177e4SLinus Torvaldsto multiple regions are specified by an array of io_region structures.
211da177e4SLinus Torvalds
221da177e4SLinus TorvaldsThe first I/O service type takes a list of memory pages as the data buffer for
23*f0ba4377SMauro Carvalho Chehabthe I/O, along with an offset into the first page::
241da177e4SLinus Torvalds
251da177e4SLinus Torvalds   struct page_list {
261da177e4SLinus Torvalds      struct page_list *next;
271da177e4SLinus Torvalds      struct page *page;
281da177e4SLinus Torvalds   };
291da177e4SLinus Torvalds
301da177e4SLinus Torvalds   int dm_io_sync(unsigned int num_regions, struct io_region *where, int rw,
311da177e4SLinus Torvalds                  struct page_list *pl, unsigned int offset,
321da177e4SLinus Torvalds                  unsigned long *error_bits);
331da177e4SLinus Torvalds   int dm_io_async(unsigned int num_regions, struct io_region *where, int rw,
341da177e4SLinus Torvalds                   struct page_list *pl, unsigned int offset,
351da177e4SLinus Torvalds                   io_notify_fn fn, void *context);
361da177e4SLinus Torvalds
371da177e4SLinus TorvaldsThe second I/O service type takes an array of bio vectors as the data buffer
381da177e4SLinus Torvaldsfor the I/O. This service can be handy if the caller has a pre-assembled bio,
39*f0ba4377SMauro Carvalho Chehabbut wants to direct different portions of the bio to different devices::
401da177e4SLinus Torvalds
411da177e4SLinus Torvalds   int dm_io_sync_bvec(unsigned int num_regions, struct io_region *where,
421da177e4SLinus Torvalds                       int rw, struct bio_vec *bvec,
431da177e4SLinus Torvalds                       unsigned long *error_bits);
441da177e4SLinus Torvalds   int dm_io_async_bvec(unsigned int num_regions, struct io_region *where,
451da177e4SLinus Torvalds                        int rw, struct bio_vec *bvec,
461da177e4SLinus Torvalds                        io_notify_fn fn, void *context);
471da177e4SLinus Torvalds
481da177e4SLinus TorvaldsThe third I/O service type takes a pointer to a vmalloc'd memory buffer as the
491da177e4SLinus Torvaldsdata buffer for the I/O. This service can be handy if the caller needs to do
501da177e4SLinus TorvaldsI/O to a large region but doesn't want to allocate a large number of individual
51*f0ba4377SMauro Carvalho Chehabmemory pages::
521da177e4SLinus Torvalds
531da177e4SLinus Torvalds   int dm_io_sync_vm(unsigned int num_regions, struct io_region *where, int rw,
541da177e4SLinus Torvalds                     void *data, unsigned long *error_bits);
551da177e4SLinus Torvalds   int dm_io_async_vm(unsigned int num_regions, struct io_region *where, int rw,
561da177e4SLinus Torvalds                      void *data, io_notify_fn fn, void *context);
571da177e4SLinus Torvalds
581da177e4SLinus TorvaldsCallers of the asynchronous I/O services must include the name of a completion
59*f0ba4377SMauro Carvalho Chehabcallback routine and a pointer to some context data for the I/O::
601da177e4SLinus Torvalds
611da177e4SLinus Torvalds   typedef void (*io_notify_fn)(unsigned long error, void *context);
621da177e4SLinus Torvalds
63*f0ba4377SMauro Carvalho ChehabThe "error" parameter in this callback, as well as the `*error` parameter in
641da177e4SLinus Torvaldsall of the synchronous versions, is a bitset (instead of a simple error value).
651da177e4SLinus TorvaldsIn the case of an write-I/O to multiple regions, this bitset allows dm-io to
661da177e4SLinus Torvaldsindicate success or failure on each individual region.
671da177e4SLinus Torvalds
681da177e4SLinus TorvaldsBefore using any of the dm-io services, the user should call dm_io_get()
691da177e4SLinus Torvaldsand specify the number of pages they expect to perform I/O on concurrently.
701da177e4SLinus TorvaldsDm-io will attempt to resize its mempool to make sure enough pages are
711da177e4SLinus Torvaldsalways available in order to avoid unnecessary waiting while performing I/O.
721da177e4SLinus Torvalds
731da177e4SLinus TorvaldsWhen the user is finished using the dm-io services, they should call
741da177e4SLinus Torvaldsdm_io_put() and specify the same number of pages that were given on the
751da177e4SLinus Torvaldsdm_io_get() call.
76