13bd94003SHeinz Mauelshagen /* SPDX-License-Identifier: GPL-2.0-only */ 21da177e4SLinus Torvalds /* 31da177e4SLinus Torvalds * Copyright (C) 2003 Sistina Software. 41da177e4SLinus Torvalds * Copyright (C) 2004 Red Hat, Inc. All rights reserved. 51da177e4SLinus Torvalds * 61da177e4SLinus Torvalds * Module Author: Heinz Mauelshagen 71da177e4SLinus Torvalds * 81da177e4SLinus Torvalds * This file is released under the GPL. 91da177e4SLinus Torvalds * 101da177e4SLinus Torvalds * Path-Selector registration. 111da177e4SLinus Torvalds */ 121da177e4SLinus Torvalds 131da177e4SLinus Torvalds #ifndef DM_PATH_SELECTOR_H 141da177e4SLinus Torvalds #define DM_PATH_SELECTOR_H 151da177e4SLinus Torvalds 161da177e4SLinus Torvalds #include <linux/device-mapper.h> 171da177e4SLinus Torvalds 181da177e4SLinus Torvalds #include "dm-mpath.h" 191da177e4SLinus Torvalds 201da177e4SLinus Torvalds /* 211da177e4SLinus Torvalds * We provide an abstraction for the code that chooses which path 221da177e4SLinus Torvalds * to send some io down. 231da177e4SLinus Torvalds */ 241da177e4SLinus Torvalds struct path_selector_type; 251da177e4SLinus Torvalds struct path_selector { 261da177e4SLinus Torvalds struct path_selector_type *type; 271da177e4SLinus Torvalds void *context; 281da177e4SLinus Torvalds }; 291da177e4SLinus Torvalds 30c06dfd12SGabriel Krisman Bertazi /* 31c06dfd12SGabriel Krisman Bertazi * If a path selector uses this flag, a high resolution timer is used 32c06dfd12SGabriel Krisman Bertazi * (via ktime_get_ns) to account for IO start time in BIO-based mpath. 33c06dfd12SGabriel Krisman Bertazi * This improves performance of some path selectors (i.e. HST), in 34c06dfd12SGabriel Krisman Bertazi * exchange for slightly higher overhead when submitting the BIO. 35c06dfd12SGabriel Krisman Bertazi * The extra cost is usually offset by improved path selection for 36c06dfd12SGabriel Krisman Bertazi * some benchmarks. 37c06dfd12SGabriel Krisman Bertazi * 38c06dfd12SGabriel Krisman Bertazi * This has no effect for request-based mpath, since it already uses a 39c06dfd12SGabriel Krisman Bertazi * higher precision timer by default. 40c06dfd12SGabriel Krisman Bertazi */ 41c06dfd12SGabriel Krisman Bertazi #define DM_PS_USE_HR_TIMER 0x00000001 42c06dfd12SGabriel Krisman Bertazi #define dm_ps_use_hr_timer(type) ((type)->features & DM_PS_USE_HR_TIMER) 43c06dfd12SGabriel Krisman Bertazi 441da177e4SLinus Torvalds /* Information about a path selector type */ 451da177e4SLinus Torvalds struct path_selector_type { 461da177e4SLinus Torvalds char *name; 471da177e4SLinus Torvalds struct module *module; 481da177e4SLinus Torvalds 49c06dfd12SGabriel Krisman Bertazi unsigned int features; 501da177e4SLinus Torvalds unsigned int table_args; 511da177e4SLinus Torvalds unsigned int info_args; 521da177e4SLinus Torvalds 531da177e4SLinus Torvalds /* 541da177e4SLinus Torvalds * Constructs a path selector object, takes custom arguments 551da177e4SLinus Torvalds */ 5686a3238cSHeinz Mauelshagen int (*create)(struct path_selector *ps, unsigned int argc, char **argv); 571da177e4SLinus Torvalds void (*destroy)(struct path_selector *ps); 581da177e4SLinus Torvalds 591da177e4SLinus Torvalds /* 601da177e4SLinus Torvalds * Add an opaque path object, along with some selector specific 611da177e4SLinus Torvalds * path args (eg, path priority). 621da177e4SLinus Torvalds */ 63c922d5f7SJosef "Jeff" Sipek int (*add_path)(struct path_selector *ps, struct dm_path *path, 641da177e4SLinus Torvalds int argc, char **argv, char **error); 651da177e4SLinus Torvalds 661da177e4SLinus Torvalds /* 671da177e4SLinus Torvalds * Chooses a path for this io, if no paths are available then 681da177e4SLinus Torvalds * NULL will be returned. 691da177e4SLinus Torvalds */ 70*8ca817c4SHeinz Mauelshagen struct dm_path *(*select_path)(struct path_selector *ps, size_t nr_bytes); 711da177e4SLinus Torvalds 721da177e4SLinus Torvalds /* 731da177e4SLinus Torvalds * Notify the selector that a path has failed. 741da177e4SLinus Torvalds */ 75c922d5f7SJosef "Jeff" Sipek void (*fail_path)(struct path_selector *ps, struct dm_path *p); 761da177e4SLinus Torvalds 771da177e4SLinus Torvalds /* 781da177e4SLinus Torvalds * Ask selector to reinstate a path. 791da177e4SLinus Torvalds */ 80c922d5f7SJosef "Jeff" Sipek int (*reinstate_path)(struct path_selector *ps, struct dm_path *p); 811da177e4SLinus Torvalds 821da177e4SLinus Torvalds /* 831da177e4SLinus Torvalds * Table content based on parameters added in ps_add_path_fn 841da177e4SLinus Torvalds * or path selector status 851da177e4SLinus Torvalds */ 86c922d5f7SJosef "Jeff" Sipek int (*status)(struct path_selector *ps, struct dm_path *path, 871da177e4SLinus Torvalds status_type_t type, char *result, unsigned int maxlen); 881da177e4SLinus Torvalds 8902ab823fSKiyoshi Ueda int (*start_io)(struct path_selector *ps, struct dm_path *path, 9002ab823fSKiyoshi Ueda size_t nr_bytes); 9102ab823fSKiyoshi Ueda int (*end_io)(struct path_selector *ps, struct dm_path *path, 92087615bfSGabriel Krisman Bertazi size_t nr_bytes, u64 start_time); 931da177e4SLinus Torvalds }; 941da177e4SLinus Torvalds 951da177e4SLinus Torvalds /* Register a path selector */ 961da177e4SLinus Torvalds int dm_register_path_selector(struct path_selector_type *type); 971da177e4SLinus Torvalds 981da177e4SLinus Torvalds /* Unregister a path selector */ 991da177e4SLinus Torvalds int dm_unregister_path_selector(struct path_selector_type *type); 1001da177e4SLinus Torvalds 1011da177e4SLinus Torvalds /* Returns a registered path selector type */ 1021da177e4SLinus Torvalds struct path_selector_type *dm_get_path_selector(const char *name); 1031da177e4SLinus Torvalds 1041da177e4SLinus Torvalds /* Releases a path selector */ 1051da177e4SLinus Torvalds void dm_put_path_selector(struct path_selector_type *pst); 1061da177e4SLinus Torvalds 1071da177e4SLinus Torvalds #endif 108