Lines Matching refs:m
52 struct multipath *m; /* Owning multipath instance */ member
162 struct multipath *m = ti->private; in free_pgpaths() local
166 if (m->hw_handler_name) in free_pgpaths()
189 struct multipath *m; in alloc_multipath() local
192 m = kzalloc(sizeof(*m), GFP_KERNEL); in alloc_multipath()
193 if (m) { in alloc_multipath()
194 INIT_LIST_HEAD(&m->priority_groups); in alloc_multipath()
195 spin_lock_init(&m->lock); in alloc_multipath()
196 m->queue_io = 1; in alloc_multipath()
197 m->pg_init_delay_msecs = DM_PG_INIT_DELAY_DEFAULT; in alloc_multipath()
198 INIT_WORK(&m->trigger_event, trigger_event); in alloc_multipath()
199 init_waitqueue_head(&m->pg_init_wait); in alloc_multipath()
200 mutex_init(&m->work_mutex); in alloc_multipath()
201 m->mpio_pool = mempool_create_slab_pool(min_ios, _mpio_cache); in alloc_multipath()
202 if (!m->mpio_pool) { in alloc_multipath()
203 kfree(m); in alloc_multipath()
206 m->ti = ti; in alloc_multipath()
207 ti->private = m; in alloc_multipath()
210 return m; in alloc_multipath()
213 static void free_multipath(struct multipath *m) in free_multipath() argument
217 list_for_each_entry_safe(pg, tmp, &m->priority_groups, list) { in free_multipath()
219 free_priority_group(pg, m->ti); in free_multipath()
222 kfree(m->hw_handler_name); in free_multipath()
223 kfree(m->hw_handler_params); in free_multipath()
224 mempool_destroy(m->mpio_pool); in free_multipath()
225 kfree(m); in free_multipath()
228 static int set_mapinfo(struct multipath *m, union map_info *info) in set_mapinfo() argument
232 mpio = mempool_alloc(m->mpio_pool, GFP_ATOMIC); in set_mapinfo()
242 static void clear_mapinfo(struct multipath *m, union map_info *info) in clear_mapinfo() argument
247 mempool_free(mpio, m->mpio_pool); in clear_mapinfo()
254 static int __pg_init_all_paths(struct multipath *m) in __pg_init_all_paths() argument
259 if (m->pg_init_in_progress || m->pg_init_disabled) in __pg_init_all_paths()
262 m->pg_init_count++; in __pg_init_all_paths()
263 m->pg_init_required = 0; in __pg_init_all_paths()
266 if (!m->current_pg) in __pg_init_all_paths()
269 if (m->pg_init_delay_retry) in __pg_init_all_paths()
270 pg_init_delay = msecs_to_jiffies(m->pg_init_delay_msecs != DM_PG_INIT_DELAY_DEFAULT ? in __pg_init_all_paths()
271 m->pg_init_delay_msecs : DM_PG_INIT_DELAY_MSECS); in __pg_init_all_paths()
272 list_for_each_entry(pgpath, &m->current_pg->pgpaths, list) { in __pg_init_all_paths()
278 m->pg_init_in_progress++; in __pg_init_all_paths()
280 return m->pg_init_in_progress; in __pg_init_all_paths()
283 static void __switch_pg(struct multipath *m, struct pgpath *pgpath) in __switch_pg() argument
285 m->current_pg = pgpath->pg; in __switch_pg()
288 if (m->hw_handler_name) { in __switch_pg()
289 m->pg_init_required = 1; in __switch_pg()
290 m->queue_io = 1; in __switch_pg()
292 m->pg_init_required = 0; in __switch_pg()
293 m->queue_io = 0; in __switch_pg()
296 m->pg_init_count = 0; in __switch_pg()
299 static int __choose_path_in_pg(struct multipath *m, struct priority_group *pg, in __choose_path_in_pg() argument
304 path = pg->ps.type->select_path(&pg->ps, &m->repeat_count, nr_bytes); in __choose_path_in_pg()
308 m->current_pgpath = path_to_pgpath(path); in __choose_path_in_pg()
310 if (m->current_pg != pg) in __choose_path_in_pg()
311 __switch_pg(m, m->current_pgpath); in __choose_path_in_pg()
316 static void __choose_pgpath(struct multipath *m, size_t nr_bytes) in __choose_pgpath() argument
321 if (!m->nr_valid_paths) { in __choose_pgpath()
322 m->queue_io = 0; in __choose_pgpath()
327 if (m->next_pg) { in __choose_pgpath()
328 pg = m->next_pg; in __choose_pgpath()
329 m->next_pg = NULL; in __choose_pgpath()
330 if (!__choose_path_in_pg(m, pg, nr_bytes)) in __choose_pgpath()
335 if (m->current_pg && !__choose_path_in_pg(m, m->current_pg, nr_bytes)) in __choose_pgpath()
345 list_for_each_entry(pg, &m->priority_groups, list) { in __choose_pgpath()
348 if (!__choose_path_in_pg(m, pg, nr_bytes)) { in __choose_pgpath()
350 m->pg_init_delay_retry = 1; in __choose_pgpath()
357 m->current_pgpath = NULL; in __choose_pgpath()
358 m->current_pg = NULL; in __choose_pgpath()
372 static int __must_push_back(struct multipath *m) in __must_push_back() argument
374 return (m->queue_if_no_path || in __must_push_back()
375 (m->queue_if_no_path != m->saved_queue_if_no_path && in __must_push_back()
376 dm_noflush_suspending(m->ti))); in __must_push_back()
386 struct multipath *m = (struct multipath *) ti->private; in __multipath_map() local
393 spin_lock_irq(&m->lock); in __multipath_map()
396 if (!m->current_pgpath || in __multipath_map()
397 (!m->queue_io && (m->repeat_count && --m->repeat_count == 0))) in __multipath_map()
398 __choose_pgpath(m, nr_bytes); in __multipath_map()
400 pgpath = m->current_pgpath; in __multipath_map()
403 if (!__must_push_back(m)) in __multipath_map()
406 } else if (m->queue_io || m->pg_init_required) { in __multipath_map()
407 __pg_init_all_paths(m); in __multipath_map()
411 if (set_mapinfo(m, map_context) < 0) in __multipath_map()
421 spin_unlock_irq(&m->lock); in __multipath_map()
434 clear_mapinfo(m, map_context); in __multipath_map()
449 spin_unlock_irq(&m->lock); in __multipath_map()
475 static int queue_if_no_path(struct multipath *m, unsigned queue_if_no_path, in queue_if_no_path() argument
480 spin_lock_irqsave(&m->lock, flags); in queue_if_no_path()
483 m->saved_queue_if_no_path = m->queue_if_no_path; in queue_if_no_path()
485 m->saved_queue_if_no_path = queue_if_no_path; in queue_if_no_path()
486 m->queue_if_no_path = queue_if_no_path; in queue_if_no_path()
487 spin_unlock_irqrestore(&m->lock, flags); in queue_if_no_path()
490 dm_table_run_md_queue_async(m->ti->table); in queue_if_no_path()
501 struct multipath *m = in trigger_event() local
504 dm_table_event(m->ti->table); in trigger_event()
558 struct multipath *m = ti->private; in parse_path() local
579 if (m->retain_attached_hw_handler || m->hw_handler_name) in parse_path()
582 if (m->retain_attached_hw_handler) { in parse_path()
593 kfree(m->hw_handler_name); in parse_path()
594 m->hw_handler_name = attached_handler_name; in parse_path()
596 kfree(m->hw_handler_params); in parse_path()
597 m->hw_handler_params = NULL; in parse_path()
601 if (m->hw_handler_name) { in parse_path()
606 r = scsi_dh_attach(q, m->hw_handler_name); in parse_path()
613 r = scsi_dh_attach(q, m->hw_handler_name); in parse_path()
622 if (m->hw_handler_params) { in parse_path()
623 r = scsi_dh_set_params(q, m->hw_handler_params); in parse_path()
648 struct multipath *m) in parse_priority_group() argument
658 struct dm_target *ti = m->ti; in parse_priority_group()
671 pg->m = m; in parse_priority_group()
720 static int parse_hw_handler(struct dm_arg_set *as, struct multipath *m) in parse_hw_handler() argument
724 struct dm_target *ti = m->ti; in parse_hw_handler()
736 m->hw_handler_name = kstrdup(dm_shift_arg(as), GFP_KERNEL); in parse_hw_handler()
737 if (!try_then_request_module(scsi_dh_handler_exist(m->hw_handler_name), in parse_hw_handler()
738 "scsi_dh_%s", m->hw_handler_name)) { in parse_hw_handler()
750 p = m->hw_handler_params = kzalloc(len, GFP_KERNEL); in parse_hw_handler()
764 kfree(m->hw_handler_name); in parse_hw_handler()
765 m->hw_handler_name = NULL; in parse_hw_handler()
769 static int parse_features(struct dm_arg_set *as, struct multipath *m) in parse_features() argument
773 struct dm_target *ti = m->ti; in parse_features()
794 r = queue_if_no_path(m, 1, 0); in parse_features()
799 m->retain_attached_hw_handler = 1; in parse_features()
805 r = dm_read_arg(_args + 1, as, &m->pg_init_retries, &ti->error); in parse_features()
812 r = dm_read_arg(_args + 2, as, &m->pg_init_delay_msecs, &ti->error); in parse_features()
834 struct multipath *m; in multipath_ctr() local
842 m = alloc_multipath(ti); in multipath_ctr()
843 if (!m) { in multipath_ctr()
848 r = parse_features(&as, m); in multipath_ctr()
852 r = parse_hw_handler(&as, m); in multipath_ctr()
856 r = dm_read_arg(_args, &as, &m->nr_priority_groups, &ti->error); in multipath_ctr()
864 if ((!m->nr_priority_groups && next_pg_num) || in multipath_ctr()
865 (m->nr_priority_groups && !next_pg_num)) { in multipath_ctr()
875 pg = parse_priority_group(&as, m); in multipath_ctr()
881 m->nr_valid_paths += pg->nr_pgpaths; in multipath_ctr()
882 list_add_tail(&pg->list, &m->priority_groups); in multipath_ctr()
886 m->next_pg = pg; in multipath_ctr()
889 if (pg_count != m->nr_priority_groups) { in multipath_ctr()
902 free_multipath(m); in multipath_ctr()
906 static void multipath_wait_for_pg_init_completion(struct multipath *m) in multipath_wait_for_pg_init_completion() argument
911 add_wait_queue(&m->pg_init_wait, &wait); in multipath_wait_for_pg_init_completion()
916 spin_lock_irqsave(&m->lock, flags); in multipath_wait_for_pg_init_completion()
917 if (!m->pg_init_in_progress) { in multipath_wait_for_pg_init_completion()
918 spin_unlock_irqrestore(&m->lock, flags); in multipath_wait_for_pg_init_completion()
921 spin_unlock_irqrestore(&m->lock, flags); in multipath_wait_for_pg_init_completion()
927 remove_wait_queue(&m->pg_init_wait, &wait); in multipath_wait_for_pg_init_completion()
930 static void flush_multipath_work(struct multipath *m) in flush_multipath_work() argument
934 spin_lock_irqsave(&m->lock, flags); in flush_multipath_work()
935 m->pg_init_disabled = 1; in flush_multipath_work()
936 spin_unlock_irqrestore(&m->lock, flags); in flush_multipath_work()
939 multipath_wait_for_pg_init_completion(m); in flush_multipath_work()
941 flush_work(&m->trigger_event); in flush_multipath_work()
943 spin_lock_irqsave(&m->lock, flags); in flush_multipath_work()
944 m->pg_init_disabled = 0; in flush_multipath_work()
945 spin_unlock_irqrestore(&m->lock, flags); in flush_multipath_work()
950 struct multipath *m = ti->private; in multipath_dtr() local
952 flush_multipath_work(m); in multipath_dtr()
953 free_multipath(m); in multipath_dtr()
962 struct multipath *m = pgpath->pg->m; in fail_path() local
964 spin_lock_irqsave(&m->lock, flags); in fail_path()
975 m->nr_valid_paths--; in fail_path()
977 if (pgpath == m->current_pgpath) in fail_path()
978 m->current_pgpath = NULL; in fail_path()
980 dm_path_uevent(DM_UEVENT_PATH_FAILED, m->ti, in fail_path()
981 pgpath->path.dev->name, m->nr_valid_paths); in fail_path()
983 schedule_work(&m->trigger_event); in fail_path()
986 spin_unlock_irqrestore(&m->lock, flags); in fail_path()
998 struct multipath *m = pgpath->pg->m; in reinstate_path() local
1000 spin_lock_irqsave(&m->lock, flags); in reinstate_path()
1018 if (!m->nr_valid_paths++) { in reinstate_path()
1019 m->current_pgpath = NULL; in reinstate_path()
1021 } else if (m->hw_handler_name && (m->current_pg == pgpath->pg)) { in reinstate_path()
1023 m->pg_init_in_progress++; in reinstate_path()
1026 dm_path_uevent(DM_UEVENT_PATH_REINSTATED, m->ti, in reinstate_path()
1027 pgpath->path.dev->name, m->nr_valid_paths); in reinstate_path()
1029 schedule_work(&m->trigger_event); in reinstate_path()
1032 spin_unlock_irqrestore(&m->lock, flags); in reinstate_path()
1034 dm_table_run_md_queue_async(m->ti->table); in reinstate_path()
1042 static int action_dev(struct multipath *m, struct dm_dev *dev, in action_dev() argument
1049 list_for_each_entry(pg, &m->priority_groups, list) { in action_dev()
1062 static void bypass_pg(struct multipath *m, struct priority_group *pg, in bypass_pg() argument
1067 spin_lock_irqsave(&m->lock, flags); in bypass_pg()
1070 m->current_pgpath = NULL; in bypass_pg()
1071 m->current_pg = NULL; in bypass_pg()
1073 spin_unlock_irqrestore(&m->lock, flags); in bypass_pg()
1075 schedule_work(&m->trigger_event); in bypass_pg()
1081 static int switch_pg_num(struct multipath *m, const char *pgstr) in switch_pg_num() argument
1089 (pgnum > m->nr_priority_groups)) { in switch_pg_num()
1094 spin_lock_irqsave(&m->lock, flags); in switch_pg_num()
1095 list_for_each_entry(pg, &m->priority_groups, list) { in switch_pg_num()
1100 m->current_pgpath = NULL; in switch_pg_num()
1101 m->current_pg = NULL; in switch_pg_num()
1102 m->next_pg = pg; in switch_pg_num()
1104 spin_unlock_irqrestore(&m->lock, flags); in switch_pg_num()
1106 schedule_work(&m->trigger_event); in switch_pg_num()
1114 static int bypass_pg_num(struct multipath *m, const char *pgstr, int bypassed) in bypass_pg_num() argument
1121 (pgnum > m->nr_priority_groups)) { in bypass_pg_num()
1126 list_for_each_entry(pg, &m->priority_groups, list) { in bypass_pg_num()
1131 bypass_pg(m, pg, bypassed); in bypass_pg_num()
1138 static int pg_init_limit_reached(struct multipath *m, struct pgpath *pgpath) in pg_init_limit_reached() argument
1143 spin_lock_irqsave(&m->lock, flags); in pg_init_limit_reached()
1145 if (m->pg_init_count <= m->pg_init_retries && !m->pg_init_disabled) in pg_init_limit_reached()
1146 m->pg_init_required = 1; in pg_init_limit_reached()
1150 spin_unlock_irqrestore(&m->lock, flags); in pg_init_limit_reached()
1159 struct multipath *m = pg->m; in pg_init_done() local
1168 if (!m->hw_handler_name) { in pg_init_done()
1173 "Error %d.", m->hw_handler_name, errors); in pg_init_done()
1184 bypass_pg(m, pg, 1); in pg_init_done()
1191 if (pg_init_limit_reached(m, pgpath)) in pg_init_done()
1204 spin_lock_irqsave(&m->lock, flags); in pg_init_done()
1206 if (pgpath == m->current_pgpath) { in pg_init_done()
1208 m->current_pgpath = NULL; in pg_init_done()
1209 m->current_pg = NULL; in pg_init_done()
1211 } else if (!m->pg_init_required) in pg_init_done()
1214 if (--m->pg_init_in_progress) in pg_init_done()
1218 if (m->pg_init_required) { in pg_init_done()
1219 m->pg_init_delay_retry = delay_retry; in pg_init_done()
1220 if (__pg_init_all_paths(m)) in pg_init_done()
1223 m->queue_io = 0; in pg_init_done()
1228 wake_up(&m->pg_init_wait); in pg_init_done()
1231 spin_unlock_irqrestore(&m->lock, flags); in pg_init_done()
1264 static int do_end_io(struct multipath *m, struct request *clone, in do_end_io() argument
1290 spin_lock_irqsave(&m->lock, flags); in do_end_io()
1291 if (!m->nr_valid_paths) { in do_end_io()
1292 if (!m->queue_if_no_path) { in do_end_io()
1293 if (!__must_push_back(m)) in do_end_io()
1300 spin_unlock_irqrestore(&m->lock, flags); in do_end_io()
1308 struct multipath *m = ti->private; in multipath_end_io() local
1316 r = do_end_io(m, clone, error, mpio); in multipath_end_io()
1323 clear_mapinfo(m, map_context); in multipath_end_io()
1336 struct multipath *m = (struct multipath *) ti->private; in multipath_presuspend() local
1338 queue_if_no_path(m, 0, 1); in multipath_presuspend()
1343 struct multipath *m = ti->private; in multipath_postsuspend() local
1345 mutex_lock(&m->work_mutex); in multipath_postsuspend()
1346 flush_multipath_work(m); in multipath_postsuspend()
1347 mutex_unlock(&m->work_mutex); in multipath_postsuspend()
1355 struct multipath *m = (struct multipath *) ti->private; in multipath_resume() local
1358 spin_lock_irqsave(&m->lock, flags); in multipath_resume()
1359 m->queue_if_no_path = m->saved_queue_if_no_path; in multipath_resume()
1360 spin_unlock_irqrestore(&m->lock, flags); in multipath_resume()
1384 struct multipath *m = (struct multipath *) ti->private; in multipath_status() local
1390 spin_lock_irqsave(&m->lock, flags); in multipath_status()
1394 DMEMIT("2 %u %u ", m->queue_io, m->pg_init_count); in multipath_status()
1396 DMEMIT("%u ", m->queue_if_no_path + in multipath_status()
1397 (m->pg_init_retries > 0) * 2 + in multipath_status()
1398 (m->pg_init_delay_msecs != DM_PG_INIT_DELAY_DEFAULT) * 2 + in multipath_status()
1399 m->retain_attached_hw_handler); in multipath_status()
1400 if (m->queue_if_no_path) in multipath_status()
1402 if (m->pg_init_retries) in multipath_status()
1403 DMEMIT("pg_init_retries %u ", m->pg_init_retries); in multipath_status()
1404 if (m->pg_init_delay_msecs != DM_PG_INIT_DELAY_DEFAULT) in multipath_status()
1405 DMEMIT("pg_init_delay_msecs %u ", m->pg_init_delay_msecs); in multipath_status()
1406 if (m->retain_attached_hw_handler) in multipath_status()
1410 if (!m->hw_handler_name || type == STATUSTYPE_INFO) in multipath_status()
1413 DMEMIT("1 %s ", m->hw_handler_name); in multipath_status()
1415 DMEMIT("%u ", m->nr_priority_groups); in multipath_status()
1417 if (m->next_pg) in multipath_status()
1418 pg_num = m->next_pg->pg_num; in multipath_status()
1419 else if (m->current_pg) in multipath_status()
1420 pg_num = m->current_pg->pg_num; in multipath_status()
1422 pg_num = (m->nr_priority_groups ? 1 : 0); in multipath_status()
1428 list_for_each_entry(pg, &m->priority_groups, list) { in multipath_status()
1431 else if (pg == m->current_pg) in multipath_status()
1461 list_for_each_entry(pg, &m->priority_groups, list) { in multipath_status()
1485 spin_unlock_irqrestore(&m->lock, flags); in multipath_status()
1492 struct multipath *m = (struct multipath *) ti->private; in multipath_message() local
1495 mutex_lock(&m->work_mutex); in multipath_message()
1504 r = queue_if_no_path(m, 1, 0); in multipath_message()
1507 r = queue_if_no_path(m, 0, 0); in multipath_message()
1518 r = bypass_pg_num(m, argv[1], 1); in multipath_message()
1521 r = bypass_pg_num(m, argv[1], 0); in multipath_message()
1524 r = switch_pg_num(m, argv[1]); in multipath_message()
1542 r = action_dev(m, dev, action); in multipath_message()
1547 mutex_unlock(&m->work_mutex); in multipath_message()
1554 struct multipath *m = ti->private; in multipath_ioctl() local
1565 spin_lock_irqsave(&m->lock, flags); in multipath_ioctl()
1567 if (!m->current_pgpath) in multipath_ioctl()
1568 __choose_pgpath(m, 0); in multipath_ioctl()
1570 pgpath = m->current_pgpath; in multipath_ioctl()
1577 if ((pgpath && m->queue_io) || (!pgpath && m->queue_if_no_path)) in multipath_ioctl()
1582 spin_unlock_irqrestore(&m->lock, flags); in multipath_ioctl()
1594 spin_lock_irqsave(&m->lock, flags); in multipath_ioctl()
1595 if (!m->current_pg) { in multipath_ioctl()
1597 __choose_pgpath(m, 0); in multipath_ioctl()
1599 if (m->pg_init_required) in multipath_ioctl()
1600 __pg_init_all_paths(m); in multipath_ioctl()
1601 spin_unlock_irqrestore(&m->lock, flags); in multipath_ioctl()
1602 dm_table_run_md_queue_async(m->ti->table); in multipath_ioctl()
1611 struct multipath *m = ti->private; in multipath_iterate_devices() local
1616 list_for_each_entry(pg, &m->priority_groups, list) { in multipath_iterate_devices()
1646 struct multipath *m = ti->private; in multipath_busy() local
1651 spin_lock_irqsave(&m->lock, flags); in multipath_busy()
1654 if (m->pg_init_in_progress || in multipath_busy()
1655 (!m->nr_valid_paths && m->queue_if_no_path)) { in multipath_busy()
1660 if (unlikely(!m->current_pgpath && m->next_pg)) in multipath_busy()
1661 pg = m->next_pg; in multipath_busy()
1662 else if (likely(m->current_pg)) in multipath_busy()
1663 pg = m->current_pg; in multipath_busy()
1698 spin_unlock_irqrestore(&m->lock, flags); in multipath_busy()