BLOCK DEVICES. Philipp Dollst

Similar documents
Lecture on Storage Systems

What is a Linux Device Driver? Kevin Dankwardt, Ph.D. VP Technology Open Source Careers

Block device drivers. Block device drivers. Thomas Petazzoni Free Electrons

Linux storage system basics

Introduction to Linux Block Drivers. Hao-Ran Liu

- Knowledge of basic computer architecture and organization, ECE 445

Linux storage system basics

Linux device Drivers Block drivers. Jernej Vičič Linux device Drivers Block drivers

Character Device Drivers

Linux drivers - Exercise

Compression and Replication of Device Files using Deduplication Technique

Linux BIO and Device Mapper

I/O Management Intro. Chapter 5

Device Drivers. CS449 Fall 2017

I/O Devices. I/O Management Intro. Sample Data Rates. I/O Device Handling. Categories of I/O Devices (by usage)

Linux Kernel Modules & Device Drivers April 9, 2012

CPSC 8220 FINAL EXAM, SPRING 2016

CSC 306 Assignment 4: A Floppy Disk Dumper

CS 4284 Systems Capstone

LOADING BLOCK DRIVERS

CS5460/6460: Operating Systems. Lecture 24: Device drivers. Anton Burtsev April, 2014

Designing and developing device drivers. Coding drivers

CS 378 (Spring 2003)

The Journey of an I/O request through the Block Layer

Linux SMR Support Status

Linux Device Drivers. 3. Char Drivers. 1. Introduction 2. Kernel Modules 3. Char Drivers 4. Advanced Char Drivers 5. Interrupts

Virtual File System (VFS) Implementation in Linux. Tushar B. Kute,

DEEP COMPRESSION. Cloop is a kernel block device. Block device compression with the cloop module COVER STORY

File. File System Implementation. File Metadata. File System Implementation. Direct Memory Access Cont. Hardware background: Direct Memory Access

Introduction to Operating Systems. Device Drivers. John Franco. Dept. of Electrical Engineering and Computing Systems University of Cincinnati

Linux Device Drivers

Topics Not Covered. Debugging (includes kmemcheck, kmemleak) Statistics Tracing UP UMA CPU and Memory Hotplug Lockdep Failslab

we are here I/O & Storage Layers Recall: C Low level I/O Recall: C Low Level Operations CS162 Operating Systems and Systems Programming Lecture 18

NPTEL Course Jan K. Gopinath Indian Institute of Science

CROWDMARK. Examination Midterm. Spring 2017 CS 350. Closed Book. Page 1 of 30. University of Waterloo CS350 Midterm Examination.

NPTEL Course Jan K. Gopinath Indian Institute of Science

Introduction Reading Writing scull. Linux Device Drivers - char driver

Operating System: Chap13 I/O Systems. National Tsing-Hua University 2016, Fall Semester

ECEN 449 Microprocessor System Design. Hardware-Software Communication. Texas A&M University

File. File System Implementation. Operations. Permissions and Data Layout. Storing and Accessing File Data. Opening a File

Practical Techniques for Purging Deleted Data Using Liveness Information

Unix (Linux) Device Drivers

Introduction to Device Drivers Part-1

Linux Device Drivers. 3. Char Drivers cont. 3. Char Drivers. 1. Introduction 2. Kernel Modules 3. Char Drivers 4. Advanced Char Drivers 5.

BASIC COMPUTER ORGANIZATION. Operating System Concepts 8 th Edition

Accelerating Storage with NVM Express SSDs and P2PDMA Stephen Bates, PhD Chief Technology Officer

Practical Techniques for Eliminating Storage of Deleted Data

250P: Computer Systems Architecture. Lecture 14: Synchronization. Anton Burtsev March, 2019

Spring 2017 :: CSE 506. Device Programming. Nima Honarmand

we are here Page 1 Recall: How do we Hide I/O Latency? I/O & Storage Layers Recall: C Low level I/O

l12 handout.txt l12 handout.txt Printed by Michael Walfish Feb 24, 11 12:57 Page 1/5 Feb 24, 11 12:57 Page 2/5

-Device. -Physical or virtual thing that does something -Software + hardware to operate a device (Controller runs port, Bus, device)

I/O Management Software. Chapter 5

Scrivere device driver su Linux. Better Embedded 2012 Andrea Righi

Compiling Your Code and Running the Tests

Managing Lustre TM Data Striping

bytes per disk block (a block is usually called sector in the disk drive literature), sectors in each track, read/write heads, and cylinders (tracks).

CSE 120 Principles of Operating Systems

I/O Management Intro. Chapter 5

MP3: VIRTUAL MEMORY PAGE FAULT MEASUREMENT

Design Of Linux USB Device Driver For LPC2148 Based Data Acquisition System Including GSM.

Operating Systems 2010/2011

Input Output (IO) Management

Kernel Korner. SG Lists. DMA makes I/O go faster by letting devices read and write memory without bothering the CPU. by James Bottomley

a data type is Types

Chapter 5 Input/Output

memory management Vaibhav Bajpai

CS 471 Operating Systems. Yue Cheng. George Mason University Fall 2017

Emulation 2. G. Lettieri. 15 Oct. 2014

CS 140 Project 4 File Systems Review Session

IRON FOR JFFS2. Raja Ram Yadhav Ramakrishnan, Abhinav Kumar. { rramakrishn2, ABSTRACT INTRODUCTION

Flash Drive Emulation

Chapter-6. SUBJECT:- Operating System TOPICS:- I/O Management. Created by : - Sanjay Patel

Linux Kernel Development (LKD)

CSE380 - Operating Systems. Communicating with Devices

Final Step #7. Memory mapping For Sunday 15/05 23h59

/* $Id: HGSMIBase.cpp $ */ * VirtualBox Video driver, common code - HGSMI initialisation and helper * functions. */

Linux Kernel Development (LKD)

I/O MANAGEMENT CATEGORIES OF I/O DEVICES 1. Slide 1. Slide 3. Controller: Three classes of devices (by usage):

Ausgewählte Betriebssysteme - Mark Russinovich & David Solomon (used with permission of authors)

SpiNNaker Application Programming Interface (API)

Linux Device Drivers 2nd Edition

Implementation and Evaluation of the Synchronization Protocol Immediate Priority Ceiling in PREEMPT-RT Linux

Quiz 12.1: Paging. Goals for Today. Quiz 12.1: Paging. Page 1. CS162 Operating Systems and Systems Programming Lecture 12.

CMPS 105 Systems Programming. Prof. Darrell Long E2.371

Module 12: I/O Systems

I/O Management Software. Chapter 5

CS 453: Operating Systems Programming Project 5 (100 points) Linux Device Driver

Confessions of a security hardware driver maintainer

USB. Development of a USB device driver working on Linux and Control Interface. Takeshi Fukutani, Shoji Kodani and Tomokazu Takahashi

PDF Document structure, that need for managing of PDF file. It uses in all functions from EMF2PDF SDK.

Final Exam Preparation Questions

ECE 598 Advanced Operating Systems Lecture 18

I/O Handling. ECE 650 Systems Programming & Engineering Duke University, Spring Based on Operating Systems Concepts, Silberschatz Chapter 13

Chapter 7 File Operations

OPERATING SYSTEMS CS3502 Spring Input/Output System Chapter 9

Disks and I/O Hakan Uraz - File Organization 1

Quiz 12.1: Paging" Quiz 12.1: Paging" Goals for Today" Page 1. CS162 Operating Systems and Systems Programming Lecture 12.

BSNL TTA Question Paper-Computers Specialization 2007

Block Device Driver. Pradipta De

Transcription:

BLOCK DEVICES Philipp Dollst

BASICS

A block driver provides access to devices that transfer randomly accessible data in fixed-size blocks disk drives, primarily. The Linux kernel sees block devices a being fundamentally different from char devices; as a result, block drivers have a distinct interface and their own particular challenges. O Reilly Linux Device Drivers, 3rd Edition PHILIPP DOLLST BLOCK DRIVERS 20.01.2015 3

DATA STRUCTURES MY_BLK_DEV GENDISC BLOCK_DEVICE_OPERATI ONS REQUEST_QUEUE REQUEST BIO PHILIPP DOLLST BLOCK DRIVERS 20.01.2015 4

REGISTRATION

BLOCK DRIVER REGISTRATION <linux/fs.h> /* * major: major number of the device, if 0 is passed into register_blkdev * new major number will be allocated * name: associated device name (e.g. shown in /proc/devices) */ int register_blkdev(unsigned int major, const char *name); void unregister_blkdev(unsigned int major, const char *name); PHILIPP DOLLST BLOCK DRIVERS 20.01.2015 6

THAT S IT?

<LINUX/GENHD.BLK> MY_BLK_DEV GENDISC BLOCK_DEVICE_OPERATI ONS REQUEST_QUEUE REQUEST BIO PHILIPP DOLLST BLOCK DRIVERS 20.01.2015 8

GENDISK my_blk_dev.mbd = alloc_disk(minor); if (! my_blk_dev.mbd) { /* * error handling goes here */ } my_blk_dev.mbd->major = major; my_blk_dev.mbd->first_minor = RB_FIRST_MINOR; my_blk_dev.mbd->fops = &mbd_fops; my_blk_dev.mbd->private_data = &mbd_dev; my_blk_dev.mbd->queue = mbd_dev.mbd_queue; set_capacity(my_blk_dev.mbd, nsectors*(hard_sector_size/kernel_sector_size)); add_disk(my_blk_dev.mbd); PHILIPP DOLLST BLOCK DRIVERS 20.01.2015 9

OPERATIONS

<LINUX/BLKDEV.H> MY_BLK_DEV GENDISC BLOCK_DEVICE_OPERAT IONS REQUEST_QUEUE REQUEST BIO PHILIPP DOLLST BLOCK DRIVERS 20.01.2015 11

BLOCK_DEVICE_OPERATIONS FILE_OPERATIONS

BLOCK DRIVER OPERATIONS <LINUX/FS.H> struct block_device_operations { int (*open) (struct block_device *, fmode_t); void (*release) (struct gendisk *, fmode_t); //implements ioctl system call int (*ioctl) (struct block_device *, fmode_t, unsigned, unsigned long); //get geometry of the device int (*getgeo)(struct block_device *, struct hd_geometry *); struct module *owner; }; PHILIPP DOLLST BLOCK DRIVERS 20.01.2015 13

IOCTL <DRIVERS/BLOCK/IOCTL.C> / Today mainly provides the devices geometry / Amount of heads, cylinders, sectors, starting point / Necessary for e.g. fdisk to work properly PHILIPP DOLLST BLOCK DRIVERS 20.01.2015 14

REQUEST PROCESSING

READ/WRITE REQUEST

<LINUX/BLKDEV.H> MY_BLK_DEV GENDISC BLOCK_DEVICE_OPERATI ONS REQUEST_QUEUE REQUEST BIO PHILIPP DOLLST BLOCK DRIVERS 20.01.2015 17

REQUEST QUEUE SET IT UP <linux/blkdev.h> /* * request: request function * lock: spinlock */ //request_queue_t is used to manage request queues request_queue_t *blk_init_queue(request_fn_proc *request, spinlock_t *lock); void blk_cleanup_queue(request_queue_t *); struct request *blk_fetch_request(request_queue_t *queue); /* * blk_dequeue_request and blk_requeue_request allow you to remove and add * back requests from/to the queue */ void blk_dequeue_request(struct request *req); void blk_requeue_request(request_queue_t *queue, struct request *req); void blk_stop_queue(request_queue_t *queue); void blk_start_queue(request_queue_t *queue); PHILIPP DOLLST BLOCK DRIVERS 20.01.2015 18

REQUEST QUEUE SKY ISN T THE LIMIT <linux/blkdev.h> /* * DMA: Direct Memory Access bypassing the CPU * dma_addr: highest physical address to which a device can perform DMA * This information is needed by the kernel to be able to create a * bounce buffer if necessary * Those operations are way more expensive in terms of performance */ void blk_queue_bounce_limit(request_queue_t *queue, u64 dma_addr); PHILIPP DOLLST BLOCK DRIVERS 20.01.2015 19

REQUEST QUEUE THE END <linux/blkdev.h> /* * return: -true all sectors have been transferred and request is completed * -false still pending */ bool blk_end_request_cur(struct request *req, int error); PHILIPP DOLLST BLOCK DRIVERS 20.01.2015 20

REQUEST METHOD DO IT <linux/blkdev.h> void request(request_queue_t *queue); PHILIPP DOLLST BLOCK DRIVERS 20.01.2015 21

<LINUX/BLKDEV.H> MY_BLK_DEV GENDISC BLOCK_DEVICE_OPERATI ONS REQUEST_QUEUE REQUEST BIO PHILIPP DOLLST BLOCK DRIVERS 20.01.2015 22

REQUEST SET IT UP <linux/blkdev.h> /* * sector: index of the sector which represents the starting point of our * requests operation * nr_sectors: number of sectors to be transferred * *buffer: pointer to the buffer representing the data source or target * rq_data_dir: determines between read and write operations, returns * - zero for read * - non zero for for write */ sector_t sector; unsigned long nr_sectors; char *buffer; rq_data_dir(struct request *req); PHILIPP DOLLST BLOCK DRIVERS 20.01.2015 23

<LINUX/BIO.H> MY_BLK_DEV GENDISC BLOCK_DEVICE_OPERATI ONS REQUEST_QUEUE REQUEST BIO PHILIPP DOLLST BLOCK DRIVERS 20.01.2015 24

BIO = BLOCKING I/O

<LINUX/BIO.H> / describes an blocking I/O request / several bios are merged into a request / contains (multiple) page(s) of data; each represented as bio_vec which contains the length in bytes and the offset of the buffer in the page PHILIPP DOLLST BLOCK DRIVERS 20.01.2015 26

<LINUX/BIO.H> REQUEST BIO BIO BIO BIO_VEC BIO_VEC BIO_VEC BIO_VEC BIO_VEC BIO_VEC PHILIPP DOLLST BLOCK DRIVERS 20.01.2015 27

SOURCES / O Reilly Linux Device Drivers, 3rd Edition Jonathan Corbet, Alessandro Rubini, Greg Kroah-Hartman http://www.oreilly.com/openbook/linuxdrive3/book/ / tldp.org http://www.tldp.org/ldp/tlk/dd/drivers.html / sysplay.in (Demo) https://sysplay.in/blog/linux-device-drivers/2014/04/disk-on-ram-playing-destructively/ PHILIPP DOLLST BLOCK DRIVERS 20.01.2015 28