<div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small"><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jun 15, 2015 at 11:39 AM, Johannes Bauer <span dir="ltr"><<a href="mailto:dfnsonfsduifb@gmx.de" target="_blank">dfnsonfsduifb@gmx.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi list,<br>
<br>
so I've had this idea stuck in my head for a while and am finally not<br>
intimidated enough my the dm API to actually give it a shot and play<br>
around. I'm just getting used to the DM internals so please apologize if<br>
I sound like an idiot, I'm just new to the DM.<br>
<br>
Something that I would like to implement first is a device mapper target<br>
that takes three block devices as input: Two equally sized devices (src1<br>
and src2) and a separate metadata device (meta). I want to map chunks of<br>
the src devices to bits of a bitmap in the meta device. If the bit is<br>
set in the meta device decides whether src1 and src2 is returned.<br>
<br>
Sounds pretty easy and I also got surprisingly far with my little kernel<br>
module. I've so far implemented ctr, dtr, map and status.<br></blockquote><div><br><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;display:inline">​Congratulations, you are actually a long way there.​</div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
In map() I actually do the switching operation. I've looked at how<br>
dm-linear implements this and copied a lot of information. Currently I<br>
do static switching (fixed block size, ingoring the meta device). Here<br>
are my questions:<br>
<br>
- How can I read within the kernel from the block device lc->meta->bdev?<br>
If I call "read_dev_sector" from "map" this results in a deadlock, I'm<br>
guessing this is now how it's supposed to work. The bcache module must<br>
perform something similar (because it also reads and writes metadata,<br>
only much more complex), but I'll be damned but couldn't find out where<br>
the actual reading/writing is performed in the code. What are things<br>
that I should look at?<br></blockquote><div><br><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;display:inline">​You have to allocate a bio, populate it, allocate pages for buffer, populate the bvec, and call make_request (or generic make request).  You will get the completion from the bio on the bottom half of the interrupt handler, so how much work you can do there is debatable.  You cannot start an new IO from there, which you need to.  You will probably want to start a helper thread and have the completion routine schedule itself onto your thread.  Once you are back on your thread, you can do just about anything.<br><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;display:inline">Because you need to do IO, you will not be able to do a simple bio "bounce redirect".  You will need to do the IO youself (ie, call another make request), but you can use the callers bvec for this, so there is no data copy required.  Once the request completes, you can then fin the caller.<br>​</div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
- Is the ctr callback the appropriate place to fail if a logical error<br>
occurs? For example, if two src devices of dissimilar size are passed to<br>
dmsetup?<br></blockquote><div><br><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;display:inline">​If you cannot continue because devices are not present or the right size, yes you should fail the ctr routine.<br><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;display:inline">If you want to setup /proc or other monitoring stuff, you can use the init routine, probably plus some statics, to setup "views" into your module.  If you want to support multiple instances (and you should), setup a /proc/{yourname} directory on the init and then populate it with sub-directories every time you create a device.<br>​</div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
- Is i_size_read(lc->src1dev->bdev->bd_inode) the correct way of<br>
determining the size of the underlying block device? If not, which<br>
function is?<br></blockquote><div><br><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;display:inline">​... I am happy to leave out answers that I don't know ...​</div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
- Can I safely assume the logical sector size is fixed to be 512 bytes<br>
in all cases?<br></blockquote><div><br><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;display:inline">​Probably not, but maybe.  You are in control of the hardware.​</div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
- In the dm-linear example, bio_sectors(bio) is checked. This gives, if<br>
I understand it correctly, the size in sectors of the BIO (usually this<br>
is 8). What I don't understand is in which cases this can become zero<br>
(dm-linear has a if that checks for bio_sectors(bio) != 0).<br></blockquote><div><br><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;display:inline">​.. just a sanity check.  If you get a call of zero size, it means something else is broken.​</div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
- Can I determine the size the bio in map() will have already in ctr()<br>
somehow? Can I assume it will never change if it was once determined?<br>
The reason is that for my example I need to make sure the chunk size is<br>
a integer multiple of the bio size and I would only like to check this<br>
once (in ctr) and not every time (in map).<br></blockquote><div><br><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;display:inline">​Block size will not change.  The size of requests to you is limited by the setup of ti->max_io_len.  If you don't set this with recent kernels, you will only get 4K, which is not all that efficient.  This is actually part of another big topic of "stacked limits", which someone could write a book on (and I would read it).​</div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Thank you very much for helping out a complete newbie :-)<br>
Best regards,<br>
Johannes<br>
<br>
--<br>
dm-devel mailing list<br>
<a href="mailto:dm-devel@redhat.com">dm-devel@redhat.com</a><br>
<a href="https://www.redhat.com/mailman/listinfo/dm-devel" rel="noreferrer" target="_blank">https://www.redhat.com/mailman/listinfo/dm-devel</a><br>
</blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature">Doug Dumitru<br>EasyCo LLC<br></div>
</div></div>