{"id":18832660,"url":"https://github.com/datto/kmod-dblock","last_synced_at":"2025-04-14T04:30:39.075Z","repository":{"id":45257917,"uuid":"338459409","full_name":"datto/kmod-dblock","owner":"datto","description":"kernel module to implement the backing data source for a block device in userspace","archived":false,"fork":false,"pushed_at":"2021-12-27T13:20:06.000Z","size":57,"stargazers_count":3,"open_issues_count":1,"forks_count":3,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-27T18:21:24.573Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-2.1","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/datto.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"COPYING","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-02-12T23:42:08.000Z","updated_at":"2024-07-25T18:56:49.000Z","dependencies_parsed_at":"2022-08-27T21:00:18.778Z","dependency_job_id":null,"html_url":"https://github.com/datto/kmod-dblock","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datto%2Fkmod-dblock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datto%2Fkmod-dblock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datto%2Fkmod-dblock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datto%2Fkmod-dblock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/datto","download_url":"https://codeload.github.com/datto/kmod-dblock/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248821614,"owners_count":21166911,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-08T01:58:40.531Z","updated_at":"2025-04-14T04:30:39.041Z","avatar_url":"https://github.com/datto.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# kmod-dblock\n\nkmod-dblock is a kernel module that allows you to implement the backing data source for a block device in userspace.\n\n# building\n\nto build the kernel module you must have the kernel headers for your running kernel installed.\n\nFedora/CentOS/RHEL:\n\n```sudo yum -y install kernel-devel-$(uname -r)```\n\nDebian/Ubuntu:\n\n```sudo apt install linux-headers-$(uname -r)```\n\nRaspberry Pi OS:\n\n```sudo apt install raspberrypi-kernel-headers```\n\nonce the headers are installed, you can build the kernel module\n\n```\nmake\nsudo insmod dblock.ko\n```\n\nto build the sample ramdisk userspace implementation\n\n```\ncd sample_ramdisk\nmake\n```\n\n\n# sample program\n\nif you run the resulting binary from the build...\n\n```\nsudo ./dblock_sample_ramdisk\n```\nthe process will create a block device called `/dev/dblockramdisk` and the process will block handling requests to that block device.\n\nin another terminal you can create a file system on the block device.\n\n```\nsudo mkfs.ext4 /dev/dblockramdisk\n```\nthen you can mount it\n\n```\nmkdir mount\nsudo mount /dev/dblockramdisk mount\n```\n\nthen you can `cd mount` to use the ramdisk created by dblock.ko\n\nto cleanly exit the block device\n\nunmount the file system\n```\numount mount\n```\n\nto exit the userspace process cleanly and destroy the block device, run the userspace program with the -d parameter.\n\n```\nsudo ./dblock_sample_ramdisk -d\n```\n\nthat will destroy the block device and the dblock_sample_ramdisk process in the first terminal will exit.\n\n\n\n# how it works\n\nthe kernel module once loaded, creates a misc device called `/dev/dblockctl`.\nthis device is how userspace applications can make requests to the dblock.ko kernel module to create and destroy block devices. the kernel module supports multiple concurrent block devices.\n\nwhen the userspace program starts, it sends an ioctl to the control device with information about the size and shape of block device to make.\nthe kernel module makes the block device in the kernel, and creates a queue in its memory to hold requests.\n\nthe the userspace program makes an ioctl to the newly created block device, and it blocks waiting for something to appear on the queue.\nwhen a request comes in for the block device, the information about the request (is it a read or a write, and if it's a write, what data needs to be written) is returned to the userspace application that was blocking on the ioctl call.\n\nthe userspace application then handles the request either collecting the data for read requests or storing the data for write requests, and then calls the ioctl again with the results of the request that was handled.\n\nthe kernel module then sends the results sent from userspace to the kernel for the block device that the initial request came from and then blocks again waiting for something else to do.\n\nthis cycle continues until an ioctl is make to the control device to destroy the block device.\n\nwhen a block device is destroyed, the kernel module sends a special response to the userspace blocking ioctl saying basically there are no more requests coming and the userspace program should not call back.\n\n\n# more details\n\nit builds and runs on x86 and ARM (both 32-bit and 64-bit).\n\nit runs on Fedora 33, Ubuntu 18.04, Ubuntu 20.04, and Raspberry Pi OS.\n\nI've tested it with the 4.15 kernel and the 5.8 kernel and the 5.10 kernel.\n\nbecause of the way the sample program is written it can only handle one request at a time.\nall requests from the block device are handled roughly in the order in which they came in.\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdatto%2Fkmod-dblock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdatto%2Fkmod-dblock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdatto%2Fkmod-dblock/lists"}