18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Internal header file for device mapper
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Copyright (C) 2001, 2002 Sistina Software
58c2ecf20Sopenharmony_ci * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * This file is released under the LGPL.
88c2ecf20Sopenharmony_ci */
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#ifndef DM_INTERNAL_H
118c2ecf20Sopenharmony_ci#define DM_INTERNAL_H
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci#include <linux/fs.h>
148c2ecf20Sopenharmony_ci#include <linux/device-mapper.h>
158c2ecf20Sopenharmony_ci#include <linux/list.h>
168c2ecf20Sopenharmony_ci#include <linux/moduleparam.h>
178c2ecf20Sopenharmony_ci#include <linux/blkdev.h>
188c2ecf20Sopenharmony_ci#include <linux/backing-dev.h>
198c2ecf20Sopenharmony_ci#include <linux/hdreg.h>
208c2ecf20Sopenharmony_ci#include <linux/completion.h>
218c2ecf20Sopenharmony_ci#include <linux/kobject.h>
228c2ecf20Sopenharmony_ci#include <linux/refcount.h>
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci#include "dm-stats.h"
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci/*
278c2ecf20Sopenharmony_ci * Suspend feature flags
288c2ecf20Sopenharmony_ci */
298c2ecf20Sopenharmony_ci#define DM_SUSPEND_LOCKFS_FLAG		(1 << 0)
308c2ecf20Sopenharmony_ci#define DM_SUSPEND_NOFLUSH_FLAG		(1 << 1)
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci/*
338c2ecf20Sopenharmony_ci * Status feature flags
348c2ecf20Sopenharmony_ci */
358c2ecf20Sopenharmony_ci#define DM_STATUS_NOFLUSH_FLAG		(1 << 0)
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci/*
388c2ecf20Sopenharmony_ci * List of devices that a metadevice uses and should open/close.
398c2ecf20Sopenharmony_ci */
408c2ecf20Sopenharmony_cistruct dm_dev_internal {
418c2ecf20Sopenharmony_ci	struct list_head list;
428c2ecf20Sopenharmony_ci	refcount_t count;
438c2ecf20Sopenharmony_ci	struct dm_dev *dm_dev;
448c2ecf20Sopenharmony_ci};
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_cistruct dm_table;
478c2ecf20Sopenharmony_cistruct dm_md_mempools;
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci/*-----------------------------------------------------------------
508c2ecf20Sopenharmony_ci * Internal table functions.
518c2ecf20Sopenharmony_ci *---------------------------------------------------------------*/
528c2ecf20Sopenharmony_civoid dm_table_event_callback(struct dm_table *t,
538c2ecf20Sopenharmony_ci			     void (*fn)(void *), void *context);
548c2ecf20Sopenharmony_cistruct dm_target *dm_table_get_target(struct dm_table *t, unsigned int index);
558c2ecf20Sopenharmony_cistruct dm_target *dm_table_find_target(struct dm_table *t, sector_t sector);
568c2ecf20Sopenharmony_cibool dm_table_has_no_data_devices(struct dm_table *table);
578c2ecf20Sopenharmony_ciint dm_calculate_queue_limits(struct dm_table *table,
588c2ecf20Sopenharmony_ci			      struct queue_limits *limits);
598c2ecf20Sopenharmony_civoid dm_table_set_restrictions(struct dm_table *t, struct request_queue *q,
608c2ecf20Sopenharmony_ci			       struct queue_limits *limits);
618c2ecf20Sopenharmony_cistruct list_head *dm_table_get_devices(struct dm_table *t);
628c2ecf20Sopenharmony_civoid dm_table_presuspend_targets(struct dm_table *t);
638c2ecf20Sopenharmony_civoid dm_table_presuspend_undo_targets(struct dm_table *t);
648c2ecf20Sopenharmony_civoid dm_table_postsuspend_targets(struct dm_table *t);
658c2ecf20Sopenharmony_ciint dm_table_resume_targets(struct dm_table *t);
668c2ecf20Sopenharmony_cienum dm_queue_mode dm_table_get_type(struct dm_table *t);
678c2ecf20Sopenharmony_cistruct target_type *dm_table_get_immutable_target_type(struct dm_table *t);
688c2ecf20Sopenharmony_cistruct dm_target *dm_table_get_immutable_target(struct dm_table *t);
698c2ecf20Sopenharmony_cistruct dm_target *dm_table_get_wildcard_target(struct dm_table *t);
708c2ecf20Sopenharmony_cibool dm_table_bio_based(struct dm_table *t);
718c2ecf20Sopenharmony_cibool dm_table_request_based(struct dm_table *t);
728c2ecf20Sopenharmony_civoid dm_table_free_md_mempools(struct dm_table *t);
738c2ecf20Sopenharmony_cistruct dm_md_mempools *dm_table_get_md_mempools(struct dm_table *t);
748c2ecf20Sopenharmony_cibool dm_table_supports_dax(struct dm_table *t, iterate_devices_callout_fn fn,
758c2ecf20Sopenharmony_ci			   int *blocksize);
768c2ecf20Sopenharmony_ciint device_not_dax_capable(struct dm_target *ti, struct dm_dev *dev,
778c2ecf20Sopenharmony_ci			   sector_t start, sector_t len, void *data);
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_civoid dm_lock_md_type(struct mapped_device *md);
808c2ecf20Sopenharmony_civoid dm_unlock_md_type(struct mapped_device *md);
818c2ecf20Sopenharmony_civoid dm_set_md_type(struct mapped_device *md, enum dm_queue_mode type);
828c2ecf20Sopenharmony_cienum dm_queue_mode dm_get_md_type(struct mapped_device *md);
838c2ecf20Sopenharmony_cistruct target_type *dm_get_immutable_target_type(struct mapped_device *md);
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_ciint dm_setup_md_queue(struct mapped_device *md, struct dm_table *t);
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci/*
888c2ecf20Sopenharmony_ci * To check whether the target type is bio-based or not (request-based).
898c2ecf20Sopenharmony_ci */
908c2ecf20Sopenharmony_ci#define dm_target_bio_based(t) ((t)->type->map != NULL)
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ci/*
938c2ecf20Sopenharmony_ci * To check whether the target type is request-based or not (bio-based).
948c2ecf20Sopenharmony_ci */
958c2ecf20Sopenharmony_ci#define dm_target_request_based(t) ((t)->type->clone_and_map_rq != NULL)
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci/*
988c2ecf20Sopenharmony_ci * To check whether the target type is a hybrid (capable of being
998c2ecf20Sopenharmony_ci * either request-based or bio-based).
1008c2ecf20Sopenharmony_ci */
1018c2ecf20Sopenharmony_ci#define dm_target_hybrid(t) (dm_target_bio_based(t) && dm_target_request_based(t))
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_ci/*-----------------------------------------------------------------
1048c2ecf20Sopenharmony_ci * A registry of target types.
1058c2ecf20Sopenharmony_ci *---------------------------------------------------------------*/
1068c2ecf20Sopenharmony_ciint dm_target_init(void);
1078c2ecf20Sopenharmony_civoid dm_target_exit(void);
1088c2ecf20Sopenharmony_cistruct target_type *dm_get_target_type(const char *name);
1098c2ecf20Sopenharmony_civoid dm_put_target_type(struct target_type *tt);
1108c2ecf20Sopenharmony_ciint dm_target_iterate(void (*iter_func)(struct target_type *tt,
1118c2ecf20Sopenharmony_ci					void *param), void *param);
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_ciint dm_split_args(int *argc, char ***argvp, char *input);
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_ci/*
1168c2ecf20Sopenharmony_ci * Is this mapped_device being deleted?
1178c2ecf20Sopenharmony_ci */
1188c2ecf20Sopenharmony_ciint dm_deleting_md(struct mapped_device *md);
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_ci/*
1218c2ecf20Sopenharmony_ci * Is this mapped_device suspended?
1228c2ecf20Sopenharmony_ci */
1238c2ecf20Sopenharmony_ciint dm_suspended_md(struct mapped_device *md);
1248c2ecf20Sopenharmony_ci
1258c2ecf20Sopenharmony_ci/*
1268c2ecf20Sopenharmony_ci * Internal suspend and resume methods.
1278c2ecf20Sopenharmony_ci */
1288c2ecf20Sopenharmony_ciint dm_suspended_internally_md(struct mapped_device *md);
1298c2ecf20Sopenharmony_civoid dm_internal_suspend_fast(struct mapped_device *md);
1308c2ecf20Sopenharmony_civoid dm_internal_resume_fast(struct mapped_device *md);
1318c2ecf20Sopenharmony_civoid dm_internal_suspend_noflush(struct mapped_device *md);
1328c2ecf20Sopenharmony_civoid dm_internal_resume(struct mapped_device *md);
1338c2ecf20Sopenharmony_ci
1348c2ecf20Sopenharmony_ci/*
1358c2ecf20Sopenharmony_ci * Test if the device is scheduled for deferred remove.
1368c2ecf20Sopenharmony_ci */
1378c2ecf20Sopenharmony_ciint dm_test_deferred_remove_flag(struct mapped_device *md);
1388c2ecf20Sopenharmony_ci
1398c2ecf20Sopenharmony_ci/*
1408c2ecf20Sopenharmony_ci * Try to remove devices marked for deferred removal.
1418c2ecf20Sopenharmony_ci */
1428c2ecf20Sopenharmony_civoid dm_deferred_remove(void);
1438c2ecf20Sopenharmony_ci
1448c2ecf20Sopenharmony_ci/*
1458c2ecf20Sopenharmony_ci * The device-mapper can be driven through one of two interfaces;
1468c2ecf20Sopenharmony_ci * ioctl or filesystem, depending which patch you have applied.
1478c2ecf20Sopenharmony_ci */
1488c2ecf20Sopenharmony_ciint dm_interface_init(void);
1498c2ecf20Sopenharmony_civoid dm_interface_exit(void);
1508c2ecf20Sopenharmony_ci
1518c2ecf20Sopenharmony_ci/*
1528c2ecf20Sopenharmony_ci * sysfs interface
1538c2ecf20Sopenharmony_ci */
1548c2ecf20Sopenharmony_ciint dm_sysfs_init(struct mapped_device *md);
1558c2ecf20Sopenharmony_civoid dm_sysfs_exit(struct mapped_device *md);
1568c2ecf20Sopenharmony_cistruct kobject *dm_kobject(struct mapped_device *md);
1578c2ecf20Sopenharmony_cistruct mapped_device *dm_get_from_kobject(struct kobject *kobj);
1588c2ecf20Sopenharmony_ci
1598c2ecf20Sopenharmony_ci/*
1608c2ecf20Sopenharmony_ci * The kobject helper
1618c2ecf20Sopenharmony_ci */
1628c2ecf20Sopenharmony_civoid dm_kobject_release(struct kobject *kobj);
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_ci/*
1658c2ecf20Sopenharmony_ci * Targets for linear and striped mappings
1668c2ecf20Sopenharmony_ci */
1678c2ecf20Sopenharmony_ciint dm_linear_init(void);
1688c2ecf20Sopenharmony_civoid dm_linear_exit(void);
1698c2ecf20Sopenharmony_ci
1708c2ecf20Sopenharmony_ciint dm_stripe_init(void);
1718c2ecf20Sopenharmony_civoid dm_stripe_exit(void);
1728c2ecf20Sopenharmony_ci
1738c2ecf20Sopenharmony_ci/*
1748c2ecf20Sopenharmony_ci * mapped_device operations
1758c2ecf20Sopenharmony_ci */
1768c2ecf20Sopenharmony_civoid dm_destroy(struct mapped_device *md);
1778c2ecf20Sopenharmony_civoid dm_destroy_immediate(struct mapped_device *md);
1788c2ecf20Sopenharmony_ciint dm_open_count(struct mapped_device *md);
1798c2ecf20Sopenharmony_ciint dm_lock_for_deletion(struct mapped_device *md, bool mark_deferred, bool only_deferred);
1808c2ecf20Sopenharmony_ciint dm_cancel_deferred_remove(struct mapped_device *md);
1818c2ecf20Sopenharmony_ciint dm_request_based(struct mapped_device *md);
1828c2ecf20Sopenharmony_ciint dm_get_table_device(struct mapped_device *md, dev_t dev, fmode_t mode,
1838c2ecf20Sopenharmony_ci			struct dm_dev **result);
1848c2ecf20Sopenharmony_civoid dm_put_table_device(struct mapped_device *md, struct dm_dev *d);
1858c2ecf20Sopenharmony_ci
1868c2ecf20Sopenharmony_ciint dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
1878c2ecf20Sopenharmony_ci		      unsigned cookie);
1888c2ecf20Sopenharmony_ci
1898c2ecf20Sopenharmony_civoid dm_internal_suspend(struct mapped_device *md);
1908c2ecf20Sopenharmony_civoid dm_internal_resume(struct mapped_device *md);
1918c2ecf20Sopenharmony_ci
1928c2ecf20Sopenharmony_ciint dm_io_init(void);
1938c2ecf20Sopenharmony_civoid dm_io_exit(void);
1948c2ecf20Sopenharmony_ci
1958c2ecf20Sopenharmony_ciint dm_kcopyd_init(void);
1968c2ecf20Sopenharmony_civoid dm_kcopyd_exit(void);
1978c2ecf20Sopenharmony_ci
1988c2ecf20Sopenharmony_ci/*
1998c2ecf20Sopenharmony_ci * Mempool operations
2008c2ecf20Sopenharmony_ci */
2018c2ecf20Sopenharmony_cistruct dm_md_mempools *dm_alloc_md_mempools(struct mapped_device *md, enum dm_queue_mode type,
2028c2ecf20Sopenharmony_ci					    unsigned integrity, unsigned per_bio_data_size,
2038c2ecf20Sopenharmony_ci					    unsigned min_pool_size);
2048c2ecf20Sopenharmony_civoid dm_free_md_mempools(struct dm_md_mempools *pools);
2058c2ecf20Sopenharmony_ci
2068c2ecf20Sopenharmony_ci/*
2078c2ecf20Sopenharmony_ci * Various helpers
2088c2ecf20Sopenharmony_ci */
2098c2ecf20Sopenharmony_ciunsigned dm_get_reserved_bio_based_ios(void);
2108c2ecf20Sopenharmony_ci
2118c2ecf20Sopenharmony_ci#endif
212