dm-mpath.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485
  1. /*
  2. * Copyright (C) 2003 Sistina Software Limited.
  3. * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved.
  4. *
  5. * This file is released under the GPL.
  6. */
  7. #include "dm.h"
  8. #include "dm-path-selector.h"
  9. #include "dm-bio-list.h"
  10. #include "dm-bio-record.h"
  11. #include "dm-uevent.h"
  12. #include <linux/ctype.h>
  13. #include <linux/init.h>
  14. #include <linux/mempool.h>
  15. #include <linux/module.h>
  16. #include <linux/pagemap.h>
  17. #include <linux/slab.h>
  18. #include <linux/time.h>
  19. #include <linux/workqueue.h>
  20. #include <scsi/scsi_dh.h>
  21. #include <asm/atomic.h>
  22. #define DM_MSG_PREFIX "multipath"
  23. #define MESG_STR(x) x, sizeof(x)
  24. /* Path properties */
  25. struct pgpath {
  26. struct list_head list;
  27. struct priority_group *pg; /* Owning PG */
  28. unsigned fail_count; /* Cumulative failure count */
  29. struct dm_path path;
  30. };
  31. #define path_to_pgpath(__pgp) container_of((__pgp), struct pgpath, path)
  32. /*
  33. * Paths are grouped into Priority Groups and numbered from 1 upwards.
  34. * Each has a path selector which controls which path gets used.
  35. */
  36. struct priority_group {
  37. struct list_head list;
  38. struct multipath *m; /* Owning multipath instance */
  39. struct path_selector ps;
  40. unsigned pg_num; /* Reference number */
  41. unsigned bypassed; /* Temporarily bypass this PG? */
  42. unsigned nr_pgpaths; /* Number of paths in PG */
  43. struct list_head pgpaths;
  44. };
  45. /* Multipath context */
  46. struct multipath {
  47. struct list_head list;
  48. struct dm_target *ti;
  49. spinlock_t lock;
  50. const char *hw_handler_name;
  51. struct work_struct activate_path;
  52. unsigned nr_priority_groups;
  53. struct list_head priority_groups;
  54. unsigned pg_init_required; /* pg_init needs calling? */
  55. unsigned pg_init_in_progress; /* Only one pg_init allowed at once */
  56. unsigned nr_valid_paths; /* Total number of usable paths */
  57. struct pgpath *current_pgpath;
  58. struct priority_group *current_pg;
  59. struct priority_group *next_pg; /* Switch to this PG if set */
  60. unsigned repeat_count; /* I/Os left before calling PS again */
  61. unsigned queue_io; /* Must we queue all I/O? */
  62. unsigned queue_if_no_path; /* Queue I/O if last path fails? */
  63. unsigned saved_queue_if_no_path;/* Saved state during suspension */
  64. unsigned pg_init_retries; /* Number of times to retry pg_init */
  65. unsigned pg_init_count; /* Number of times pg_init called */
  66. struct work_struct process_queued_ios;
  67. struct bio_list queued_ios;
  68. unsigned queue_size;
  69. struct work_struct trigger_event;
  70. /*
  71. * We must use a mempool of dm_mpath_io structs so that we
  72. * can resubmit bios on error.
  73. */
  74. mempool_t *mpio_pool;
  75. };
  76. /*
  77. * Context information attached to each bio we process.
  78. */
  79. struct dm_mpath_io {
  80. struct pgpath *pgpath;
  81. struct dm_bio_details details;
  82. };
  83. typedef int (*action_fn) (struct pgpath *pgpath);
  84. #define MIN_IOS 256 /* Mempool size */
  85. static struct kmem_cache *_mpio_cache;
  86. static struct workqueue_struct *kmultipathd, *kmpath_handlerd;
  87. static void process_queued_ios(struct work_struct *work);
  88. static void trigger_event(struct work_struct *work);
  89. static void activate_path(struct work_struct *work);
  90. /*-----------------------------------------------
  91. * Allocation routines
  92. *-----------------------------------------------*/
  93. static struct pgpath *alloc_pgpath(void)
  94. {
  95. struct pgpath *pgpath = kzalloc(sizeof(*pgpath), GFP_KERNEL);
  96. if (pgpath)
  97. pgpath->path.is_active = 1;
  98. return pgpath;
  99. }
  100. static void free_pgpath(struct pgpath *pgpath)
  101. {
  102. kfree(pgpath);
  103. }
  104. static struct priority_group *alloc_priority_group(void)
  105. {
  106. struct priority_group *pg;
  107. pg = kzalloc(sizeof(*pg), GFP_KERNEL);
  108. if (pg)
  109. INIT_LIST_HEAD(&pg->pgpaths);
  110. return pg;
  111. }
  112. static void free_pgpaths(struct list_head *pgpaths, struct dm_target *ti)
  113. {
  114. struct pgpath *pgpath, *tmp;
  115. struct multipath *m = ti->private;
  116. list_for_each_entry_safe(pgpath, tmp, pgpaths, list) {
  117. list_del(&pgpath->list);
  118. if (m->hw_handler_name)
  119. scsi_dh_detach(bdev_get_queue(pgpath->path.dev->bdev));
  120. dm_put_device(ti, pgpath->path.dev);
  121. free_pgpath(pgpath);
  122. }
  123. }
  124. static void free_priority_group(struct priority_group *pg,
  125. struct dm_target *ti)
  126. {
  127. struct path_selector *ps = &pg->ps;
  128. if (ps->type) {
  129. ps->type->destroy(ps);
  130. dm_put_path_selector(ps->type);
  131. }
  132. free_pgpaths(&pg->pgpaths, ti);
  133. kfree(pg);
  134. }
  135. static struct multipath *alloc_multipath(struct dm_target *ti)
  136. {
  137. struct multipath *m;
  138. m = kzalloc(sizeof(*m), GFP_KERNEL);
  139. if (m) {
  140. INIT_LIST_HEAD(&m->priority_groups);
  141. spin_lock_init(&m->lock);
  142. m->queue_io = 1;
  143. INIT_WORK(&m->process_queued_ios, process_queued_ios);
  144. INIT_WORK(&m->trigger_event, trigger_event);
  145. INIT_WORK(&m->activate_path, activate_path);
  146. m->mpio_pool = mempool_create_slab_pool(MIN_IOS, _mpio_cache);
  147. if (!m->mpio_pool) {
  148. kfree(m);
  149. return NULL;
  150. }
  151. m->ti = ti;
  152. ti->private = m;
  153. }
  154. return m;
  155. }
  156. static void free_multipath(struct multipath *m)
  157. {
  158. struct priority_group *pg, *tmp;
  159. list_for_each_entry_safe(pg, tmp, &m->priority_groups, list) {
  160. list_del(&pg->list);
  161. free_priority_group(pg, m->ti);
  162. }
  163. kfree(m->hw_handler_name);
  164. mempool_destroy(m->mpio_pool);
  165. kfree(m);
  166. }
  167. /*-----------------------------------------------
  168. * Path selection
  169. *-----------------------------------------------*/
  170. static void __switch_pg(struct multipath *m, struct pgpath *pgpath)
  171. {
  172. m->current_pg = pgpath->pg;
  173. /* Must we initialise the PG first, and queue I/O till it's ready? */
  174. if (m->hw_handler_name) {
  175. m->pg_init_required = 1;
  176. m->queue_io = 1;
  177. } else {
  178. m->pg_init_required = 0;
  179. m->queue_io = 0;
  180. }
  181. m->pg_init_count = 0;
  182. }
  183. static int __choose_path_in_pg(struct multipath *m, struct priority_group *pg)
  184. {
  185. struct dm_path *path;
  186. path = pg->ps.type->select_path(&pg->ps, &m->repeat_count);
  187. if (!path)
  188. return -ENXIO;
  189. m->current_pgpath = path_to_pgpath(path);
  190. if (m->current_pg != pg)
  191. __switch_pg(m, m->current_pgpath);
  192. return 0;
  193. }
  194. static void __choose_pgpath(struct multipath *m)
  195. {
  196. struct priority_group *pg;
  197. unsigned bypassed = 1;
  198. if (!m->nr_valid_paths)
  199. goto failed;
  200. /* Were we instructed to switch PG? */
  201. if (m->next_pg) {
  202. pg = m->next_pg;
  203. m->next_pg = NULL;
  204. if (!__choose_path_in_pg(m, pg))
  205. return;
  206. }
  207. /* Don't change PG until it has no remaining paths */
  208. if (m->current_pg && !__choose_path_in_pg(m, m->current_pg))
  209. return;
  210. /*
  211. * Loop through priority groups until we find a valid path.
  212. * First time we skip PGs marked 'bypassed'.
  213. * Second time we only try the ones we skipped.
  214. */
  215. do {
  216. list_for_each_entry(pg, &m->priority_groups, list) {
  217. if (pg->bypassed == bypassed)
  218. continue;
  219. if (!__choose_path_in_pg(m, pg))
  220. return;
  221. }
  222. } while (bypassed--);
  223. failed:
  224. m->current_pgpath = NULL;
  225. m->current_pg = NULL;
  226. }
  227. /*
  228. * Check whether bios must be queued in the device-mapper core rather
  229. * than here in the target.
  230. *
  231. * m->lock must be held on entry.
  232. *
  233. * If m->queue_if_no_path and m->saved_queue_if_no_path hold the
  234. * same value then we are not between multipath_presuspend()
  235. * and multipath_resume() calls and we have no need to check
  236. * for the DMF_NOFLUSH_SUSPENDING flag.
  237. */
  238. static int __must_push_back(struct multipath *m)
  239. {
  240. return (m->queue_if_no_path != m->saved_queue_if_no_path &&
  241. dm_noflush_suspending(m->ti));
  242. }
  243. static int map_io(struct multipath *m, struct bio *bio,
  244. struct dm_mpath_io *mpio, unsigned was_queued)
  245. {
  246. int r = DM_MAPIO_REMAPPED;
  247. unsigned long flags;
  248. struct pgpath *pgpath;
  249. spin_lock_irqsave(&m->lock, flags);
  250. /* Do we need to select a new pgpath? */
  251. if (!m->current_pgpath ||
  252. (!m->queue_io && (m->repeat_count && --m->repeat_count == 0)))
  253. __choose_pgpath(m);
  254. pgpath = m->current_pgpath;
  255. if (was_queued)
  256. m->queue_size--;
  257. if ((pgpath && m->queue_io) ||
  258. (!pgpath && m->queue_if_no_path)) {
  259. /* Queue for the daemon to resubmit */
  260. bio_list_add(&m->queued_ios, bio);
  261. m->queue_size++;
  262. if ((m->pg_init_required && !m->pg_init_in_progress) ||
  263. !m->queue_io)
  264. queue_work(kmultipathd, &m->process_queued_ios);
  265. pgpath = NULL;
  266. r = DM_MAPIO_SUBMITTED;
  267. } else if (pgpath)
  268. bio->bi_bdev = pgpath->path.dev->bdev;
  269. else if (__must_push_back(m))
  270. r = DM_MAPIO_REQUEUE;
  271. else
  272. r = -EIO; /* Failed */
  273. mpio->pgpath = pgpath;
  274. spin_unlock_irqrestore(&m->lock, flags);
  275. return r;
  276. }
  277. /*
  278. * If we run out of usable paths, should we queue I/O or error it?
  279. */
  280. static int queue_if_no_path(struct multipath *m, unsigned queue_if_no_path,
  281. unsigned save_old_value)
  282. {
  283. unsigned long flags;
  284. spin_lock_irqsave(&m->lock, flags);
  285. if (save_old_value)
  286. m->saved_queue_if_no_path = m->queue_if_no_path;
  287. else
  288. m->saved_queue_if_no_path = queue_if_no_path;
  289. m->queue_if_no_path = queue_if_no_path;
  290. if (!m->queue_if_no_path && m->queue_size)
  291. queue_work(kmultipathd, &m->process_queued_ios);
  292. spin_unlock_irqrestore(&m->lock, flags);
  293. return 0;
  294. }
  295. /*-----------------------------------------------------------------
  296. * The multipath daemon is responsible for resubmitting queued ios.
  297. *---------------------------------------------------------------*/
  298. static void dispatch_queued_ios(struct multipath *m)
  299. {
  300. int r;
  301. unsigned long flags;
  302. struct bio *bio = NULL, *next;
  303. struct dm_mpath_io *mpio;
  304. union map_info *info;
  305. spin_lock_irqsave(&m->lock, flags);
  306. bio = bio_list_get(&m->queued_ios);
  307. spin_unlock_irqrestore(&m->lock, flags);
  308. while (bio) {
  309. next = bio->bi_next;
  310. bio->bi_next = NULL;
  311. info = dm_get_mapinfo(bio);
  312. mpio = info->ptr;
  313. r = map_io(m, bio, mpio, 1);
  314. if (r < 0)
  315. bio_endio(bio, r);
  316. else if (r == DM_MAPIO_REMAPPED)
  317. generic_make_request(bio);
  318. else if (r == DM_MAPIO_REQUEUE)
  319. bio_endio(bio, -EIO);
  320. bio = next;
  321. }
  322. }
  323. static void process_queued_ios(struct work_struct *work)
  324. {
  325. struct multipath *m =
  326. container_of(work, struct multipath, process_queued_ios);
  327. struct pgpath *pgpath = NULL;
  328. unsigned init_required = 0, must_queue = 1;
  329. unsigned long flags;
  330. spin_lock_irqsave(&m->lock, flags);
  331. if (!m->queue_size)
  332. goto out;
  333. if (!m->current_pgpath)
  334. __choose_pgpath(m);
  335. pgpath = m->current_pgpath;
  336. if ((pgpath && !m->queue_io) ||
  337. (!pgpath && !m->queue_if_no_path))
  338. must_queue = 0;
  339. if (m->pg_init_required && !m->pg_init_in_progress) {
  340. m->pg_init_count++;
  341. m->pg_init_required = 0;
  342. m->pg_init_in_progress = 1;
  343. init_required = 1;
  344. }
  345. out:
  346. spin_unlock_irqrestore(&m->lock, flags);
  347. if (init_required)
  348. queue_work(kmpath_handlerd, &m->activate_path);
  349. if (!must_queue)
  350. dispatch_queued_ios(m);
  351. }
  352. /*
  353. * An event is triggered whenever a path is taken out of use.
  354. * Includes path failure and PG bypass.
  355. */
  356. static void trigger_event(struct work_struct *work)
  357. {
  358. struct multipath *m =
  359. container_of(work, struct multipath, trigger_event);
  360. dm_table_event(m->ti->table);
  361. }
  362. /*-----------------------------------------------------------------
  363. * Constructor/argument parsing:
  364. * <#multipath feature args> [<arg>]*
  365. * <#hw_handler args> [hw_handler [<arg>]*]
  366. * <#priority groups>
  367. * <initial priority group>
  368. * [<selector> <#selector args> [<arg>]*
  369. * <#paths> <#per-path selector args>
  370. * [<path> [<arg>]* ]+ ]+
  371. *---------------------------------------------------------------*/
  372. struct param {
  373. unsigned min;
  374. unsigned max;
  375. char *error;
  376. };
  377. static int read_param(struct param *param, char *str, unsigned *v, char **error)
  378. {
  379. if (!str ||
  380. (sscanf(str, "%u", v) != 1) ||
  381. (*v < param->min) ||
  382. (*v > param->max)) {
  383. *error = param->error;
  384. return -EINVAL;
  385. }
  386. return 0;
  387. }
  388. struct arg_set {
  389. unsigned argc;
  390. char **argv;
  391. };
  392. static char *shift(struct arg_set *as)
  393. {
  394. char *r;
  395. if (as->argc) {
  396. as->argc--;
  397. r = *as->argv;
  398. as->argv++;
  399. return r;
  400. }
  401. return NULL;
  402. }
  403. static void consume(struct arg_set *as, unsigned n)
  404. {
  405. BUG_ON (as->argc < n);
  406. as->argc -= n;
  407. as->argv += n;
  408. }
  409. static int parse_path_selector(struct arg_set *as, struct priority_group *pg,
  410. struct dm_target *ti)
  411. {
  412. int r;
  413. struct path_selector_type *pst;
  414. unsigned ps_argc;
  415. static struct param _params[] = {
  416. {0, 1024, "invalid number of path selector args"},
  417. };
  418. pst = dm_get_path_selector(shift(as));
  419. if (!pst) {
  420. ti->error = "unknown path selector type";
  421. return -EINVAL;
  422. }
  423. r = read_param(_params, shift(as), &ps_argc, &ti->error);
  424. if (r) {
  425. dm_put_path_selector(pst);
  426. return -EINVAL;
  427. }
  428. r = pst->create(&pg->ps, ps_argc, as->argv);
  429. if (r) {
  430. dm_put_path_selector(pst);
  431. ti->error = "path selector constructor failed";
  432. return r;
  433. }
  434. pg->ps.type = pst;
  435. consume(as, ps_argc);
  436. return 0;
  437. }
  438. static struct pgpath *parse_path(struct arg_set *as, struct path_selector *ps,
  439. struct dm_target *ti)
  440. {
  441. int r;
  442. struct pgpath *p;
  443. struct multipath *m = ti->private;
  444. /* we need at least a path arg */
  445. if (as->argc < 1) {
  446. ti->error = "no device given";
  447. return NULL;
  448. }
  449. p = alloc_pgpath();
  450. if (!p)
  451. return NULL;
  452. r = dm_get_device(ti, shift(as), ti->begin, ti->len,
  453. dm_table_get_mode(ti->table), &p->path.dev);
  454. if (r) {
  455. ti->error = "error getting device";
  456. goto bad;
  457. }
  458. if (m->hw_handler_name) {
  459. r = scsi_dh_attach(bdev_get_queue(p->path.dev->bdev),
  460. m->hw_handler_name);
  461. if (r < 0) {
  462. dm_put_device(ti, p->path.dev);
  463. goto bad;
  464. }
  465. }
  466. r = ps->type->add_path(ps, &p->path, as->argc, as->argv, &ti->error);
  467. if (r) {
  468. dm_put_device(ti, p->path.dev);
  469. goto bad;
  470. }
  471. return p;
  472. bad:
  473. free_pgpath(p);
  474. return NULL;
  475. }
  476. static struct priority_group *parse_priority_group(struct arg_set *as,
  477. struct multipath *m)
  478. {
  479. static struct param _params[] = {
  480. {1, 1024, "invalid number of paths"},
  481. {0, 1024, "invalid number of selector args"}
  482. };
  483. int r;
  484. unsigned i, nr_selector_args, nr_params;
  485. struct priority_group *pg;
  486. struct dm_target *ti = m->ti;
  487. if (as->argc < 2) {
  488. as->argc = 0;
  489. ti->error = "not enough priority group aruments";
  490. return NULL;
  491. }
  492. pg = alloc_priority_group();
  493. if (!pg) {
  494. ti->error = "couldn't allocate priority group";
  495. return NULL;
  496. }
  497. pg->m = m;
  498. r = parse_path_selector(as, pg, ti);
  499. if (r)
  500. goto bad;
  501. /*
  502. * read the paths
  503. */
  504. r = read_param(_params, shift(as), &pg->nr_pgpaths, &ti->error);
  505. if (r)
  506. goto bad;
  507. r = read_param(_params + 1, shift(as), &nr_selector_args, &ti->error);
  508. if (r)
  509. goto bad;
  510. nr_params = 1 + nr_selector_args;
  511. for (i = 0; i < pg->nr_pgpaths; i++) {
  512. struct pgpath *pgpath;
  513. struct arg_set path_args;
  514. if (as->argc < nr_params) {
  515. ti->error = "not enough path parameters";
  516. goto bad;
  517. }
  518. path_args.argc = nr_params;
  519. path_args.argv = as->argv;
  520. pgpath = parse_path(&path_args, &pg->ps, ti);
  521. if (!pgpath)
  522. goto bad;
  523. pgpath->pg = pg;
  524. list_add_tail(&pgpath->list, &pg->pgpaths);
  525. consume(as, nr_params);
  526. }
  527. return pg;
  528. bad:
  529. free_priority_group(pg, ti);
  530. return NULL;
  531. }
  532. static int parse_hw_handler(struct arg_set *as, struct multipath *m)
  533. {
  534. unsigned hw_argc;
  535. struct dm_target *ti = m->ti;
  536. static struct param _params[] = {
  537. {0, 1024, "invalid number of hardware handler args"},
  538. };
  539. if (read_param(_params, shift(as), &hw_argc, &ti->error))
  540. return -EINVAL;
  541. if (!hw_argc)
  542. return 0;
  543. m->hw_handler_name = kstrdup(shift(as), GFP_KERNEL);
  544. request_module("scsi_dh_%s", m->hw_handler_name);
  545. if (scsi_dh_handler_exist(m->hw_handler_name) == 0) {
  546. ti->error = "unknown hardware handler type";
  547. kfree(m->hw_handler_name);
  548. m->hw_handler_name = NULL;
  549. return -EINVAL;
  550. }
  551. consume(as, hw_argc - 1);
  552. return 0;
  553. }
  554. static int parse_features(struct arg_set *as, struct multipath *m)
  555. {
  556. int r;
  557. unsigned argc;
  558. struct dm_target *ti = m->ti;
  559. const char *param_name;
  560. static struct param _params[] = {
  561. {0, 3, "invalid number of feature args"},
  562. {1, 50, "pg_init_retries must be between 1 and 50"},
  563. };
  564. r = read_param(_params, shift(as), &argc, &ti->error);
  565. if (r)
  566. return -EINVAL;
  567. if (!argc)
  568. return 0;
  569. do {
  570. param_name = shift(as);
  571. argc--;
  572. if (!strnicmp(param_name, MESG_STR("queue_if_no_path"))) {
  573. r = queue_if_no_path(m, 1, 0);
  574. continue;
  575. }
  576. if (!strnicmp(param_name, MESG_STR("pg_init_retries")) &&
  577. (argc >= 1)) {
  578. r = read_param(_params + 1, shift(as),
  579. &m->pg_init_retries, &ti->error);
  580. argc--;
  581. continue;
  582. }
  583. ti->error = "Unrecognised multipath feature request";
  584. r = -EINVAL;
  585. } while (argc && !r);
  586. return r;
  587. }
  588. static int multipath_ctr(struct dm_target *ti, unsigned int argc,
  589. char **argv)
  590. {
  591. /* target parameters */
  592. static struct param _params[] = {
  593. {1, 1024, "invalid number of priority groups"},
  594. {1, 1024, "invalid initial priority group number"},
  595. };
  596. int r;
  597. struct multipath *m;
  598. struct arg_set as;
  599. unsigned pg_count = 0;
  600. unsigned next_pg_num;
  601. as.argc = argc;
  602. as.argv = argv;
  603. m = alloc_multipath(ti);
  604. if (!m) {
  605. ti->error = "can't allocate multipath";
  606. return -EINVAL;
  607. }
  608. r = parse_features(&as, m);
  609. if (r)
  610. goto bad;
  611. r = parse_hw_handler(&as, m);
  612. if (r)
  613. goto bad;
  614. r = read_param(_params, shift(&as), &m->nr_priority_groups, &ti->error);
  615. if (r)
  616. goto bad;
  617. r = read_param(_params + 1, shift(&as), &next_pg_num, &ti->error);
  618. if (r)
  619. goto bad;
  620. /* parse the priority groups */
  621. while (as.argc) {
  622. struct priority_group *pg;
  623. pg = parse_priority_group(&as, m);
  624. if (!pg) {
  625. r = -EINVAL;
  626. goto bad;
  627. }
  628. m->nr_valid_paths += pg->nr_pgpaths;
  629. list_add_tail(&pg->list, &m->priority_groups);
  630. pg_count++;
  631. pg->pg_num = pg_count;
  632. if (!--next_pg_num)
  633. m->next_pg = pg;
  634. }
  635. if (pg_count != m->nr_priority_groups) {
  636. ti->error = "priority group count mismatch";
  637. r = -EINVAL;
  638. goto bad;
  639. }
  640. return 0;
  641. bad:
  642. free_multipath(m);
  643. return r;
  644. }
  645. static void multipath_dtr(struct dm_target *ti)
  646. {
  647. struct multipath *m = (struct multipath *) ti->private;
  648. flush_workqueue(kmpath_handlerd);
  649. flush_workqueue(kmultipathd);
  650. free_multipath(m);
  651. }
  652. /*
  653. * Map bios, recording original fields for later in case we have to resubmit
  654. */
  655. static int multipath_map(struct dm_target *ti, struct bio *bio,
  656. union map_info *map_context)
  657. {
  658. int r;
  659. struct dm_mpath_io *mpio;
  660. struct multipath *m = (struct multipath *) ti->private;
  661. mpio = mempool_alloc(m->mpio_pool, GFP_NOIO);
  662. dm_bio_record(&mpio->details, bio);
  663. map_context->ptr = mpio;
  664. bio->bi_rw |= (1 << BIO_RW_FAILFAST);
  665. r = map_io(m, bio, mpio, 0);
  666. if (r < 0 || r == DM_MAPIO_REQUEUE)
  667. mempool_free(mpio, m->mpio_pool);
  668. return r;
  669. }
  670. /*
  671. * Take a path out of use.
  672. */
  673. static int fail_path(struct pgpath *pgpath)
  674. {
  675. unsigned long flags;
  676. struct multipath *m = pgpath->pg->m;
  677. spin_lock_irqsave(&m->lock, flags);
  678. if (!pgpath->path.is_active)
  679. goto out;
  680. DMWARN("Failing path %s.", pgpath->path.dev->name);
  681. pgpath->pg->ps.type->fail_path(&pgpath->pg->ps, &pgpath->path);
  682. pgpath->path.is_active = 0;
  683. pgpath->fail_count++;
  684. m->nr_valid_paths--;
  685. if (pgpath == m->current_pgpath)
  686. m->current_pgpath = NULL;
  687. dm_path_uevent(DM_UEVENT_PATH_FAILED, m->ti,
  688. pgpath->path.dev->name, m->nr_valid_paths);
  689. queue_work(kmultipathd, &m->trigger_event);
  690. out:
  691. spin_unlock_irqrestore(&m->lock, flags);
  692. return 0;
  693. }
  694. /*
  695. * Reinstate a previously-failed path
  696. */
  697. static int reinstate_path(struct pgpath *pgpath)
  698. {
  699. int r = 0;
  700. unsigned long flags;
  701. struct multipath *m = pgpath->pg->m;
  702. spin_lock_irqsave(&m->lock, flags);
  703. if (pgpath->path.is_active)
  704. goto out;
  705. if (!pgpath->pg->ps.type->reinstate_path) {
  706. DMWARN("Reinstate path not supported by path selector %s",
  707. pgpath->pg->ps.type->name);
  708. r = -EINVAL;
  709. goto out;
  710. }
  711. r = pgpath->pg->ps.type->reinstate_path(&pgpath->pg->ps, &pgpath->path);
  712. if (r)
  713. goto out;
  714. pgpath->path.is_active = 1;
  715. m->current_pgpath = NULL;
  716. if (!m->nr_valid_paths++ && m->queue_size)
  717. queue_work(kmultipathd, &m->process_queued_ios);
  718. dm_path_uevent(DM_UEVENT_PATH_REINSTATED, m->ti,
  719. pgpath->path.dev->name, m->nr_valid_paths);
  720. queue_work(kmultipathd, &m->trigger_event);
  721. out:
  722. spin_unlock_irqrestore(&m->lock, flags);
  723. return r;
  724. }
  725. /*
  726. * Fail or reinstate all paths that match the provided struct dm_dev.
  727. */
  728. static int action_dev(struct multipath *m, struct dm_dev *dev,
  729. action_fn action)
  730. {
  731. int r = 0;
  732. struct pgpath *pgpath;
  733. struct priority_group *pg;
  734. list_for_each_entry(pg, &m->priority_groups, list) {
  735. list_for_each_entry(pgpath, &pg->pgpaths, list) {
  736. if (pgpath->path.dev == dev)
  737. r = action(pgpath);
  738. }
  739. }
  740. return r;
  741. }
  742. /*
  743. * Temporarily try to avoid having to use the specified PG
  744. */
  745. static void bypass_pg(struct multipath *m, struct priority_group *pg,
  746. int bypassed)
  747. {
  748. unsigned long flags;
  749. spin_lock_irqsave(&m->lock, flags);
  750. pg->bypassed = bypassed;
  751. m->current_pgpath = NULL;
  752. m->current_pg = NULL;
  753. spin_unlock_irqrestore(&m->lock, flags);
  754. queue_work(kmultipathd, &m->trigger_event);
  755. }
  756. /*
  757. * Switch to using the specified PG from the next I/O that gets mapped
  758. */
  759. static int switch_pg_num(struct multipath *m, const char *pgstr)
  760. {
  761. struct priority_group *pg;
  762. unsigned pgnum;
  763. unsigned long flags;
  764. if (!pgstr || (sscanf(pgstr, "%u", &pgnum) != 1) || !pgnum ||
  765. (pgnum > m->nr_priority_groups)) {
  766. DMWARN("invalid PG number supplied to switch_pg_num");
  767. return -EINVAL;
  768. }
  769. spin_lock_irqsave(&m->lock, flags);
  770. list_for_each_entry(pg, &m->priority_groups, list) {
  771. pg->bypassed = 0;
  772. if (--pgnum)
  773. continue;
  774. m->current_pgpath = NULL;
  775. m->current_pg = NULL;
  776. m->next_pg = pg;
  777. }
  778. spin_unlock_irqrestore(&m->lock, flags);
  779. queue_work(kmultipathd, &m->trigger_event);
  780. return 0;
  781. }
  782. /*
  783. * Set/clear bypassed status of a PG.
  784. * PGs are numbered upwards from 1 in the order they were declared.
  785. */
  786. static int bypass_pg_num(struct multipath *m, const char *pgstr, int bypassed)
  787. {
  788. struct priority_group *pg;
  789. unsigned pgnum;
  790. if (!pgstr || (sscanf(pgstr, "%u", &pgnum) != 1) || !pgnum ||
  791. (pgnum > m->nr_priority_groups)) {
  792. DMWARN("invalid PG number supplied to bypass_pg");
  793. return -EINVAL;
  794. }
  795. list_for_each_entry(pg, &m->priority_groups, list) {
  796. if (!--pgnum)
  797. break;
  798. }
  799. bypass_pg(m, pg, bypassed);
  800. return 0;
  801. }
  802. /*
  803. * Should we retry pg_init immediately?
  804. */
  805. static int pg_init_limit_reached(struct multipath *m, struct pgpath *pgpath)
  806. {
  807. unsigned long flags;
  808. int limit_reached = 0;
  809. spin_lock_irqsave(&m->lock, flags);
  810. if (m->pg_init_count <= m->pg_init_retries)
  811. m->pg_init_required = 1;
  812. else
  813. limit_reached = 1;
  814. spin_unlock_irqrestore(&m->lock, flags);
  815. return limit_reached;
  816. }
  817. static void pg_init_done(struct dm_path *path, int errors)
  818. {
  819. struct pgpath *pgpath = path_to_pgpath(path);
  820. struct priority_group *pg = pgpath->pg;
  821. struct multipath *m = pg->m;
  822. unsigned long flags;
  823. /* device or driver problems */
  824. switch (errors) {
  825. case SCSI_DH_OK:
  826. break;
  827. case SCSI_DH_NOSYS:
  828. if (!m->hw_handler_name) {
  829. errors = 0;
  830. break;
  831. }
  832. DMERR("Cannot failover device because scsi_dh_%s was not "
  833. "loaded.", m->hw_handler_name);
  834. /*
  835. * Fail path for now, so we do not ping pong
  836. */
  837. fail_path(pgpath);
  838. break;
  839. case SCSI_DH_DEV_TEMP_BUSY:
  840. /*
  841. * Probably doing something like FW upgrade on the
  842. * controller so try the other pg.
  843. */
  844. bypass_pg(m, pg, 1);
  845. break;
  846. /* TODO: For SCSI_DH_RETRY we should wait a couple seconds */
  847. case SCSI_DH_RETRY:
  848. case SCSI_DH_IMM_RETRY:
  849. case SCSI_DH_RES_TEMP_UNAVAIL:
  850. if (pg_init_limit_reached(m, pgpath))
  851. fail_path(pgpath);
  852. errors = 0;
  853. break;
  854. default:
  855. /*
  856. * We probably do not want to fail the path for a device
  857. * error, but this is what the old dm did. In future
  858. * patches we can do more advanced handling.
  859. */
  860. fail_path(pgpath);
  861. }
  862. spin_lock_irqsave(&m->lock, flags);
  863. if (errors) {
  864. DMERR("Could not failover device. Error %d.", errors);
  865. m->current_pgpath = NULL;
  866. m->current_pg = NULL;
  867. } else if (!m->pg_init_required) {
  868. m->queue_io = 0;
  869. pg->bypassed = 0;
  870. }
  871. m->pg_init_in_progress = 0;
  872. queue_work(kmultipathd, &m->process_queued_ios);
  873. spin_unlock_irqrestore(&m->lock, flags);
  874. }
  875. static void activate_path(struct work_struct *work)
  876. {
  877. int ret;
  878. struct multipath *m =
  879. container_of(work, struct multipath, activate_path);
  880. struct dm_path *path = &m->current_pgpath->path;
  881. ret = scsi_dh_activate(bdev_get_queue(path->dev->bdev));
  882. pg_init_done(path, ret);
  883. }
  884. /*
  885. * end_io handling
  886. */
  887. static int do_end_io(struct multipath *m, struct bio *bio,
  888. int error, struct dm_mpath_io *mpio)
  889. {
  890. unsigned long flags;
  891. if (!error)
  892. return 0; /* I/O complete */
  893. if ((error == -EWOULDBLOCK) && bio_rw_ahead(bio))
  894. return error;
  895. if (error == -EOPNOTSUPP)
  896. return error;
  897. spin_lock_irqsave(&m->lock, flags);
  898. if (!m->nr_valid_paths) {
  899. if (__must_push_back(m)) {
  900. spin_unlock_irqrestore(&m->lock, flags);
  901. return DM_ENDIO_REQUEUE;
  902. } else if (!m->queue_if_no_path) {
  903. spin_unlock_irqrestore(&m->lock, flags);
  904. return -EIO;
  905. } else {
  906. spin_unlock_irqrestore(&m->lock, flags);
  907. goto requeue;
  908. }
  909. }
  910. spin_unlock_irqrestore(&m->lock, flags);
  911. if (mpio->pgpath)
  912. fail_path(mpio->pgpath);
  913. requeue:
  914. dm_bio_restore(&mpio->details, bio);
  915. /* queue for the daemon to resubmit or fail */
  916. spin_lock_irqsave(&m->lock, flags);
  917. bio_list_add(&m->queued_ios, bio);
  918. m->queue_size++;
  919. if (!m->queue_io)
  920. queue_work(kmultipathd, &m->process_queued_ios);
  921. spin_unlock_irqrestore(&m->lock, flags);
  922. return DM_ENDIO_INCOMPLETE; /* io not complete */
  923. }
  924. static int multipath_end_io(struct dm_target *ti, struct bio *bio,
  925. int error, union map_info *map_context)
  926. {
  927. struct multipath *m = ti->private;
  928. struct dm_mpath_io *mpio = map_context->ptr;
  929. struct pgpath *pgpath = mpio->pgpath;
  930. struct path_selector *ps;
  931. int r;
  932. r = do_end_io(m, bio, error, mpio);
  933. if (pgpath) {
  934. ps = &pgpath->pg->ps;
  935. if (ps->type->end_io)
  936. ps->type->end_io(ps, &pgpath->path);
  937. }
  938. if (r != DM_ENDIO_INCOMPLETE)
  939. mempool_free(mpio, m->mpio_pool);
  940. return r;
  941. }
  942. /*
  943. * Suspend can't complete until all the I/O is processed so if
  944. * the last path fails we must error any remaining I/O.
  945. * Note that if the freeze_bdev fails while suspending, the
  946. * queue_if_no_path state is lost - userspace should reset it.
  947. */
  948. static void multipath_presuspend(struct dm_target *ti)
  949. {
  950. struct multipath *m = (struct multipath *) ti->private;
  951. queue_if_no_path(m, 0, 1);
  952. }
  953. /*
  954. * Restore the queue_if_no_path setting.
  955. */
  956. static void multipath_resume(struct dm_target *ti)
  957. {
  958. struct multipath *m = (struct multipath *) ti->private;
  959. unsigned long flags;
  960. spin_lock_irqsave(&m->lock, flags);
  961. m->queue_if_no_path = m->saved_queue_if_no_path;
  962. spin_unlock_irqrestore(&m->lock, flags);
  963. }
  964. /*
  965. * Info output has the following format:
  966. * num_multipath_feature_args [multipath_feature_args]*
  967. * num_handler_status_args [handler_status_args]*
  968. * num_groups init_group_number
  969. * [A|D|E num_ps_status_args [ps_status_args]*
  970. * num_paths num_selector_args
  971. * [path_dev A|F fail_count [selector_args]* ]+ ]+
  972. *
  973. * Table output has the following format (identical to the constructor string):
  974. * num_feature_args [features_args]*
  975. * num_handler_args hw_handler [hw_handler_args]*
  976. * num_groups init_group_number
  977. * [priority selector-name num_ps_args [ps_args]*
  978. * num_paths num_selector_args [path_dev [selector_args]* ]+ ]+
  979. */
  980. static int multipath_status(struct dm_target *ti, status_type_t type,
  981. char *result, unsigned int maxlen)
  982. {
  983. int sz = 0;
  984. unsigned long flags;
  985. struct multipath *m = (struct multipath *) ti->private;
  986. struct priority_group *pg;
  987. struct pgpath *p;
  988. unsigned pg_num;
  989. char state;
  990. spin_lock_irqsave(&m->lock, flags);
  991. /* Features */
  992. if (type == STATUSTYPE_INFO)
  993. DMEMIT("2 %u %u ", m->queue_size, m->pg_init_count);
  994. else {
  995. DMEMIT("%u ", m->queue_if_no_path +
  996. (m->pg_init_retries > 0) * 2);
  997. if (m->queue_if_no_path)
  998. DMEMIT("queue_if_no_path ");
  999. if (m->pg_init_retries)
  1000. DMEMIT("pg_init_retries %u ", m->pg_init_retries);
  1001. }
  1002. if (!m->hw_handler_name || type == STATUSTYPE_INFO)
  1003. DMEMIT("0 ");
  1004. else
  1005. DMEMIT("1 %s ", m->hw_handler_name);
  1006. DMEMIT("%u ", m->nr_priority_groups);
  1007. if (m->next_pg)
  1008. pg_num = m->next_pg->pg_num;
  1009. else if (m->current_pg)
  1010. pg_num = m->current_pg->pg_num;
  1011. else
  1012. pg_num = 1;
  1013. DMEMIT("%u ", pg_num);
  1014. switch (type) {
  1015. case STATUSTYPE_INFO:
  1016. list_for_each_entry(pg, &m->priority_groups, list) {
  1017. if (pg->bypassed)
  1018. state = 'D'; /* Disabled */
  1019. else if (pg == m->current_pg)
  1020. state = 'A'; /* Currently Active */
  1021. else
  1022. state = 'E'; /* Enabled */
  1023. DMEMIT("%c ", state);
  1024. if (pg->ps.type->status)
  1025. sz += pg->ps.type->status(&pg->ps, NULL, type,
  1026. result + sz,
  1027. maxlen - sz);
  1028. else
  1029. DMEMIT("0 ");
  1030. DMEMIT("%u %u ", pg->nr_pgpaths,
  1031. pg->ps.type->info_args);
  1032. list_for_each_entry(p, &pg->pgpaths, list) {
  1033. DMEMIT("%s %s %u ", p->path.dev->name,
  1034. p->path.is_active ? "A" : "F",
  1035. p->fail_count);
  1036. if (pg->ps.type->status)
  1037. sz += pg->ps.type->status(&pg->ps,
  1038. &p->path, type, result + sz,
  1039. maxlen - sz);
  1040. }
  1041. }
  1042. break;
  1043. case STATUSTYPE_TABLE:
  1044. list_for_each_entry(pg, &m->priority_groups, list) {
  1045. DMEMIT("%s ", pg->ps.type->name);
  1046. if (pg->ps.type->status)
  1047. sz += pg->ps.type->status(&pg->ps, NULL, type,
  1048. result + sz,
  1049. maxlen - sz);
  1050. else
  1051. DMEMIT("0 ");
  1052. DMEMIT("%u %u ", pg->nr_pgpaths,
  1053. pg->ps.type->table_args);
  1054. list_for_each_entry(p, &pg->pgpaths, list) {
  1055. DMEMIT("%s ", p->path.dev->name);
  1056. if (pg->ps.type->status)
  1057. sz += pg->ps.type->status(&pg->ps,
  1058. &p->path, type, result + sz,
  1059. maxlen - sz);
  1060. }
  1061. }
  1062. break;
  1063. }
  1064. spin_unlock_irqrestore(&m->lock, flags);
  1065. return 0;
  1066. }
  1067. static int multipath_message(struct dm_target *ti, unsigned argc, char **argv)
  1068. {
  1069. int r;
  1070. struct dm_dev *dev;
  1071. struct multipath *m = (struct multipath *) ti->private;
  1072. action_fn action;
  1073. if (argc == 1) {
  1074. if (!strnicmp(argv[0], MESG_STR("queue_if_no_path")))
  1075. return queue_if_no_path(m, 1, 0);
  1076. else if (!strnicmp(argv[0], MESG_STR("fail_if_no_path")))
  1077. return queue_if_no_path(m, 0, 0);
  1078. }
  1079. if (argc != 2)
  1080. goto error;
  1081. if (!strnicmp(argv[0], MESG_STR("disable_group")))
  1082. return bypass_pg_num(m, argv[1], 1);
  1083. else if (!strnicmp(argv[0], MESG_STR("enable_group")))
  1084. return bypass_pg_num(m, argv[1], 0);
  1085. else if (!strnicmp(argv[0], MESG_STR("switch_group")))
  1086. return switch_pg_num(m, argv[1]);
  1087. else if (!strnicmp(argv[0], MESG_STR("reinstate_path")))
  1088. action = reinstate_path;
  1089. else if (!strnicmp(argv[0], MESG_STR("fail_path")))
  1090. action = fail_path;
  1091. else
  1092. goto error;
  1093. r = dm_get_device(ti, argv[1], ti->begin, ti->len,
  1094. dm_table_get_mode(ti->table), &dev);
  1095. if (r) {
  1096. DMWARN("message: error getting device %s",
  1097. argv[1]);
  1098. return -EINVAL;
  1099. }
  1100. r = action_dev(m, dev, action);
  1101. dm_put_device(ti, dev);
  1102. return r;
  1103. error:
  1104. DMWARN("Unrecognised multipath message received.");
  1105. return -EINVAL;
  1106. }
  1107. static int multipath_ioctl(struct dm_target *ti, struct inode *inode,
  1108. struct file *filp, unsigned int cmd,
  1109. unsigned long arg)
  1110. {
  1111. struct multipath *m = (struct multipath *) ti->private;
  1112. struct block_device *bdev = NULL;
  1113. unsigned long flags;
  1114. struct file fake_file = {};
  1115. struct dentry fake_dentry = {};
  1116. int r = 0;
  1117. fake_file.f_path.dentry = &fake_dentry;
  1118. spin_lock_irqsave(&m->lock, flags);
  1119. if (!m->current_pgpath)
  1120. __choose_pgpath(m);
  1121. if (m->current_pgpath) {
  1122. bdev = m->current_pgpath->path.dev->bdev;
  1123. fake_dentry.d_inode = bdev->bd_inode;
  1124. fake_file.f_mode = m->current_pgpath->path.dev->mode;
  1125. }
  1126. if (m->queue_io)
  1127. r = -EAGAIN;
  1128. else if (!bdev)
  1129. r = -EIO;
  1130. spin_unlock_irqrestore(&m->lock, flags);
  1131. return r ? : blkdev_driver_ioctl(bdev->bd_inode, &fake_file,
  1132. bdev->bd_disk, cmd, arg);
  1133. }
  1134. /*-----------------------------------------------------------------
  1135. * Module setup
  1136. *---------------------------------------------------------------*/
  1137. static struct target_type multipath_target = {
  1138. .name = "multipath",
  1139. .version = {1, 0, 5},
  1140. .module = THIS_MODULE,
  1141. .ctr = multipath_ctr,
  1142. .dtr = multipath_dtr,
  1143. .map = multipath_map,
  1144. .end_io = multipath_end_io,
  1145. .presuspend = multipath_presuspend,
  1146. .resume = multipath_resume,
  1147. .status = multipath_status,
  1148. .message = multipath_message,
  1149. .ioctl = multipath_ioctl,
  1150. };
  1151. static int __init dm_multipath_init(void)
  1152. {
  1153. int r;
  1154. /* allocate a slab for the dm_ios */
  1155. _mpio_cache = KMEM_CACHE(dm_mpath_io, 0);
  1156. if (!_mpio_cache)
  1157. return -ENOMEM;
  1158. r = dm_register_target(&multipath_target);
  1159. if (r < 0) {
  1160. DMERR("register failed %d", r);
  1161. kmem_cache_destroy(_mpio_cache);
  1162. return -EINVAL;
  1163. }
  1164. kmultipathd = create_workqueue("kmpathd");
  1165. if (!kmultipathd) {
  1166. DMERR("failed to create workqueue kmpathd");
  1167. dm_unregister_target(&multipath_target);
  1168. kmem_cache_destroy(_mpio_cache);
  1169. return -ENOMEM;
  1170. }
  1171. /*
  1172. * A separate workqueue is used to handle the device handlers
  1173. * to avoid overloading existing workqueue. Overloading the
  1174. * old workqueue would also create a bottleneck in the
  1175. * path of the storage hardware device activation.
  1176. */
  1177. kmpath_handlerd = create_singlethread_workqueue("kmpath_handlerd");
  1178. if (!kmpath_handlerd) {
  1179. DMERR("failed to create workqueue kmpath_handlerd");
  1180. destroy_workqueue(kmultipathd);
  1181. dm_unregister_target(&multipath_target);
  1182. kmem_cache_destroy(_mpio_cache);
  1183. return -ENOMEM;
  1184. }
  1185. DMINFO("version %u.%u.%u loaded",
  1186. multipath_target.version[0], multipath_target.version[1],
  1187. multipath_target.version[2]);
  1188. return r;
  1189. }
  1190. static void __exit dm_multipath_exit(void)
  1191. {
  1192. int r;
  1193. destroy_workqueue(kmpath_handlerd);
  1194. destroy_workqueue(kmultipathd);
  1195. r = dm_unregister_target(&multipath_target);
  1196. if (r < 0)
  1197. DMERR("target unregister failed %d", r);
  1198. kmem_cache_destroy(_mpio_cache);
  1199. }
  1200. module_init(dm_multipath_init);
  1201. module_exit(dm_multipath_exit);
  1202. MODULE_DESCRIPTION(DM_NAME " multipath target");
  1203. MODULE_AUTHOR("Sistina Software <dm-devel@redhat.com>");
  1204. MODULE_LICENSE("GPL");