11da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
21da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Copyright (C) 2003 Sistina Software.
31da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Copyright (C) 2004 Red Hat, Inc. All rights reserved.
41da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
51da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Module Author: Heinz Mauelshagen
61da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
71da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * This file is released under the GPL.
81da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
91da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Path-Selector registration.
101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifndef	DM_PATH_SELECTOR_H
131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define	DM_PATH_SELECTOR_H
141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/device-mapper.h>
161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include "dm-mpath.h"
181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * We provide an abstraction for the code that chooses which path
211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * to send some io down.
221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstruct path_selector_type;
241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstruct path_selector {
251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	struct path_selector_type *type;
261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	void *context;
271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds};
281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Information about a path selector type */
301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstruct path_selector_type {
311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	char *name;
321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	struct module *module;
331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	unsigned int table_args;
351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	unsigned int info_args;
361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/*
381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 * Constructs a path selector object, takes custom arguments
391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 */
401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	int (*create) (struct path_selector *ps, unsigned argc, char **argv);
411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	void (*destroy) (struct path_selector *ps);
421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/*
441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 * Add an opaque path object, along with some selector specific
451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 * path args (eg, path priority).
461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 */
47c922d5f7f5457da9e9b5a26dd53e2dcef6ca2f7dJosef "Jeff" Sipek	int (*add_path) (struct path_selector *ps, struct dm_path *path,
481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			 int argc, char **argv, char **error);
491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/*
511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 * Chooses a path for this io, if no paths are available then
521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 * NULL will be returned.
531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 *
541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 * repeat_count is the number of times to use the path before
551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 * calling the function again.  0 means don't call it again unless
561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 * the path fails.
571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 */
58c922d5f7f5457da9e9b5a26dd53e2dcef6ca2f7dJosef "Jeff" Sipek	struct dm_path *(*select_path) (struct path_selector *ps,
5902ab823fd1a27d193bda06b74fdad685a20a3e5eKiyoshi Ueda					unsigned *repeat_count,
6002ab823fd1a27d193bda06b74fdad685a20a3e5eKiyoshi Ueda					size_t nr_bytes);
611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/*
631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 * Notify the selector that a path has failed.
641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 */
65c922d5f7f5457da9e9b5a26dd53e2dcef6ca2f7dJosef "Jeff" Sipek	void (*fail_path) (struct path_selector *ps, struct dm_path *p);
661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/*
681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 * Ask selector to reinstate a path.
691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 */
70c922d5f7f5457da9e9b5a26dd53e2dcef6ca2f7dJosef "Jeff" Sipek	int (*reinstate_path) (struct path_selector *ps, struct dm_path *p);
711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/*
731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 * Table content based on parameters added in ps_add_path_fn
741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 * or path selector status
751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 */
76c922d5f7f5457da9e9b5a26dd53e2dcef6ca2f7dJosef "Jeff" Sipek	int (*status) (struct path_selector *ps, struct dm_path *path,
771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		       status_type_t type, char *result, unsigned int maxlen);
781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
7902ab823fd1a27d193bda06b74fdad685a20a3e5eKiyoshi Ueda	int (*start_io) (struct path_selector *ps, struct dm_path *path,
8002ab823fd1a27d193bda06b74fdad685a20a3e5eKiyoshi Ueda			 size_t nr_bytes);
8102ab823fd1a27d193bda06b74fdad685a20a3e5eKiyoshi Ueda	int (*end_io) (struct path_selector *ps, struct dm_path *path,
8202ab823fd1a27d193bda06b74fdad685a20a3e5eKiyoshi Ueda		       size_t nr_bytes);
831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds};
841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Register a path selector */
861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsint dm_register_path_selector(struct path_selector_type *type);
871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Unregister a path selector */
891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsint dm_unregister_path_selector(struct path_selector_type *type);
901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Returns a registered path selector type */
921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstruct path_selector_type *dm_get_path_selector(const char *name);
931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Releases a path selector  */
951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsvoid dm_put_path_selector(struct path_selector_type *pst);
961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif
98