dm-mpath.c 32 KB

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