2003-07-22 21:02:53

by Christophe Saout

[permalink] [raw]
Subject: [RFC] File backed target for device-mapper

Hi!

I just wrote a dm target uses a file as backend instead of another block
device.

It's heavily based on the linux 2.5 loop device (so it uses the inode
operation sendfile for read operations and the address space operations
prepare_write and commit_write for write operations).

A dm device can be created with the target options "filename offset"
where offset is given in bytes.

--
Christophe Saout <[email protected]>
Please avoid sending me Word or PowerPoint attachments.
See http://www.fsf.org/philosophy/no-word-attachments.html


Attachments:
dm-file.c (10.65 kB)

2003-07-22 21:24:12

by Christophe Saout

[permalink] [raw]
Subject: Re: [RFC] File backed target for device-mapper

Am Di, 2003-07-22 um 23.17 schrieb Christophe Saout:

> I just wrote a dm target uses a file as backend instead of another block
> device.
>
> It's heavily based on the linux 2.5 loop device (so it uses the inode
> operation sendfile for read operations and the address space operations
> prepare_write and commit_write for write operations).

Umm... lalala... (a cleanup and a *fix*) :D

--- dm-file.c.orig 2003-07-22 23:36:57.639746368 +0200
+++ dm-file.c 2003-07-22 23:37:26.203404032 +0200
@@ -87,17 +87,16 @@
{
char *src;
char *dst = (char *)desc->buf;
- unsigned long count = desc->count;

- if (size > count)
- size = count;
+ if (size > desc->count)
+ size = desc->count;

src = kmap(page) + offset;
if (src != dst) /* FIXME: is src == dst possible? */
memcpy(dst, src, size);
kunmap(page);

- desc->count = count - size;
+ desc->count -= size;
desc->written += size;
(char *)desc->buf += size;

@@ -127,8 +126,6 @@

if (r < 0)
break;
-
- pos += bv->bv_len;
}

return 0;


--
Christophe Saout <[email protected]>
Please avoid sending me Word or PowerPoint attachments.
See http://www.fsf.org/philosophy/no-word-attachments.html

2003-07-22 21:43:45

by Alasdair G Kergon

[permalink] [raw]
Subject: Re: [dm-devel] [RFC] File backed target for device-mapper

On Tue, Jul 22, 2003 at 11:17:39PM +0200, Christophe Saout wrote:
> I just wrote a dm target uses a file as backend instead of another block
> device.

Another suggestion:

A target that always returns a block of zeros [or more generally,
some other repeating pattern e.g. if the read goes beyond the end
of your file - required to be multiple of sector size - it loops
round to the beginning; writes get dropped]

So you can easily create, for example a /dev/zero-like block device of
arbitrary size, which might be useful for replacing a lost disk that
contained a stripe if you want to read off the data from the other
stripes at correct offsets.

Alasdair
--
[email protected]