Re: scsi adapter module over block device - need help

2012-10-17 Thread Greg Freemyer
Sorry,  dropped kernelnewbies somehow.

Please keep them in cc.  Your message and my reply below.

On Wed, Oct 17, 2012 at 6:46 PM, Greg Freemyer  wrote:
> On Wed, Oct 17, 2012 at 12:06 PM, Dmitry Filippov  
> wrote:
>> Greg,
>>
>> thank you for reply!
>> Yeah there is a kind of analogy to network stack in scsi stack.
>>
>> the are 3 layers in scsi stack:
>> upper layer (sg, sd, sr, st drivers) that implements high level abstraction
>> middle layer which routes scsi commnads/requests to low level drivers
>> low layer - actually host adapters. low level drivers which registers
>> within scsi stack, gets scsi commands from mid layer and perform
>> actual actions on device.
>>
>> so from file system any syscall reaches vfs layer first, and then to
>> upper scsi layer.
>>
>> thanks,
>> Dmitry
>
> vfs actually talks to the block i/o layer which may or may not include
> multiple device mapper layers.  Device mapper (DM) can of course
> implement logical volumes and/or some raid levels by combining
> multiple block devices.  It can also do block translations etc.
>
> (There is also the MD layer, but I don't really know how it fits in.
> DM is a newer subsystem and has a cleaner architecture I believe, but
> it doesn't offer as many raid levels as MD does.  You can have both DM
> and MD in use together if appropriate.)
>
> At the bottom of the stack there is also a scsi-physical layer: much
> like IP can travel over multiple physical media (Ethernet, T1/E1,
> etc.) scsi can traverse lots of different physical media.
>
> And then in some cases there is a translation layer below that.  SAT
> (SCSI / ATA Translation) is the best known and typically implemented
> in external USB carriers.
>
> So it's more like:
>
> syscall ->
> vfs ->
> (block layer <-> device mapper <-> MD) ->
> scsi upper layer ->
> scsi mid layer ->
> scsi low layer ->
> scsi physical   (eg. Parallel, SAS, USB) ->
> translation (eg. SAT)
>
> Notice how I showed the block layer, device mapper, and MD on one
> line.  That's because they really interact a lot and potentially have
> multiple layers of DM / MD translations.
>
> Also, I don't show libata in the above stack.  If you want to talk to
> a SATA drive, then you'll want to understand how it fits in.
>
> (If you don't know, libata is NOT a full fledged block driver.  It was
> shoe horned into the above SCSI stack.  That's why it's /dev/sdx now
> and not /dev/hda like it was 10 years ago.  The /dev/hda (legacy IDE)
> block driver stack is still in kernel, but it no longer accepts major
> updates. (deprecated? I think that's right.))
>
> But all that's the linux kernel structure.
>
> There are also scsi layers defined in the SCSI specs.  If you're going
> to work with SCSI you will want to be somewhat familiar with the
> specs.  t10 is the SCSI standards body.  Take a look a this
> architectural chart:
>
> http://www.t10.org/scsi-3.htm
>
> Note that it is the architecture of the specs, and not necessarily the
> architecture of kernel.
>
> I think libata fits into that architecture just below the SAM level,
> so it is a sibling of parallel SCSI, SAS, FC, iSCSI, USB, etc.
>
> Again, that is not really the optimal way for libata to work, but it
> prevents having to write unique upper layers for libata.  libata has
> been around as long as the 2.6 kernel at least (it was in 2.4 too, but
> was less important).
>
> It has been a goal of the libata developers to become a full fledged
> block driver for all these years, but I don't think they've made much
> progress on that.  I suspect it's too much work for little gain.
>
> ==
> Now with that basic info in place, back to your original desire:
>
> "I want to write module that implements SCSI-disk logic, keeping its
> data on block device."
>
> To me, that sounds like libata.  Libata is a kernel module that sits
> under the SCSI upper/mid layers and translates scsi commands to ATA
> commands and then sends those commands to a ATA controller (both SATA
> and PATA controllers are supported).
>
> But, it sounds like you want to be able to issue your writes as SCSI
> requests?  Is that right?  If so, that almost sounds like iSCSI with a
> built-in loopback network.
>
> Maybe you can elaborate using more specific terminology?
>
> FYI: If I were you, I would want to create a new DM (device mapper)
> module that could tie in directly at the block layer of the linux
> kernel.  It would be able to accept block i/o commands from the block
> layer, manipulate those commands, then re-issue them to the block
> layer so they could be pushed down into the actual block stack (ie.
> SCSI).
>
> All the infrastructure is already in place to do that.
>
> Thus, while you say you want to write a SCSI module, I think a Device
> Mapper module makes far more sense to do what you want.  And you're
> not forcing your concept on to the kernel.  Instead your taking the
> kernel's design and leveraging it.
>
> Hope that helps
> Greg

___
Kern

Re: scsi adapter module over block device - need help

2012-10-06 Thread Greg Freemyer
On Sat, Oct 6, 2012 at 9:28 AM, Dmitry Filippov  wrote:
> Hi all,
>
> i'm just learning kernel and not experienced in writing code for it.
> I'm going to write kernel module in studying purposes and i hope
> someone from you could help me with it and in best case guide me
> through overall process.
>
> I want to write module that implements SCSI-disk logic, keeping its
> data on block device. For example partition of existing disk. So i
> want to pass the name of block device as parameter to my module while
> loading to kernel.
>
> So it will be some kind of virtual(pseudo) scsi device that appears in
> /dev as scsi disk and in fact some block device as backend. I want it
> to be as simple as possible... keeping just essential parts... and it
> is not intended to be some kind of production driver... i want it to
> be just as simple as sbull from LDD)))
>
> As from my point of view there are 2 major parts, with which i'm
> completely not confident and doesn't know from where to start...
> 1. scsi subsystem... so how to write my module to interact with scsi
> subsystem in this case and to not reinvent the wheel. using scsi
> kernel API as much as possible.
> i have found interesting thing in kernel source scsi_debug module...
> which represent scsi disk and have ram as backend (so some kind of
> sbull but with scsi). However i got overwhelmed with its code. It is
> very difficult for me to sort out with it by my own... maybe someone
> can help?
>
> 2. module code interaction with existing block device... that is i
> completely don't understand how to achieve. ok.. i have device name in
> kernel space... whats then? how i can access this device?
> so how i can write some adapter for existing device and transit some
> writes/reads and other fops from my device to existing... I saw same
> questions on forums... and the only answer is to use sys_write... or
> vfs_write... to existing block device node... if it is most
> simple/correct way?
>
> i hope someone could help me sort out in those things eventually.
> Really need your help!
>
> thanks in advance,
> -Dmitry Filippov

Dmitry,

I might be able to give some high-level guidance.

The first thing you need to know is the "network stack".

I'm assuming you know ethernet => IP => TCP type of levels for networking.

Can you provide a similar set of layers for scsi.  As an example USB
external drives actually fit into the SCSI stack, not the IDE or SATA
stack.  Can you list the layering starting with the filesystem?

Greg

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


scsi adapter module over block device - need help

2012-10-06 Thread Dmitry Filippov
Hi all,

i'm just learning kernel and not experienced in writing code for it.
I'm going to write kernel module in studying purposes and i hope
someone from you could help me with it and in best case guide me
through overall process.

I want to write module that implements SCSI-disk logic, keeping its
data on block device. For example partition of existing disk. So i
want to pass the name of block device as parameter to my module while
loading to kernel.

So it will be some kind of virtual(pseudo) scsi device that appears in
/dev as scsi disk and in fact some block device as backend. I want it
to be as simple as possible... keeping just essential parts... and it
is not intended to be some kind of production driver... i want it to
be just as simple as sbull from LDD)))

As from my point of view there are 2 major parts, with which i'm
completely not confident and doesn't know from where to start...
1. scsi subsystem... so how to write my module to interact with scsi
subsystem in this case and to not reinvent the wheel. using scsi
kernel API as much as possible.
i have found interesting thing in kernel source scsi_debug module...
which represent scsi disk and have ram as backend (so some kind of
sbull but with scsi). However i got overwhelmed with its code. It is
very difficult for me to sort out with it by my own... maybe someone
can help?

2. module code interaction with existing block device... that is i
completely don't understand how to achieve. ok.. i have device name in
kernel space... whats then? how i can access this device?
so how i can write some adapter for existing device and transit some
writes/reads and other fops from my device to existing... I saw same
questions on forums... and the only answer is to use sys_write... or
vfs_write... to existing block device node... if it is most
simple/correct way?

i hope someone could help me sort out in those things eventually.
Really need your help!

thanks in advance,
-Dmitry Filippov

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies