Re: Mapping of Filename to allocated blocks

2016-07-20 Thread Manoj Rao
Thanks Arshad, Luis for the response.
This project was on back burner for a while and now it's
coming back to life.

tl;dr: I'm looking for a way to tell if a given inode object
belongs to a persistent block device or not ex: a sysfs node
doesn't have a corresponding block device backing it.

I looked into the source code for hdparm implementation.
I was able to borrow a lot of it and move them in kernel (for
academic purposes only). Here's my (very limited) understanding so
far, hdparm tries to read a storage device's 'geometry' which includes
info such as cylinders, heads, sectors etc. on mechanical disks. One
of the key parameters of a storage device is the start_lba which is
basically the first block on a persistent device that contains data
from a given file. In hdparm, it is able to get this info by simply
reading from the block device's sysfs node, under,
/sys/dev/block/.../start
I intend to do something similar in the kernel by doing something
similar to when the above sysfs node is read. The implementation for
this is partition-generic.c
However, I need to run this for each and every read system call which
includes all the procfs, sysfs and other RAM fs based file reads. My
code is causing the kernel to panic at some point due to an illegal
memory access while trying to obtain the starting sector/block for the
file that's currently being read. My hunch is the crash occurs when
file being read is on a non-persistent fs such as a sysfs node
I have gotten hold of the inode structure and I'm trying to find if
a given inode is stored persistently or not and I've been unable to
find this information so far. I have all the appropriate NULL checks
and each time it crashes the accessed address points a garbage,
non-zero address. Any thoughts or inputs are highly
appreciated. Thanks.

​​
--
​Manoj​


On Wed, Apr 27, 2016 at 8:32 PM, arshad hussain 
wrote:

> On Thu, Apr 28, 2016 at 7:28 AM, Manoj Rao  wrote:
> > Hi All,
> >
> > I'm looking for a way to get a filename associated with a given physical
> > block (ideally what I'd like is a mapping of filename <=> all the
> allocated
> > blocks for this file).
>
> If you have not done already, this could be a good starting point.
> Look at FIBMAP IOCTL.
>
> Here is one usage of FIEMAP, demonstrated via hdparam.
> # hdparm --fibmap 
>
> >
> > Is there a recommended way to do this already in kernel? if not, then
> where
> > should I start looking to add changes?
>
> Not sure about what would be the Recommended method. But this could be done
> in user-space vs doing it in kernel space. For example, consider cases like
> single file restore - there will be a requirement to figure out the
> logical - physical block allocation for a file which could be achieved
> through...
> Read superblock
> Read dentry - Home into the required inode (file)
> Read inode - to figure out the location of block.
>
> Note: This is not generic - and would require changes as layout is
> different
> for filesystems.
>
> Thanks
> Arshad
>
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Mapping of Filename to allocated blocks

2016-04-28 Thread Luis de Bethencourt
On 28/04/16 04:32, arshad hussain wrote:
> On Thu, Apr 28, 2016 at 7:28 AM, Manoj Rao  wrote:
>> Hi All,
>>
>> I'm looking for a way to get a filename associated with a given physical
>> block (ideally what I'd like is a mapping of filename <=> all the allocated
>> blocks for this file).
> 
> If you have not done already, this could be a good starting point.
> Look at FIBMAP IOCTL.
> 
> Here is one usage of FIEMAP, demonstrated via hdparam.
> # hdparm --fibmap 
> 
>>
>> Is there a recommended way to do this already in kernel? if not, then where
>> should I start looking to add changes?
> 
> Not sure about what would be the Recommended method. But this could be done
> in user-space vs doing it in kernel space. For example, consider cases like
> single file restore - there will be a requirement to figure out the
> logical - physical block allocation for a file which could be achieved
> through...
> Read superblock
> Read dentry - Home into the required inode (file)
> Read inode - to figure out the location of block.
> 
> Note: This is not generic - and would require changes as layout is different
> for filesystems.
> 
> Thanks
> Arshad
> 

If you are going to create anything based on VFS (Virtual File Switch), I
recommend reading this article from LWN.

https://lwn.net/Articles/57369/

Even create a small memory-bound file system to get comfortable with the API.

If you want a version that works with current mainline, check out:
https://github.com/luisbg/toy_kernel_modules/blob/master/toyfs/toyfs.c

Sorry it doesn't have comments yet, I will be adding those very soon.

Happy hacking,
Luis 


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


Re: Mapping of Filename to allocated blocks

2016-04-27 Thread arshad hussain
On Thu, Apr 28, 2016 at 7:28 AM, Manoj Rao  wrote:
> Hi All,
>
> I'm looking for a way to get a filename associated with a given physical
> block (ideally what I'd like is a mapping of filename <=> all the allocated
> blocks for this file).

If you have not done already, this could be a good starting point.
Look at FIBMAP IOCTL.

Here is one usage of FIEMAP, demonstrated via hdparam.
# hdparm --fibmap 

>
> Is there a recommended way to do this already in kernel? if not, then where
> should I start looking to add changes?

Not sure about what would be the Recommended method. But this could be done
in user-space vs doing it in kernel space. For example, consider cases like
single file restore - there will be a requirement to figure out the
logical - physical block allocation for a file which could be achieved
through...
Read superblock
Read dentry - Home into the required inode (file)
Read inode - to figure out the location of block.

Note: This is not generic - and would require changes as layout is different
for filesystems.

Thanks
Arshad

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


Mapping of Filename to allocated blocks

2016-04-27 Thread Manoj Rao
Hi All,

I'm looking for a way to get a filename associated with a given physical
block (ideally what I'd like is a mapping of filename <=> all the allocated
blocks for this file).

Is there a recommended way to do this already in kernel? if not, then where
should I start looking to add changes?

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