Patch?: linux-2.5.33/drivers/block/loop.c update
The followingp patch is the latest version of my loop.c
updates.
This version makes device backed loop devices work even
when the bio_alloc in the IO path returns NULL (i.e., under memory pressure). When a loop device is configured, a page (or q->hardsect_size if that is bigger) is preallocated for use in case of memory allocation failure. If memory allocation failure occurs in the IO path, the bio is submitted using this reservd area, one page at a time. The advantage of this approach is that is possible to allow bio producers to submit very big transfers without needing to reserve so much memory for backup.
Because /dev/loop now can handle the memory allocation
failures, I have changed the memory allocation in the IO path to be non-blocking.
I have tested this with the bio allocation code changed
to always fail. I tested the following cases:
plain encrypted
device X
file on ext2 X X
file on tmpfs X X
I have not yet tested it on an encrypted device because
Linux 2.5.32 and .33 cause the computers' keyboard not work on every machine that I've tried them on, and the arrangement that I use for testing an encrypted device requires me to enter a password on a keyboard before networking has come up. I may fiddling with setting up anotehr way to test that case, although I'd rather devote that energy to tracking down the keyboard problem.
The other new changes are basically just clean ups. There are now separate q->make_request_fn and
loop_handler functions for file-backed and device-backed cases. Besides pulling somre branches and subroutine calls out of the IO path, this also makes it easier to read.
The variables that were previously named "bio" have been
renamed to "loop_bio" if they are used only as a bio for /dev/loop/nnn, or "dev_bio" when they are used only as a bio for the underlying hardware device that the loop is mounted on. In the few cases where a bio variable could be used either way under different circumstances, its name remains "bio". I think this makes the code much easier to undertstand and maintain.
Signature · 4 lines
Adam J. Richter __ ______________ 575 Oroville Road [email protected] \ / Milpitas, California 95035 +1 408 309-6081 | g g d r a s i l United States of America "Free Software For The Rest Of Us."
include/linux/loop.h +34 -19
@@ -1,8 +1,3 @@ -#ifndef _LINUX_LOOP_H -#define _LINUX_LOOP_H - -#include <linux/kdev_t.h> -/* * include/linux/loop.h *
@@ -12,11 +7,20 @@* permitted under the GNU General Public License. */ +#ifndef _LINUX_LOOP_H +#define _LINUX_LOOP_H + +#include <linux/kdev_t.h> +#define LO_NAME_SIZE 64#define LO_KEY_SIZE 32#ifdef __KERNEL__ +#include <linux/bio.h> +#include <linux/blkdev.h> +#include <linux/completion.h> +/* Possible states of device */ enum { Lo_unbound,
@@ -24,13 +28,27 @@ Lo_rundown, }; +/* IV calculation related constants */ +#define LO_IV_MODE_DEFAULT 0/* old logical block size based mode */ +#define LO_IV_MODE_SECTOR 1/* calculate IV based on relative +512 byte sectors */ +#define LO_IV_SECTOR_BITS 9 +#define LO_IV_SECTOR_SIZE (1 << LO_IV_SECTOR_BITS) + +struct loop_device ; + +typedef int (*loop_file_xfer_t )(struct loop_device *lo,int rw, +void *data,int len,loff_t pos); +struct loop_device { +request_queue_t queue;int lo_number; -int lo_refcnt; -int lo_offset; +loff_t lo_offset; +sector_t lo_sector_offset;/* lo_offset / 512 */ int lo_encrypt_type;int lo_encrypt_key_size; -int lo_flags; +void (*thread_handle_bio)(struct loop_device *lo, +struct bio *bio);int (*transfer)(struct loop_device *,int cmd,char *raw_buf,char *loop_buf,int size,int real_block);
@@ -51,11 +69,14 @@spinlock_t lo_lock;struct bio *lo_bio;struct bio *lo_biotail; -int lo_state; -struct semaphore lo_sem; -struct semaphore lo_ctl_mutex; +struct completion lo_thread_exited;struct semaphore lo_bh_mutex;atomic_t lo_pending; +int lo_iv_mode; +struct list_head lo_list; +loop_file_xfer_t lo_file_io[2 ];/* [0]=read and [1]=write */ +struct semaphore lo_backup_sem; +struct bio lo_backup_bio; }; typedef int (* transfer_proc_t)(struct loop_device *, int cmd,
@@ -64,13 +85,6 @@#endif /* __KERNEL__ */ -/* -* Loop flags -*/ -#define LO_FLAGS_DO_BMAP 1 -#define LO_FLAGS_READ_ONLY 2 -#define LO_FLAGS_BH_REMAP 4 -/* * Note that this structure gets the wrong offsets when directly used * from a glibc program, because glibc has a 32bit dev_t.
@@ -94,7 +108,7 @@int lo_offset;int lo_encrypt_type;int lo_encrypt_key_size;/* ioctl w/o */ -int lo_flags;/* ioctl r/o */ +int lo_flags;/* no longer used, formerly r/o */ char lo_name[LO_NAME_SIZE ];unsigned char lo_encrypt_key[LO_KEY_SIZE ];/* ioctl w/o */ unsigned long lo_init[2 ];
@@ -114,6 +128,7 @@#define LO_CRYPT_IDEA 6#define LO_CRYPT_DUMMY 9#define LO_CRYPT_SKIPJACK 10 +#define LO_CRYPT_CRYPTOAPI 18/* international crypto patch */ #define MAX_LO_CRYPT 20#ifdef __KERNEL__
drivers/block/loop.c +716 -529
1,689 lines not on this page · raw message