Changes in 4.9.269 net: usb: ax88179_178a: initialize local variables before use iwlwifi: Fix softirq/hardirq disabling in iwl_pcie_enqueue_hcmd() ALSA: usb-audio: Add MIDI quirk for Vox ToneLab EX USB: Add LPM quirk for Lenovo ThinkPad USB-C Dock Gen2 Ethernet USB: Add reset-resume quirk for WD19's Realtek Hub platform/x86: thinkpad_acpi: Correct thermal sensor allocation s390/disassembler: increase ebpf disasm buffer size ACPI: custom_method: fix potential use-after-free issue ACPI: custom_method: fix a possible memory leak arm64: dts: mt8173: fix property typo of 'phys' in dsi node ecryptfs: fix kernel panic with null dev_name mmc: core: Do a power cycle when the CMD11 fails mmc: core: Set read only for SD cards with permanent write protect bit btrfs: fix metadata extent leak after failure to create subvolume fbdev: zero-fill colormap in fbcmap.c staging: wimax/i2400m: fix byte-order issue usb: gadget: uvc: add bInterval checking for HS mode usb: dwc3: gadget: Ignore EP queue requests during bus reset usb: xhci: Fix port minor revision PCI: PM: Do not read power state in pci_enable_device_flags() x86/build: Propagate $(CLANG_FLAGS) to $(REALMODE_FLAGS) spi: dln2: Fix reference leak to master spi: omap-100k: Fix reference leak to master intel_th: Consistency and off-by-one fix phy: phy-twl4030-usb: Fix possible use-after-free in twl4030_usb_remove() btrfs: convert logic BUG_ON()'s in replace_path to ASSERT()'s scsi: target: pscsi: Fix warning in pscsi_complete_cmd() media: ite-cir: check for receive overflow extcon: arizona: Fix some issues when HPDET IRQ fires after the jack has been unplugged media: media/saa7164: fix saa7164_encoder_register() memory leak bugs media: gspca/sq905.c: fix uninitialized variable power: supply: Use IRQF_ONESHOT scsi: qla2xxx: Always check the return value of qla24xx_get_isp_stats() scsi: scsi_dh_alua: Remove check for ASC 24h in alua_rtpg() media: em28xx: fix memory leak clk: socfpga: arria10: Fix memory leak of socfpga_clk on error return power: supply: generic-adc-battery: fix possible use-after-free in gab_remove() power: supply: s3c_adc_battery: fix possible use-after-free in s3c_adc_bat_remove() media: adv7604: fix possible use-after-free in adv76xx_remove() media: i2c: adv7511-v4l2: fix possible use-after-free in adv7511_remove() media: i2c: adv7842: fix possible use-after-free in adv7842_remove() media: dvb-usb: fix memory leak in dvb_usb_adapter_init media: gscpa/stv06xx: fix memory leak drm/msm/mdp5: Configure PP_SYNC_HEIGHT to double the vtotal drm/amdgpu: fix NULL pointer dereference scsi: lpfc: Fix crash when a REG_RPI mailbox fails triggering a LOGO response scsi: libfc: Fix a format specifier ALSA: emu8000: Fix a use after free in snd_emu8000_create_mixer ALSA: sb: Fix two use after free in snd_sb_qsound_build arm64/vdso: Discard .note.gnu.property sections in vDSO openvswitch: fix stack OOB read while fragmenting IPv4 packets NFSv4: Don't discard segments marked for return in _pnfs_return_layout() jffs2: Fix kasan slab-out-of-bounds problem powerpc/eeh: Fix EEH handling for hugepages in ioremap space. powerpc: fix EDEADLOCK redefinition error in uapi/asm/errno.h jffs2: check the validity of dstlen in jffs2_zlib_compress() Revert 337f13046ff0 ("futex: Allow FUTEX_CLOCK_REALTIME with FUTEX_WAIT op") ftrace: Handle commands when closing set_ftrace_filter file ext4: fix check to prevent false positive report of incorrect used inodes ext4: fix error code in ext4_commit_super media: dvbdev: Fix memory leak in dvb_media_device_free() usb: gadget: dummy_hcd: fix gpf in gadget_setup usb: gadget: Fix double free of device descriptor pointers usb: gadget/function/f_fs string table fix for multiple languages dm persistent data: packed struct should have an aligned() attribute too dm space map common: fix division bug in sm_ll_find_free_block() dm rq: fix double free of blk_mq_tag_set in dev remove after table load fails Bluetooth: verify AMP hci_chan before amp_destroy hsr: use netdev_err() instead of WARN_ONCE() bluetooth: eliminate the potential race condition when removing the HCI controller net/nfc: fix use-after-free llcp_sock_bind/connect FDDI: defxx: Bail out gracefully with unassigned PCI resource for CSR misc: lis3lv02d: Fix false-positive WARN on various HP models misc: vmw_vmci: explicitly initialize vmci_notify_bm_set_msg struct misc: vmw_vmci: explicitly initialize vmci_datagram payload tracing: Treat recording comm for idle task as a success tracing: Use strlcpy() instead of strcpy() in __trace_find_cmdline() tracing: Map all PIDs to command lines tracing: Restructure trace_clock_global() to never block md-cluster: fix use-after-free issue when removing rdev md: factor out a mddev_find_locked helper from mddev_find md: md_open returns -EBUSY when entering racing area ipw2x00: potential buffer overflow in libipw_wx_set_encodeext() cfg80211: scan: drop entry from hidden_list on overflow drm/radeon: fix copy of uninitialized variable back to userspace ALSA: hda/realtek: Re-order ALC882 Acer quirk table entries ALSA: hda/realtek: Re-order ALC882 Sony quirk table entries ALSA: hda/realtek: Re-order ALC269 Sony quirk table entries ALSA: hda/realtek: Re-order ALC269 Lenovo quirk table entries ALSA: hda/realtek: Remove redundant entry for ALC861 Haier/Uniwill devices usb: gadget: pch_udc: Revert d3cb25a12138 completely memory: gpmc: fix out of bounds read and dereference on gpmc_cs[] ARM: dts: exynos: correct PMIC interrupt trigger level on SMDK5250 ARM: dts: exynos: correct PMIC interrupt trigger level on Snow serial: stm32: fix incorrect characters on console usb: gadget: pch_udc: Replace cpu_to_le32() by lower_32_bits() usb: gadget: pch_udc: Check if driver is present before calling ->setup() usb: gadget: pch_udc: Check for DMA mapping error crypto: qat - don't release uninitialized resources crypto: qat - ADF_STATUS_PF_RUNNING should be set after adf_dev_init fotg210-udc: Fix DMA on EP0 for length > max packet size fotg210-udc: Fix EP0 IN requests bigger than two packets fotg210-udc: Remove a dubious condition leading to fotg210_done fotg210-udc: Mask GRP2 interrupts we don't handle fotg210-udc: Don't DMA more than the buffer can take fotg210-udc: Complete OUT requests on short packets mtd: require write permissions for locking and badblock ioctls bus: qcom: Put child node before return crypto: qat - fix error path in adf_isr_resource_alloc() mtd: rawnand: gpmi: Fix a double free in gpmi_nand_init staging: rtl8192u: Fix potential infinite loop staging: greybus: uart: fix unprivileged TIOCCSERIAL crypto: qat - Fix a double free in adf_create_ring usb: gadget: r8a66597: Add missing null check on return from platform_get_resource USB: cdc-acm: fix unprivileged TIOCCSERIAL tty: actually undefine superseded ASYNC flags tty: fix return value for unsupported ioctls firmware: qcom-scm: Fix QCOM_SCM configuration x86/platform/uv: Fix !KEXEC build failure Drivers: hv: vmbus: Increase wait time for VMbus unload ttyprintk: Add TTY hangup callback. media: vivid: fix assignment of dev->fbuf_out_flags media: omap4iss: return error code when omap4iss_get() failed media: m88rs6000t: avoid potential out-of-bounds reads on arrays pata_arasan_cf: fix IRQ check pata_ipx4xx_cf: fix IRQ check sata_mv: add IRQ checks ata: libahci_platform: fix IRQ check scsi: fcoe: Fix mismatched fcoe_wwn_from_mac declaration media: dvb-usb-remote: fix dvb_usb_nec_rc_key_to_event type mismatch clk: uniphier: Fix potential infinite loop scsi: jazz_esp: Add IRQ check scsi: sun3x_esp: Add IRQ check scsi: sni_53c710: Add IRQ check HSI: core: fix resource leaks in hsi_add_client_from_dt() x86/events/amd/iommu: Fix sysfs type mismatch HID: plantronics: Workaround for double volume key presses perf symbols: Fix dso__fprintf_symbols_by_name() to return the number of printed chars net: lapbether: Prevent racing when checking whether the netif is running powerpc/prom: Mark identical_pvr_fixup as __init ALSA: core: remove redundant spin_lock pair in snd_card_disconnect nfc: pn533: prevent potential memory corruption ALSA: usb-audio: Add error checks for usb_driver_claim_interface() calls liquidio: Fix unintented sign extension of a left shift of a u16 powerpc/perf: Fix PMU constraint check for EBB events powerpc: iommu: fix build when neither PCI or IBMVIO is set mac80211: bail out if cipher schemes are invalid mt7601u: fix always true expression net: thunderx: Fix unintentional sign extension issue i2c: cadence: add IRQ check i2c: emev2: add IRQ check i2c: jz4780: add IRQ check i2c: sh7760: add IRQ check MIPS: pci-legacy: stop using of_pci_range_to_resource powerpc/pseries: extract host bridge from pci_bus prior to bus removal i2c: sh7760: fix IRQ error path mwl8k: Fix a double Free in mwl8k_probe_hw vsock/vmci: log once the failed queue pair allocation RDMA/i40iw: Fix error unwinding when i40iw_hmc_sd_one fails net: davinci_emac: Fix incorrect masking of tx and rx error channel ath9k: Fix error check in ath9k_hw_read_revisions() for PCI devices powerpc/52xx: Fix an invalid ASM expression ('addi' used instead of 'add') net:emac/emac-mac: Fix a use after free in emac_mac_tx_buf_send net:nfc:digital: Fix a double free in digital_tg_recv_dep_req kfifo: fix ternary sign extension bugs Revert "net/sctp: fix race condition in sctp_destroy_sock" sctp: delay auto_asconf init until binding the first addr Revert "of/fdt: Make sure no-map does not remove already reserved regions" Revert "fdt: Properly handle "no-map" field in the memory region" fs: dlm: fix debugfs dump tipc: convert dest node's address to network order net: stmmac: Set FIFO sizes for ipq806x ALSA: hdsp: don't disable if not enabled ALSA: hdspm: don't disable if not enabled ALSA: rme9652: don't disable if not enabled Bluetooth: Set CONF_NOT_COMPLETE as l2cap_chan default Bluetooth: initialize skb_queue_head at l2cap_chan_create() ip6_vti: proper dev_{hold|put} in ndo_[un]init methods mac80211: clear the beacon's CRC after channel switch cuse: prevent clone selftests: Set CC to clang in lib.mk if LLVM is set kconfig: nconf: stop endless search loops sctp: Fix out-of-bounds warning in sctp_process_asconf_param() ASoC: rt286: Generalize support for ALC3263 codec samples/bpf: Fix broken tracex1 due to kprobe argument change powerpc/pseries: Stop calling printk in rtas_stop_self() wl3501_cs: Fix out-of-bounds warnings in wl3501_send_pkt wl3501_cs: Fix out-of-bounds warnings in wl3501_mgmt_join powerpc/iommu: Annotate nested lock for lockdep net: ethernet: mtk_eth_soc: fix RX VLAN offload ASoC: rt286: Make RT286_SET_GPIO_* readable and writable f2fs: fix a redundant call to f2fs_balance_fs if an error occurs PCI: Release OF node in pci_scan_device()'s error path ARM: 9064/1: hw_breakpoint: Do not directly check the event's overflow_handler hook NFSv4.2: Always flush out writes in nfs42_proc_fallocate() NFS: Deal correctly with attribute generation counter overflow pNFS/flexfiles: fix incorrect size check in decode_nfs_fh() NFSv4.2 fix handling of sr_eof in SEEK's reply sctp: fix a SCTP_MIB_CURRESTAB leak in sctp_sf_do_dupcook_b drm/radeon: Fix off-by-one power_state index heap overwrite khugepaged: fix wrong result value for trace_mm_collapse_huge_page_isolate() mm/hugeltb: handle the error case in hugetlb_fix_reserve_counts() ksm: fix potential missing rmap_item for stable_node kernel: kexec_file: fix error return code of kexec_calculate_store_digests() ARC: entry: fix off-by-one error in syscall number validation powerpc/64s: Fix crashes when toggling entry flush barrier squashfs: fix divide error in calculate_skip() iio: proximity: pulsedlight: Fix rumtime PM imbalance on error usb: fotg210-hcd: Fix an error message ACPI: scan: Fix a memory leak in an error handling path usb: xhci: Increase timeout for HC halt usb: dwc2: Fix gadget DMA unmap direction usb: core: hub: fix race condition about TRSMRCY of resume KVM: x86: Cancel pvclock_gtod_work on module removal FDDI: defxx: Make MMIO the configuration default except for EISA MIPS: Reinstate platform `__div64_32' handler MIPS: Avoid DIVU in `__div64_32' is result would be zero MIPS: Avoid handcoded DIVU in `__div64_32' altogether thermal/core/fair share: Lock the thermal zone while looping over instances dm ioctl: fix out of bounds array access when no devices kobject_uevent: remove warning in init_uevent_argv() netfilter: conntrack: Make global sysctls readonly in non-init netns clk: exynos7: Mark aclk_fsys1_200 as critical x86/msr: Fix wr/rdmsr_safe_regs_on_cpu() prototypes extcon: adc-jack: Fix incompatible pointer type warning kgdb: fix gcc-11 warning on indentation usb: sl811-hcd: improve misleading indentation cxgb4: Fix the -Wmisleading-indentation warning isdn: capi: fix mismatched prototypes ACPI / hotplug / PCI: Fix reference count leak in enable_slot() Input: silead - add workaround for x86 BIOS-es which bring the chip up in a stuck state um: Mark all kernel symbols as local ceph: fix fscache invalidation ALSA: hda: generic: change the DAC ctl name for LO+SPK or LO+HP lib: stackdepot: turn depot_lock spinlock to raw_spinlock sit: proper dev_{hold|put} in ndo_[un]init methods ip6_tunnel: sit: proper dev_{hold|put} in ndo_[un]init methods xhci: Do not use GFP_KERNEL in (potentially) atomic context ipv6: remove extra dev_hold() for fallback tunnels Linux 4.9.269 Signed-off-by: Greg Kroah-Hartman <gregkh@google.com> Change-Id: Ib994aef2c6746afa8dcbb237d8c0645ba2c6f7e1
1037 lines
26 KiB
C
1037 lines
26 KiB
C
/*
|
|
* Copyright (C) 2016 Red Hat, Inc. All rights reserved.
|
|
*
|
|
* This file is released under the GPL.
|
|
*/
|
|
|
|
#include "dm-core.h"
|
|
#include "dm-rq.h"
|
|
|
|
#include <linux/elevator.h> /* for rq_end_sector() */
|
|
#include <linux/blk-mq.h>
|
|
|
|
#define DM_MSG_PREFIX "core-rq"
|
|
|
|
#define DM_MQ_NR_HW_QUEUES 1
|
|
#define DM_MQ_QUEUE_DEPTH 2048
|
|
static unsigned dm_mq_nr_hw_queues = DM_MQ_NR_HW_QUEUES;
|
|
static unsigned dm_mq_queue_depth = DM_MQ_QUEUE_DEPTH;
|
|
|
|
/*
|
|
* Request-based DM's mempools' reserved IOs set by the user.
|
|
*/
|
|
#define RESERVED_REQUEST_BASED_IOS 256
|
|
static unsigned reserved_rq_based_ios = RESERVED_REQUEST_BASED_IOS;
|
|
|
|
#ifdef CONFIG_DM_MQ_DEFAULT
|
|
static bool use_blk_mq = true;
|
|
#else
|
|
static bool use_blk_mq = false;
|
|
#endif
|
|
|
|
bool dm_use_blk_mq_default(void)
|
|
{
|
|
return use_blk_mq;
|
|
}
|
|
|
|
bool dm_use_blk_mq(struct mapped_device *md)
|
|
{
|
|
return md->use_blk_mq;
|
|
}
|
|
EXPORT_SYMBOL_GPL(dm_use_blk_mq);
|
|
|
|
unsigned dm_get_reserved_rq_based_ios(void)
|
|
{
|
|
return __dm_get_module_param(&reserved_rq_based_ios,
|
|
RESERVED_REQUEST_BASED_IOS, DM_RESERVED_MAX_IOS);
|
|
}
|
|
EXPORT_SYMBOL_GPL(dm_get_reserved_rq_based_ios);
|
|
|
|
static unsigned dm_get_blk_mq_nr_hw_queues(void)
|
|
{
|
|
return __dm_get_module_param(&dm_mq_nr_hw_queues, 1, 32);
|
|
}
|
|
|
|
static unsigned dm_get_blk_mq_queue_depth(void)
|
|
{
|
|
return __dm_get_module_param(&dm_mq_queue_depth,
|
|
DM_MQ_QUEUE_DEPTH, BLK_MQ_MAX_DEPTH);
|
|
}
|
|
|
|
int dm_request_based(struct mapped_device *md)
|
|
{
|
|
return blk_queue_stackable(md->queue);
|
|
}
|
|
|
|
static void dm_old_start_queue(struct request_queue *q)
|
|
{
|
|
unsigned long flags;
|
|
|
|
spin_lock_irqsave(q->queue_lock, flags);
|
|
if (blk_queue_stopped(q))
|
|
blk_start_queue(q);
|
|
spin_unlock_irqrestore(q->queue_lock, flags);
|
|
}
|
|
|
|
static void dm_mq_start_queue(struct request_queue *q)
|
|
{
|
|
unsigned long flags;
|
|
|
|
spin_lock_irqsave(q->queue_lock, flags);
|
|
queue_flag_clear(QUEUE_FLAG_STOPPED, q);
|
|
spin_unlock_irqrestore(q->queue_lock, flags);
|
|
|
|
blk_mq_start_stopped_hw_queues(q, true);
|
|
blk_mq_kick_requeue_list(q);
|
|
}
|
|
|
|
void dm_start_queue(struct request_queue *q)
|
|
{
|
|
if (!q->mq_ops)
|
|
dm_old_start_queue(q);
|
|
else
|
|
dm_mq_start_queue(q);
|
|
}
|
|
|
|
static void dm_old_stop_queue(struct request_queue *q)
|
|
{
|
|
unsigned long flags;
|
|
|
|
spin_lock_irqsave(q->queue_lock, flags);
|
|
if (!blk_queue_stopped(q))
|
|
blk_stop_queue(q);
|
|
spin_unlock_irqrestore(q->queue_lock, flags);
|
|
}
|
|
|
|
static void dm_mq_stop_queue(struct request_queue *q)
|
|
{
|
|
unsigned long flags;
|
|
|
|
spin_lock_irqsave(q->queue_lock, flags);
|
|
if (blk_queue_stopped(q)) {
|
|
spin_unlock_irqrestore(q->queue_lock, flags);
|
|
return;
|
|
}
|
|
|
|
queue_flag_set(QUEUE_FLAG_STOPPED, q);
|
|
spin_unlock_irqrestore(q->queue_lock, flags);
|
|
|
|
/* Avoid that requeuing could restart the queue. */
|
|
blk_mq_cancel_requeue_work(q);
|
|
blk_mq_stop_hw_queues(q);
|
|
}
|
|
|
|
void dm_stop_queue(struct request_queue *q)
|
|
{
|
|
if (!q->mq_ops)
|
|
dm_old_stop_queue(q);
|
|
else
|
|
dm_mq_stop_queue(q);
|
|
}
|
|
|
|
static struct dm_rq_target_io *alloc_old_rq_tio(struct mapped_device *md,
|
|
gfp_t gfp_mask)
|
|
{
|
|
return mempool_alloc(md->io_pool, gfp_mask);
|
|
}
|
|
|
|
static void free_old_rq_tio(struct dm_rq_target_io *tio)
|
|
{
|
|
mempool_free(tio, tio->md->io_pool);
|
|
}
|
|
|
|
static struct request *alloc_old_clone_request(struct mapped_device *md,
|
|
gfp_t gfp_mask)
|
|
{
|
|
return mempool_alloc(md->rq_pool, gfp_mask);
|
|
}
|
|
|
|
static void free_old_clone_request(struct mapped_device *md, struct request *rq)
|
|
{
|
|
mempool_free(rq, md->rq_pool);
|
|
}
|
|
|
|
/*
|
|
* Partial completion handling for request-based dm
|
|
*/
|
|
static void end_clone_bio(struct bio *clone)
|
|
{
|
|
struct dm_rq_clone_bio_info *info =
|
|
container_of(clone, struct dm_rq_clone_bio_info, clone);
|
|
struct dm_rq_target_io *tio = info->tio;
|
|
struct bio *bio = info->orig;
|
|
unsigned int nr_bytes = info->orig->bi_iter.bi_size;
|
|
int error = clone->bi_error;
|
|
|
|
bio_put(clone);
|
|
|
|
if (tio->error)
|
|
/*
|
|
* An error has already been detected on the request.
|
|
* Once error occurred, just let clone->end_io() handle
|
|
* the remainder.
|
|
*/
|
|
return;
|
|
else if (error) {
|
|
/*
|
|
* Don't notice the error to the upper layer yet.
|
|
* The error handling decision is made by the target driver,
|
|
* when the request is completed.
|
|
*/
|
|
tio->error = error;
|
|
return;
|
|
}
|
|
|
|
/*
|
|
* I/O for the bio successfully completed.
|
|
* Notice the data completion to the upper layer.
|
|
*/
|
|
|
|
/*
|
|
* bios are processed from the head of the list.
|
|
* So the completing bio should always be rq->bio.
|
|
* If it's not, something wrong is happening.
|
|
*/
|
|
if (tio->orig->bio != bio)
|
|
DMERR("bio completion is going in the middle of the request");
|
|
|
|
/*
|
|
* Update the original request.
|
|
* Do not use blk_end_request() here, because it may complete
|
|
* the original request before the clone, and break the ordering.
|
|
*/
|
|
blk_update_request(tio->orig, 0, nr_bytes);
|
|
}
|
|
|
|
static struct dm_rq_target_io *tio_from_request(struct request *rq)
|
|
{
|
|
return (rq->q->mq_ops ? blk_mq_rq_to_pdu(rq) : rq->special);
|
|
}
|
|
|
|
static void rq_end_stats(struct mapped_device *md, struct request *orig)
|
|
{
|
|
if (unlikely(dm_stats_used(&md->stats))) {
|
|
struct dm_rq_target_io *tio = tio_from_request(orig);
|
|
tio->duration_jiffies = jiffies - tio->duration_jiffies;
|
|
dm_stats_account_io(&md->stats, rq_data_dir(orig),
|
|
blk_rq_pos(orig), tio->n_sectors, true,
|
|
tio->duration_jiffies, &tio->stats_aux);
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Don't touch any member of the md after calling this function because
|
|
* the md may be freed in dm_put() at the end of this function.
|
|
* Or do dm_get() before calling this function and dm_put() later.
|
|
*/
|
|
static void rq_completed(struct mapped_device *md, int rw, bool run_queue)
|
|
{
|
|
struct request_queue *q = md->queue;
|
|
unsigned long flags;
|
|
|
|
atomic_dec(&md->pending[rw]);
|
|
|
|
/* nudge anyone waiting on suspend queue */
|
|
if (!md_in_flight(md))
|
|
wake_up(&md->wait);
|
|
|
|
/*
|
|
* Run this off this callpath, as drivers could invoke end_io while
|
|
* inside their request_fn (and holding the queue lock). Calling
|
|
* back into ->request_fn() could deadlock attempting to grab the
|
|
* queue lock again.
|
|
*/
|
|
if (!q->mq_ops && run_queue) {
|
|
spin_lock_irqsave(q->queue_lock, flags);
|
|
blk_run_queue_async(q);
|
|
spin_unlock_irqrestore(q->queue_lock, flags);
|
|
}
|
|
|
|
/*
|
|
* dm_put() must be at the end of this function. See the comment above
|
|
*/
|
|
dm_put(md);
|
|
}
|
|
|
|
static void free_rq_clone(struct request *clone)
|
|
{
|
|
struct dm_rq_target_io *tio = clone->end_io_data;
|
|
struct mapped_device *md = tio->md;
|
|
|
|
blk_rq_unprep_clone(clone);
|
|
|
|
/*
|
|
* It is possible for a clone_old_rq() allocated clone to
|
|
* get passed in -- it may not yet have a request_queue.
|
|
* This is known to occur if the error target replaces
|
|
* a multipath target that has a request_fn queue stacked
|
|
* on blk-mq queue(s).
|
|
*/
|
|
if (clone->q && clone->q->mq_ops)
|
|
/* stacked on blk-mq queue(s) */
|
|
tio->ti->type->release_clone_rq(clone);
|
|
else if (!md->queue->mq_ops)
|
|
/* request_fn queue stacked on request_fn queue(s) */
|
|
free_old_clone_request(md, clone);
|
|
|
|
if (!md->queue->mq_ops)
|
|
free_old_rq_tio(tio);
|
|
}
|
|
|
|
/*
|
|
* Complete the clone and the original request.
|
|
* Must be called without clone's queue lock held,
|
|
* see end_clone_request() for more details.
|
|
*/
|
|
static void dm_end_request(struct request *clone, int error)
|
|
{
|
|
int rw = rq_data_dir(clone);
|
|
struct dm_rq_target_io *tio = clone->end_io_data;
|
|
struct mapped_device *md = tio->md;
|
|
struct request *rq = tio->orig;
|
|
|
|
if (rq->cmd_type == REQ_TYPE_BLOCK_PC) {
|
|
rq->errors = clone->errors;
|
|
rq->resid_len = clone->resid_len;
|
|
|
|
if (rq->sense)
|
|
/*
|
|
* We are using the sense buffer of the original
|
|
* request.
|
|
* So setting the length of the sense data is enough.
|
|
*/
|
|
rq->sense_len = clone->sense_len;
|
|
}
|
|
|
|
free_rq_clone(clone);
|
|
rq_end_stats(md, rq);
|
|
if (!rq->q->mq_ops)
|
|
blk_end_request_all(rq, error);
|
|
else
|
|
blk_mq_end_request(rq, error);
|
|
rq_completed(md, rw, true);
|
|
}
|
|
|
|
static void dm_unprep_request(struct request *rq)
|
|
{
|
|
struct dm_rq_target_io *tio = tio_from_request(rq);
|
|
struct request *clone = tio->clone;
|
|
|
|
if (!rq->q->mq_ops) {
|
|
rq->special = NULL;
|
|
rq->cmd_flags &= ~REQ_DONTPREP;
|
|
}
|
|
|
|
if (clone)
|
|
free_rq_clone(clone);
|
|
else if (!tio->md->queue->mq_ops)
|
|
free_old_rq_tio(tio);
|
|
}
|
|
|
|
/*
|
|
* Requeue the original request of a clone.
|
|
*/
|
|
static void dm_old_requeue_request(struct request *rq)
|
|
{
|
|
struct request_queue *q = rq->q;
|
|
unsigned long flags;
|
|
|
|
spin_lock_irqsave(q->queue_lock, flags);
|
|
blk_requeue_request(q, rq);
|
|
blk_run_queue_async(q);
|
|
spin_unlock_irqrestore(q->queue_lock, flags);
|
|
}
|
|
|
|
static void __dm_mq_kick_requeue_list(struct request_queue *q, unsigned long msecs)
|
|
{
|
|
unsigned long flags;
|
|
|
|
spin_lock_irqsave(q->queue_lock, flags);
|
|
if (!blk_queue_stopped(q))
|
|
blk_mq_delay_kick_requeue_list(q, msecs);
|
|
spin_unlock_irqrestore(q->queue_lock, flags);
|
|
}
|
|
|
|
void dm_mq_kick_requeue_list(struct mapped_device *md)
|
|
{
|
|
__dm_mq_kick_requeue_list(dm_get_md_queue(md), 0);
|
|
}
|
|
EXPORT_SYMBOL(dm_mq_kick_requeue_list);
|
|
|
|
static void dm_mq_delay_requeue_request(struct request *rq, unsigned long msecs)
|
|
{
|
|
blk_mq_requeue_request(rq);
|
|
__dm_mq_kick_requeue_list(rq->q, msecs);
|
|
}
|
|
|
|
static void dm_requeue_original_request(struct dm_rq_target_io *tio, bool delay_requeue)
|
|
{
|
|
struct mapped_device *md = tio->md;
|
|
struct request *rq = tio->orig;
|
|
int rw = rq_data_dir(rq);
|
|
|
|
rq_end_stats(md, rq);
|
|
dm_unprep_request(rq);
|
|
|
|
if (!rq->q->mq_ops)
|
|
dm_old_requeue_request(rq);
|
|
else
|
|
dm_mq_delay_requeue_request(rq, delay_requeue ? 5000 : 0);
|
|
|
|
rq_completed(md, rw, false);
|
|
}
|
|
|
|
static void dm_done(struct request *clone, int error, bool mapped)
|
|
{
|
|
int r = error;
|
|
struct dm_rq_target_io *tio = clone->end_io_data;
|
|
dm_request_endio_fn rq_end_io = NULL;
|
|
|
|
if (tio->ti) {
|
|
rq_end_io = tio->ti->type->rq_end_io;
|
|
|
|
if (mapped && rq_end_io)
|
|
r = rq_end_io(tio->ti, clone, error, &tio->info);
|
|
}
|
|
|
|
if (unlikely(r == -EREMOTEIO && (req_op(clone) == REQ_OP_WRITE_SAME) &&
|
|
!clone->q->limits.max_write_same_sectors))
|
|
disable_write_same(tio->md);
|
|
|
|
if (r <= 0)
|
|
/* The target wants to complete the I/O */
|
|
dm_end_request(clone, r);
|
|
else if (r == DM_ENDIO_INCOMPLETE)
|
|
/* The target will handle the I/O */
|
|
return;
|
|
else if (r == DM_ENDIO_REQUEUE)
|
|
/* The target wants to requeue the I/O */
|
|
dm_requeue_original_request(tio, false);
|
|
else {
|
|
DMWARN("unimplemented target endio return value: %d", r);
|
|
BUG();
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Request completion handler for request-based dm
|
|
*/
|
|
static void dm_softirq_done(struct request *rq)
|
|
{
|
|
bool mapped = true;
|
|
struct dm_rq_target_io *tio = tio_from_request(rq);
|
|
struct request *clone = tio->clone;
|
|
int rw;
|
|
|
|
if (!clone) {
|
|
rq_end_stats(tio->md, rq);
|
|
rw = rq_data_dir(rq);
|
|
if (!rq->q->mq_ops) {
|
|
blk_end_request_all(rq, tio->error);
|
|
rq_completed(tio->md, rw, false);
|
|
free_old_rq_tio(tio);
|
|
} else {
|
|
blk_mq_end_request(rq, tio->error);
|
|
rq_completed(tio->md, rw, false);
|
|
}
|
|
return;
|
|
}
|
|
|
|
if (rq->cmd_flags & REQ_FAILED)
|
|
mapped = false;
|
|
|
|
dm_done(clone, tio->error, mapped);
|
|
}
|
|
|
|
/*
|
|
* Complete the clone and the original request with the error status
|
|
* through softirq context.
|
|
*/
|
|
static void dm_complete_request(struct request *rq, int error)
|
|
{
|
|
struct dm_rq_target_io *tio = tio_from_request(rq);
|
|
|
|
tio->error = error;
|
|
if (!rq->q->mq_ops)
|
|
blk_complete_request(rq);
|
|
else
|
|
blk_mq_complete_request(rq, error);
|
|
}
|
|
|
|
/*
|
|
* Complete the not-mapped clone and the original request with the error status
|
|
* through softirq context.
|
|
* Target's rq_end_io() function isn't called.
|
|
* This may be used when the target's map_rq() or clone_and_map_rq() functions fail.
|
|
*/
|
|
static void dm_kill_unmapped_request(struct request *rq, int error)
|
|
{
|
|
rq->cmd_flags |= REQ_FAILED;
|
|
dm_complete_request(rq, error);
|
|
}
|
|
|
|
/*
|
|
* Called with the clone's queue lock held (in the case of .request_fn)
|
|
*/
|
|
static void end_clone_request(struct request *clone, int error)
|
|
{
|
|
struct dm_rq_target_io *tio = clone->end_io_data;
|
|
|
|
if (!clone->q->mq_ops) {
|
|
/*
|
|
* For just cleaning up the information of the queue in which
|
|
* the clone was dispatched.
|
|
* The clone is *NOT* freed actually here because it is alloced
|
|
* from dm own mempool (REQ_ALLOCED isn't set).
|
|
*/
|
|
__blk_put_request(clone->q, clone);
|
|
}
|
|
|
|
/*
|
|
* Actual request completion is done in a softirq context which doesn't
|
|
* hold the clone's queue lock. Otherwise, deadlock could occur because:
|
|
* - another request may be submitted by the upper level driver
|
|
* of the stacking during the completion
|
|
* - the submission which requires queue lock may be done
|
|
* against this clone's queue
|
|
*/
|
|
dm_complete_request(tio->orig, error);
|
|
}
|
|
|
|
static void dm_dispatch_clone_request(struct request *clone, struct request *rq)
|
|
{
|
|
int r;
|
|
|
|
if (blk_queue_io_stat(clone->q))
|
|
clone->cmd_flags |= REQ_IO_STAT;
|
|
|
|
clone->start_time = jiffies;
|
|
r = blk_insert_cloned_request(clone->q, clone);
|
|
if (r)
|
|
/* must complete clone in terms of original request */
|
|
dm_complete_request(rq, r);
|
|
}
|
|
|
|
static int dm_rq_bio_constructor(struct bio *bio, struct bio *bio_orig,
|
|
void *data)
|
|
{
|
|
struct dm_rq_target_io *tio = data;
|
|
struct dm_rq_clone_bio_info *info =
|
|
container_of(bio, struct dm_rq_clone_bio_info, clone);
|
|
|
|
info->orig = bio_orig;
|
|
info->tio = tio;
|
|
bio->bi_end_io = end_clone_bio;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int setup_clone(struct request *clone, struct request *rq,
|
|
struct dm_rq_target_io *tio, gfp_t gfp_mask)
|
|
{
|
|
int r;
|
|
|
|
r = blk_rq_prep_clone(clone, rq, tio->md->bs, gfp_mask,
|
|
dm_rq_bio_constructor, tio);
|
|
if (r)
|
|
return r;
|
|
|
|
clone->cmd = rq->cmd;
|
|
clone->cmd_len = rq->cmd_len;
|
|
clone->sense = rq->sense;
|
|
clone->end_io = end_clone_request;
|
|
clone->end_io_data = tio;
|
|
|
|
tio->clone = clone;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static struct request *clone_old_rq(struct request *rq, struct mapped_device *md,
|
|
struct dm_rq_target_io *tio, gfp_t gfp_mask)
|
|
{
|
|
/*
|
|
* Create clone for use with .request_fn request_queue
|
|
*/
|
|
struct request *clone;
|
|
|
|
clone = alloc_old_clone_request(md, gfp_mask);
|
|
if (!clone)
|
|
return NULL;
|
|
|
|
blk_rq_init(NULL, clone);
|
|
if (setup_clone(clone, rq, tio, gfp_mask)) {
|
|
/* -ENOMEM */
|
|
free_old_clone_request(md, clone);
|
|
return NULL;
|
|
}
|
|
|
|
return clone;
|
|
}
|
|
|
|
static void map_tio_request(struct kthread_work *work);
|
|
|
|
static void init_tio(struct dm_rq_target_io *tio, struct request *rq,
|
|
struct mapped_device *md)
|
|
{
|
|
tio->md = md;
|
|
tio->ti = NULL;
|
|
tio->clone = NULL;
|
|
tio->orig = rq;
|
|
tio->error = 0;
|
|
/*
|
|
* Avoid initializing info for blk-mq; it passes
|
|
* target-specific data through info.ptr
|
|
* (see: dm_mq_init_request)
|
|
*/
|
|
if (!md->init_tio_pdu)
|
|
memset(&tio->info, 0, sizeof(tio->info));
|
|
if (md->kworker_task)
|
|
kthread_init_work(&tio->work, map_tio_request);
|
|
}
|
|
|
|
static struct dm_rq_target_io *dm_old_prep_tio(struct request *rq,
|
|
struct mapped_device *md,
|
|
gfp_t gfp_mask)
|
|
{
|
|
struct dm_rq_target_io *tio;
|
|
int srcu_idx;
|
|
struct dm_table *table;
|
|
|
|
tio = alloc_old_rq_tio(md, gfp_mask);
|
|
if (!tio)
|
|
return NULL;
|
|
|
|
init_tio(tio, rq, md);
|
|
|
|
table = dm_get_live_table(md, &srcu_idx);
|
|
/*
|
|
* Must clone a request if this .request_fn DM device
|
|
* is stacked on .request_fn device(s).
|
|
*/
|
|
if (!dm_table_all_blk_mq_devices(table)) {
|
|
if (!clone_old_rq(rq, md, tio, gfp_mask)) {
|
|
dm_put_live_table(md, srcu_idx);
|
|
free_old_rq_tio(tio);
|
|
return NULL;
|
|
}
|
|
}
|
|
dm_put_live_table(md, srcu_idx);
|
|
|
|
return tio;
|
|
}
|
|
|
|
/*
|
|
* Called with the queue lock held.
|
|
*/
|
|
static int dm_old_prep_fn(struct request_queue *q, struct request *rq)
|
|
{
|
|
struct mapped_device *md = q->queuedata;
|
|
struct dm_rq_target_io *tio;
|
|
|
|
if (unlikely(rq->special)) {
|
|
DMWARN("Already has something in rq->special.");
|
|
return BLKPREP_KILL;
|
|
}
|
|
|
|
tio = dm_old_prep_tio(rq, md, GFP_ATOMIC);
|
|
if (!tio)
|
|
return BLKPREP_DEFER;
|
|
|
|
rq->special = tio;
|
|
rq->cmd_flags |= REQ_DONTPREP;
|
|
|
|
return BLKPREP_OK;
|
|
}
|
|
|
|
/*
|
|
* Returns:
|
|
* DM_MAPIO_* : the request has been processed as indicated
|
|
* DM_MAPIO_REQUEUE : the original request needs to be immediately requeued
|
|
* < 0 : the request was completed due to failure
|
|
*/
|
|
static int map_request(struct dm_rq_target_io *tio)
|
|
{
|
|
int r;
|
|
struct dm_target *ti = tio->ti;
|
|
struct mapped_device *md = tio->md;
|
|
struct request *rq = tio->orig;
|
|
struct request *clone = NULL;
|
|
|
|
if (tio->clone) {
|
|
clone = tio->clone;
|
|
r = ti->type->map_rq(ti, clone, &tio->info);
|
|
if (r == DM_MAPIO_DELAY_REQUEUE)
|
|
return DM_MAPIO_REQUEUE; /* .request_fn requeue is always immediate */
|
|
} else {
|
|
r = ti->type->clone_and_map_rq(ti, rq, &tio->info, &clone);
|
|
if (r < 0) {
|
|
/* The target wants to complete the I/O */
|
|
dm_kill_unmapped_request(rq, r);
|
|
return r;
|
|
}
|
|
if (r == DM_MAPIO_REMAPPED &&
|
|
setup_clone(clone, rq, tio, GFP_ATOMIC)) {
|
|
/* -ENOMEM */
|
|
ti->type->release_clone_rq(clone);
|
|
return DM_MAPIO_REQUEUE;
|
|
}
|
|
}
|
|
|
|
switch (r) {
|
|
case DM_MAPIO_SUBMITTED:
|
|
/* The target has taken the I/O to submit by itself later */
|
|
break;
|
|
case DM_MAPIO_REMAPPED:
|
|
/* The target has remapped the I/O so dispatch it */
|
|
trace_block_rq_remap(clone->q, clone, disk_devt(dm_disk(md)),
|
|
blk_rq_pos(rq));
|
|
dm_dispatch_clone_request(clone, rq);
|
|
break;
|
|
case DM_MAPIO_REQUEUE:
|
|
/* The target wants to requeue the I/O */
|
|
break;
|
|
case DM_MAPIO_DELAY_REQUEUE:
|
|
/* The target wants to requeue the I/O after a delay */
|
|
dm_requeue_original_request(tio, true);
|
|
break;
|
|
default:
|
|
if (r > 0) {
|
|
DMWARN("unimplemented target map return value: %d", r);
|
|
BUG();
|
|
}
|
|
|
|
/* The target wants to complete the I/O */
|
|
dm_kill_unmapped_request(rq, r);
|
|
}
|
|
|
|
return r;
|
|
}
|
|
|
|
static void dm_start_request(struct mapped_device *md, struct request *orig)
|
|
{
|
|
if (!orig->q->mq_ops)
|
|
blk_start_request(orig);
|
|
else
|
|
blk_mq_start_request(orig);
|
|
atomic_inc(&md->pending[rq_data_dir(orig)]);
|
|
|
|
if (md->seq_rq_merge_deadline_usecs) {
|
|
md->last_rq_pos = rq_end_sector(orig);
|
|
md->last_rq_rw = rq_data_dir(orig);
|
|
md->last_rq_start_time = ktime_get();
|
|
}
|
|
|
|
if (unlikely(dm_stats_used(&md->stats))) {
|
|
struct dm_rq_target_io *tio = tio_from_request(orig);
|
|
tio->duration_jiffies = jiffies;
|
|
tio->n_sectors = blk_rq_sectors(orig);
|
|
dm_stats_account_io(&md->stats, rq_data_dir(orig),
|
|
blk_rq_pos(orig), tio->n_sectors, false, 0,
|
|
&tio->stats_aux);
|
|
}
|
|
|
|
/*
|
|
* Hold the md reference here for the in-flight I/O.
|
|
* We can't rely on the reference count by device opener,
|
|
* because the device may be closed during the request completion
|
|
* when all bios are completed.
|
|
* See the comment in rq_completed() too.
|
|
*/
|
|
dm_get(md);
|
|
}
|
|
|
|
static void map_tio_request(struct kthread_work *work)
|
|
{
|
|
struct dm_rq_target_io *tio = container_of(work, struct dm_rq_target_io, work);
|
|
|
|
if (map_request(tio) == DM_MAPIO_REQUEUE)
|
|
dm_requeue_original_request(tio, false);
|
|
}
|
|
|
|
ssize_t dm_attr_rq_based_seq_io_merge_deadline_show(struct mapped_device *md, char *buf)
|
|
{
|
|
return sprintf(buf, "%u\n", md->seq_rq_merge_deadline_usecs);
|
|
}
|
|
|
|
#define MAX_SEQ_RQ_MERGE_DEADLINE_USECS 100000
|
|
|
|
ssize_t dm_attr_rq_based_seq_io_merge_deadline_store(struct mapped_device *md,
|
|
const char *buf, size_t count)
|
|
{
|
|
unsigned deadline;
|
|
|
|
if (dm_get_md_type(md) != DM_TYPE_REQUEST_BASED)
|
|
return count;
|
|
|
|
if (kstrtouint(buf, 10, &deadline))
|
|
return -EINVAL;
|
|
|
|
if (deadline > MAX_SEQ_RQ_MERGE_DEADLINE_USECS)
|
|
deadline = MAX_SEQ_RQ_MERGE_DEADLINE_USECS;
|
|
|
|
md->seq_rq_merge_deadline_usecs = deadline;
|
|
|
|
return count;
|
|
}
|
|
|
|
static bool dm_old_request_peeked_before_merge_deadline(struct mapped_device *md)
|
|
{
|
|
ktime_t kt_deadline;
|
|
|
|
if (!md->seq_rq_merge_deadline_usecs)
|
|
return false;
|
|
|
|
kt_deadline = ns_to_ktime((u64)md->seq_rq_merge_deadline_usecs * NSEC_PER_USEC);
|
|
kt_deadline = ktime_add_safe(md->last_rq_start_time, kt_deadline);
|
|
|
|
return !ktime_after(ktime_get(), kt_deadline);
|
|
}
|
|
|
|
/*
|
|
* q->request_fn for old request-based dm.
|
|
* Called with the queue lock held.
|
|
*/
|
|
static void dm_old_request_fn(struct request_queue *q)
|
|
{
|
|
struct mapped_device *md = q->queuedata;
|
|
struct dm_target *ti = md->immutable_target;
|
|
struct request *rq;
|
|
struct dm_rq_target_io *tio;
|
|
sector_t pos = 0;
|
|
|
|
if (unlikely(!ti)) {
|
|
int srcu_idx;
|
|
struct dm_table *map = dm_get_live_table(md, &srcu_idx);
|
|
|
|
if (unlikely(!map)) {
|
|
dm_put_live_table(md, srcu_idx);
|
|
return;
|
|
}
|
|
ti = dm_table_find_target(map, pos);
|
|
dm_put_live_table(md, srcu_idx);
|
|
}
|
|
|
|
/*
|
|
* For suspend, check blk_queue_stopped() and increment
|
|
* ->pending within a single queue_lock not to increment the
|
|
* number of in-flight I/Os after the queue is stopped in
|
|
* dm_suspend().
|
|
*/
|
|
while (!blk_queue_stopped(q)) {
|
|
rq = blk_peek_request(q);
|
|
if (!rq)
|
|
return;
|
|
|
|
/* always use block 0 to find the target for flushes for now */
|
|
pos = 0;
|
|
if (req_op(rq) != REQ_OP_FLUSH)
|
|
pos = blk_rq_pos(rq);
|
|
|
|
if ((dm_old_request_peeked_before_merge_deadline(md) &&
|
|
md_in_flight(md) && rq->bio && rq->bio->bi_vcnt == 1 &&
|
|
md->last_rq_pos == pos && md->last_rq_rw == rq_data_dir(rq)) ||
|
|
(ti->type->busy && ti->type->busy(ti))) {
|
|
blk_delay_queue(q, 10);
|
|
return;
|
|
}
|
|
|
|
dm_start_request(md, rq);
|
|
|
|
tio = tio_from_request(rq);
|
|
/* Establish tio->ti before queuing work (map_tio_request) */
|
|
tio->ti = ti;
|
|
kthread_queue_work(&md->kworker, &tio->work);
|
|
BUG_ON(!irqs_disabled());
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Fully initialize a .request_fn request-based queue.
|
|
*/
|
|
int dm_old_init_request_queue(struct mapped_device *md)
|
|
{
|
|
/* Fully initialize the queue */
|
|
if (!blk_init_allocated_queue(md->queue, dm_old_request_fn, NULL))
|
|
return -EINVAL;
|
|
|
|
/* disable dm_old_request_fn's merge heuristic by default */
|
|
md->seq_rq_merge_deadline_usecs = 0;
|
|
|
|
dm_init_normal_md_queue(md);
|
|
blk_queue_softirq_done(md->queue, dm_softirq_done);
|
|
blk_queue_prep_rq(md->queue, dm_old_prep_fn);
|
|
|
|
/* Initialize the request-based DM worker thread */
|
|
kthread_init_worker(&md->kworker);
|
|
md->kworker_task = kthread_run(kthread_worker_fn, &md->kworker,
|
|
"kdmwork-%s", dm_device_name(md));
|
|
if (IS_ERR(md->kworker_task)) {
|
|
int error = PTR_ERR(md->kworker_task);
|
|
md->kworker_task = NULL;
|
|
return error;
|
|
}
|
|
|
|
elv_register_queue(md->queue);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int dm_mq_init_request(void *data, struct request *rq,
|
|
unsigned int hctx_idx, unsigned int request_idx,
|
|
unsigned int numa_node)
|
|
{
|
|
struct mapped_device *md = data;
|
|
struct dm_rq_target_io *tio = blk_mq_rq_to_pdu(rq);
|
|
|
|
/*
|
|
* Must initialize md member of tio, otherwise it won't
|
|
* be available in dm_mq_queue_rq.
|
|
*/
|
|
tio->md = md;
|
|
|
|
if (md->init_tio_pdu) {
|
|
/* target-specific per-io data is immediately after the tio */
|
|
tio->info.ptr = tio + 1;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int dm_mq_queue_rq(struct blk_mq_hw_ctx *hctx,
|
|
const struct blk_mq_queue_data *bd)
|
|
{
|
|
struct request *rq = bd->rq;
|
|
struct dm_rq_target_io *tio = blk_mq_rq_to_pdu(rq);
|
|
struct mapped_device *md = tio->md;
|
|
struct dm_target *ti = md->immutable_target;
|
|
|
|
if (unlikely(!ti)) {
|
|
int srcu_idx;
|
|
struct dm_table *map = dm_get_live_table(md, &srcu_idx);
|
|
|
|
ti = dm_table_find_target(map, 0);
|
|
dm_put_live_table(md, srcu_idx);
|
|
}
|
|
|
|
/*
|
|
* On suspend dm_stop_queue() handles stopping the blk-mq
|
|
* request_queue BUT: even though the hw_queues are marked
|
|
* BLK_MQ_S_STOPPED at that point there is still a race that
|
|
* is allowing block/blk-mq.c to call ->queue_rq against a
|
|
* hctx that it really shouldn't. The following check guards
|
|
* against this rarity (albeit _not_ race-free).
|
|
*/
|
|
if (unlikely(test_bit(BLK_MQ_S_STOPPED, &hctx->state)))
|
|
return BLK_MQ_RQ_QUEUE_BUSY;
|
|
|
|
if (ti->type->busy && ti->type->busy(ti))
|
|
return BLK_MQ_RQ_QUEUE_BUSY;
|
|
|
|
dm_start_request(md, rq);
|
|
|
|
/* Init tio using md established in .init_request */
|
|
init_tio(tio, rq, md);
|
|
|
|
/*
|
|
* Establish tio->ti before calling map_request().
|
|
*/
|
|
tio->ti = ti;
|
|
|
|
/* Direct call is fine since .queue_rq allows allocations */
|
|
if (map_request(tio) == DM_MAPIO_REQUEUE) {
|
|
/* Undo dm_start_request() before requeuing */
|
|
rq_end_stats(md, rq);
|
|
rq_completed(md, rq_data_dir(rq), false);
|
|
return BLK_MQ_RQ_QUEUE_BUSY;
|
|
}
|
|
|
|
return BLK_MQ_RQ_QUEUE_OK;
|
|
}
|
|
|
|
static struct blk_mq_ops dm_mq_ops = {
|
|
.queue_rq = dm_mq_queue_rq,
|
|
.complete = dm_softirq_done,
|
|
.init_request = dm_mq_init_request,
|
|
};
|
|
|
|
int dm_mq_init_request_queue(struct mapped_device *md, struct dm_table *t)
|
|
{
|
|
struct request_queue *q;
|
|
struct dm_target *immutable_tgt;
|
|
int err;
|
|
|
|
if (!dm_table_all_blk_mq_devices(t)) {
|
|
DMERR("request-based dm-mq may only be stacked on blk-mq device(s)");
|
|
return -EINVAL;
|
|
}
|
|
|
|
md->tag_set = kzalloc_node(sizeof(struct blk_mq_tag_set), GFP_KERNEL, md->numa_node_id);
|
|
if (!md->tag_set)
|
|
return -ENOMEM;
|
|
|
|
md->tag_set->ops = &dm_mq_ops;
|
|
md->tag_set->queue_depth = dm_get_blk_mq_queue_depth();
|
|
md->tag_set->numa_node = md->numa_node_id;
|
|
md->tag_set->flags = BLK_MQ_F_SHOULD_MERGE | BLK_MQ_F_SG_MERGE;
|
|
md->tag_set->nr_hw_queues = dm_get_blk_mq_nr_hw_queues();
|
|
md->tag_set->driver_data = md;
|
|
|
|
md->tag_set->cmd_size = sizeof(struct dm_rq_target_io);
|
|
immutable_tgt = dm_table_get_immutable_target(t);
|
|
if (immutable_tgt && immutable_tgt->per_io_data_size) {
|
|
/* any target-specific per-io data is immediately after the tio */
|
|
md->tag_set->cmd_size += immutable_tgt->per_io_data_size;
|
|
md->init_tio_pdu = true;
|
|
}
|
|
|
|
err = blk_mq_alloc_tag_set(md->tag_set);
|
|
if (err)
|
|
goto out_kfree_tag_set;
|
|
|
|
q = blk_mq_init_allocated_queue(md->tag_set, md->queue);
|
|
if (IS_ERR(q)) {
|
|
err = PTR_ERR(q);
|
|
goto out_tag_set;
|
|
}
|
|
dm_init_md_queue(md);
|
|
|
|
/* backfill 'mq' sysfs registration normally done in blk_register_queue */
|
|
err = blk_mq_register_dev(disk_to_dev(md->disk), q);
|
|
if (err)
|
|
goto out_cleanup_queue;
|
|
|
|
return 0;
|
|
|
|
out_cleanup_queue:
|
|
blk_cleanup_queue(q);
|
|
out_tag_set:
|
|
blk_mq_free_tag_set(md->tag_set);
|
|
out_kfree_tag_set:
|
|
kfree(md->tag_set);
|
|
md->tag_set = NULL;
|
|
|
|
return err;
|
|
}
|
|
|
|
void dm_mq_cleanup_mapped_device(struct mapped_device *md)
|
|
{
|
|
if (md->tag_set) {
|
|
blk_mq_free_tag_set(md->tag_set);
|
|
kfree(md->tag_set);
|
|
md->tag_set = NULL;
|
|
}
|
|
}
|
|
|
|
module_param(reserved_rq_based_ios, uint, S_IRUGO | S_IWUSR);
|
|
MODULE_PARM_DESC(reserved_rq_based_ios, "Reserved IOs in request-based mempools");
|
|
|
|
module_param(use_blk_mq, bool, S_IRUGO | S_IWUSR);
|
|
MODULE_PARM_DESC(use_blk_mq, "Use block multiqueue for request-based DM devices");
|
|
|
|
module_param(dm_mq_nr_hw_queues, uint, S_IRUGO | S_IWUSR);
|
|
MODULE_PARM_DESC(dm_mq_nr_hw_queues, "Number of hardware queues for request-based dm-mq devices");
|
|
|
|
module_param(dm_mq_queue_depth, uint, S_IRUGO | S_IWUSR);
|
|
MODULE_PARM_DESC(dm_mq_queue_depth, "Queue depth for request-based dm-mq devices");
|