Linux Updates

Uncover our latest and greatest product updates
blogImage

Understanding Device Mapper and Filter Driver

Device Mapper is a virtual block device driver framework provided by Linux kernel which provides an infrastructure to filter I/O for block devices. It provides a platform for filter drivers also known as targets to map a BIO to multiple block devices, or to modify the BIO while it is in transit in kernel.Figure 1.1 shows the position of the device mapper layer in the kernel I/O architecture. It is positioned between the generic block layer and the I/O scheduler.Figure 1.1Since Device Mapper itself is a block device driver, it registers the functions to handle block I/O with the generic block layer. These functions transform the received BIOs and pass them to corresponding functions from the target device drivers for further processing. The Device Mapper block device driver exports a set of ioctl methods which are used by a userspace program dmsetup. dmsetup creates a mapping between the sectors of the virtual block device and the sectors of the real block device. When this mapping is created, a data structure (mapping device) is generated, which stores all the information about the target and the underlying block drivers. The information regarding the underlying block drivers is stored in a configuration table in the kernel memory.When the generic block layer receives a BIO for an I/O, the BIO is plugged into the request queue of the Device Mapper block driver. The Device Mapper driver now processes the BIO as follows.The BIO is cloned and the end-of-I/O completion handler for the cloned BIO is set to that of Device Mapper’s end-of-I/O handler.The targets for the BIO are looked up in the list of targets, and the cloned BIO is handed over to the appropriate target implementation.The target implementation processes the cloned BIO and modifies the data contained by the BIO.The target driver directs the BIO towards the underlying block device that was mapped by the Device Mapper layer earlier, sets an appropriate end of I/O handler for the BIO and invokes the entry method generic_make_request() for the device driver.Upon completion of the I/O request by the device driver, the cloned BIO’send-of-I/O handler invokes Device Mapper block driver’s end-of-I/O handler, which then notifies the upper layers about the completion of I/O. The above process is depicted in figure 1.2.Linux Filter DriverThis Filter Driver intends to use a design that makes inserting and removing the filter hook into the Block I/O stack. Hook can be dynamically placed and removed into the io stack of the intended block device. The hook can be placed and removed with minimal and almost zero downtime. The IOs will be suspended for a very short time while the hook is placed. The upper layers/applications are not knowledgeable of the hook and will continue performing IO as before i.e the hook is transparent to the upper layers/ applications.The hook is placed for device corresponding to the major number. This means that IO to any minor device which is a child to the hooked major number will be filtered. However IO to only the intended minor device will be recorded.Filter driver is called on every I/O operation. Such drivers are used by backup and snapshot software. The interface to the kernel module will be a character device which will facilitate various IOCTLs through which a user can control and command the kernel module. A filter driver should not affect the normal working of the existing driver stack in any major way.Following is the code snippet for the filter driver hook:void filter_hook(struct request_queue *q, struct bio *bio) { unsigned long sector; unsigned int nr_sectors; int ret = 0, first_minor = 0; if (bio_data_dir(bio) == WRITE) { nr_sectors = bio_sectors(bio); sector = bio->bi_sector; printk(KERN_INFO "Capture %llu:%llu, start %ld, len %x.", MAJOR(bio->bi_bdev->bd_dev), MINOR(bio->bi_bdev->bd_dev), sector, nr_sectors); orig_request_fn(q, bio); } //    return ret; } long filter_handle_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) { int ret = 0; struct gendisk *gd = NULL; struct block_device *bdev = NULL; orig_request_fn = NULL; bdev = bdget(MKDEV(disk_major, disk_minor)); gd = bdev->bd_disk; if (gd->queue->queue_lock) spin_lock(gd->queue->queue_lock); orig_request_fn = gd->queue->make_request_fn; //Replace the make_request_fn with custom make_request gd->queue->make_request_fn = filter_hook; if (gd->queue->queue_lock) spin_unlock(gd->queue->queue_lock); return ret; }

Aziro Marketing

EXPLORE ALL TAGS
2019 dockercon
Advanced analytics
Agentic AI
agile
AI
AI ML
AIOps
Amazon Aws
Amazon EC2
Analytics
Analytics tools
AndroidThings
Anomaly Detection
Anomaly monitor
Ansible Test Automation
apache
apache8
Apache Spark RDD
app containerization
application containerization
applications
Application Security
application testing
artificial intelligence
asynchronous replication
automate
automation
automation testing
Autonomous Storage
AWS Lambda
Aziro
Aziro Technologies
big data
Big Data Analytics
big data pipeline
Big Data QA
Big Data Tester
Big Data Testing
bitcoin
blockchain
blog
bluetooth
buildroot
business intelligence
busybox
chef
ci/cd
CI/CD security
cloud
Cloud Analytics
cloud computing
Cloud Cost Optimization
cloud devops
Cloud Infrastructure
Cloud Interoperability
Cloud Native Solution
Cloud Security
cloudstack
cloud storage
Cloud Storage Data
Cloud Storage Security
Codeless Automation
Cognitive analytics
Configuration Management
connected homes
container
Containers
container world 2019
container world conference
continuous-delivery
continuous deployment
continuous integration
Coronavirus
Covid-19
cryptocurrency
cyber security
data-analytics
data backup and recovery
datacenter
data protection
data replication
data-security
data-storage
deep learning
demo
Descriptive analytics
Descriptive analytics tools
development
devops
devops agile
devops automation
DEVOPS CERTIFICATION
devops monitoring
DevOps QA
DevOps Security
DevOps testing
DevSecOps
Digital Transformation
disaster recovery
DMA
docker
dockercon
dockercon 2019
dockercon 2019 san francisco
dockercon usa 2019
docker swarm
DRaaS
edge computing
Embedded AI
embedded-systems
end-to-end-test-automation
FaaS
finance
fintech
FIrebase
flash memory
flash memory summit
FMS2017
GDPR faqs
Glass-Box AI
golang
GraphQL
graphql vs rest
gui testing
habitat
hadoop
hardware-providers
healthcare
Heartfullness
High Performance Computing
Holistic Life
HPC
Hybrid-Cloud
hyper-converged
hyper-v
IaaS
IaaS Security
icinga
icinga for monitoring
Image Recognition 2024
infographic
InSpec
internet-of-things
investing
iot
iot application
iot testing
java 8 streams
javascript
jenkins
KubeCon
kubernetes
kubernetesday
kubernetesday bangalore
libstorage
linux
litecoin
log analytics
Log mining
Low-Code
Low-Code No-Code Platforms
Loyalty
machine-learning
Meditation
Microservices
migration
Mindfulness
ML
mobile-application-testing
mobile-automation-testing
monitoring tools
Mutli-Cloud
network
network file storage
new features
NFS
NVMe
NVMEof
NVMes
Online Education
opensource
openstack
opscode-2
OSS
others
Paas
PDLC
Positivty
predictive analytics
Predictive analytics tools
prescriptive analysis
private-cloud
product sustenance
programming language
public cloud
qa
qa automation
quality-assurance
Rapid Application Development
raspberry pi
RDMA
real time analytics
realtime analytics platforms
Real-time data analytics
Recovery
Recovery as a service
recovery as service
rsa
rsa 2019
rsa 2019 san francisco
rsac 2018
rsa conference
rsa conference 2019
rsa usa 2019
SaaS Security
san francisco
SDC India 2019
SDDC
security
Security Monitoring
Selenium Test Automation
selenium testng
serverless
Serverless Computing
Site Reliability Engineering
smart homes
smart mirror
SNIA
snia india 2019
SNIA SDC 2019
SNIA SDC INDIA
SNIA SDC USA
software
software defined storage
software-testing
software testing trends
software testing trends 2019
SRE
STaaS
storage
storage events
storage replication
Storage Trends 2018
storage virtualization
support
Synchronous Replication
technology
tech support
test-automation
Testing
testing automation tools
thought leadership articles
trends
tutorials
ui automation testing
ui testing
ui testing automation
vCenter Operations Manager
vCOPS
virtualization
VMware
vmworld
VMworld 2019
vmworld 2019 san francisco
VMworld 2019 US
vROM
Web Automation Testing
web test automation
WFH

LET'S ENGINEER

Your Next Product Breakthrough

Book a Free 30-minute Meeting with our technology experts.

Aziro has been a true engineering partner in our digital transformation journey. Their AI-native approach and deep technical expertise helped us modernize our infrastructure and accelerate product delivery without compromising quality. The collaboration has been seamless, efficient, and outcome-driven.

Customer Placeholder
CTO

Fortune 500 company