Re: help with ext3 reserved inode

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Donato,


On Mon, Jul 6, 2009 at 11:50 PM, Donato Capitella<d.capitella@xxxxxx> wrote:
> Ok, this is what I want to do.
>
> I'm developing a patch to ext3; this patch uses a queue of structures
> representing tasks to be performed and a separated kernel thread that
> reads the structures from the queue as they become available and
> performs the required task on the filesystem.
>

What kind of tasks are you referring to? Are these some kind of
administrative tasks?
Or do you mean the I/O also as such tasks?

> So, if the system crashes when there are still things to do in the
> queue, those tasks won't be accomplished. That's why I want to keep this
> queue in a reserved inode so that I can restart the tasks in case of
> system crash.
>
If the tasks include the I/O's,
Do you intend to maintain the data associated with each operation?


> Now, what am I trying to develop? Basically this function:
>
> write_to_log(my_struct *task) {
>        1. get reserved inode
>        2. append the struct pointed to by task to the reserved inode
> }
>

Neways, as far as the implementation of what you intend to do.
The crash that you are seeing is pretty much expected. Since, the
inode <3> is un-allocated and you are trying to access it.

So, here is one of the way to achieve what you are looking for.
The code is not complete... Just fews steps. And I have tried it to
keep it tightly coupled with ext3.

handle = ext3_journal_start (....);
spin_lock_prefetch(&inode_lock);

inode = alloc_inode(sb);
if (inode) {
               spin_lock(&inode_lock);
               __inode_add_to_lists(sb, NULL, inode);
               inode->i_ino = 3;
                inode->i_state = 0;
               spin_unlock(&inode_lock);
 }

ei = EXT3_I(inode);
sbi = EXT3_SB(sb);

brelse(bitmap_bh);
bitmap_bh = read_inode_bitmap(sb, group);
if (!bitmap_bh)
              goto fail;

err = ext3_journal_get_write_access(handle, bitmap_bh);
if (err)
       goto fail;

/*
 * I have hardcoded 0 in place of group as inode #3 resides in block group 0.
 * 3 signifies the inode number below.
 */

 if (!ext3_set_bit_atomic(sb_bgl_lock(sbi, 0), 3, bitmap_bh->b_data)) {

                                        BUFFER_TRACE(bitmap_bh, "call
ext3_journal_dirty_metadata");
                                        err =
ext3_journal_dirty_metadata(handle, bitmap_bh);
                                        if (err)
                                              goto fail;

fail:
All the error handling comes here.


Also, you will have to do a lot of initialization to the data members
of the inode.
Refer to ext3_new_inode( ), new_inode( ) and alloc_inode( ) for
further references.


> On Mon, 2009-07-06 at 22:47 +0530, Manish Katiyar wrote:
>> On Mon, Jul 6, 2009 at 8:45 PM, Donato Capitella<d.capitella@xxxxxx> wrote:
>>
>> [ Please keep kernelnewbies in cc while replying ]
>>
>> > Well, I tried to initialize the inode 3 with debugfs, but nothing
>> > changed. I just set the file mode and the creation but when I try to
>> > read the inode with the ext3_iget() function, somehow it fails and
>> > dereferences a NULL pointer :(
>>
>> What pointer is NULL ? ext3_iget doesn't return a NULL pointer (either
>> it returns a valid inode pointer or an errno typecasted as ptr). Where
>> is it crashing ? What are you using the reserved inode for ?
>>
>>
>> >
>> > Maybe I am missing something.
>>
>> Unless you tell us the complete picture it might be hard to identify.
>> A snippet of code would definitely help, but I am pretty sure that it
>> is because you don't have a valid inode structure on disk and you need
>> to initialize it appropriately.
>>
>> > Which fields do I need to initialize in
>> > order for this to work?
>>
>> Have you tried the same thing on ext2 first ? I would suggest doing
>> that because ext2_iget() is much simpler than ext3_iget(). While
>> setting i_mode you also need to take care that mode also consists of
>> filetype apart from permissions. You also may have to initialize
>> i_nlinks appropriately
>>
>> >Shouldn't be this hard to just read an inode...
>> It isn't but you need to create a valid inode before that.
>>
>> Thanks -
>> Manish
>>
>> >
>> > Thanks again,
>> > Donato
>> >
>> >
>> > On Sun, 2009-07-05 at 22:37 +0530, Manish Katiyar wrote:
>> >> On Sun, Jul 5, 2009 at 10:28 PM, Donato Capitella<d.capitella@xxxxxx> wrote:
>> >> > Well, as it's a reserved inode, I didn't create it. stat <3> shows that
>> >> > the inode has bad type... so this might be the problem. But how am I
>> >> > supposed to initialize the inode fields if I can't read it?
>> >>
>> >> What are you reserving it for ? Note that the reserved inodes today (2
>> >> for root) & (8 for journal commonly) both are initialized during mkfs.
>> >> You also need to do something similar. Depending on what you are using
>> >> it for you may need to initialize it properly. To do that you can do
>> >> the following :-
>> >>
>> >> a) Either write a simple C program to write the fields properly at
>> >> correct offset.
>> >> b) Hack the code of mkfs to include your inode too.
>> >> c) Use debugfs to change the contents of inode 3. This is the easiest
>> >> option but I am not sure if you can modify all the fields of the
>> >> inode, so it depends on what you need.
>> >>
>> >> Thanks -
>> >> Manish
>> >>
>> >> >
>> >> >
>> >> > On Sun, 2009-07-05 at 22:06 +0530, Manish Katiyar wrote:
>> >> >> On Sun, Jul 5, 2009 at 7:30 PM, Donato Capitella<d.capitella@xxxxxx> wrote:
>> >> >> > Hi there,
>> >> >> > I need some help with a patch to the ext3 filesystem I'm developing. I'm
>> >> >> > completelly new to kernel programming and I need to understand
>> >> >> > practically how to use one of the ext3 reserved inode for storing a log.
>> >> >> >
>> >> >> > I thought it would be just as easy as getting the inode with the
>> >> >> > ext3_iget() function, but it doesn't seem to be the case. For example,
>> >> >> > if I try to load the third reserved inode like this :
>> >> >> >
>> >> >> > inode = ext3_iget(sb, 3);
>> >> >> >
>> >> >> > ext3_iget() fails somehow and crashes the process with a NULL pointer
>> >> >> > reference. What am I missing here?
>> >> >> Have you created the inode 3 ? What entries does it have ? What does
>> >> >> "stat <3>" show from the debugfs ?
>> >> >>
>> >> >> Thanks -
>> >> >> Manish
>> >> >>
>> >> >>
>> >> >> > How do you use a reserved inode? Can
>> >> >> > anybody point to some documentation or project that uses reserved
>> >> >> > inodes?
>> >> >> >
>> >> >> > I'm really stuck :(
>> >> >> >
>> >> >> > Thanks a lot,
>> >> >> > Donato Capitella
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >> > --
>> >> >> > To unsubscribe from this list: send an email with
>> >> >> > "unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
>> >> >> > Please read the FAQ at http://kernelnewbies.org/FAQ
>> >> >> >
>> >> >> >
>> >> >>
>> >> >>
>> >> >>
>> >> >
>> >> >
>> >>
>> >>
>> >>
>> >
>> >
>>
>>
>>
>
>
> --
> To unsubscribe from this list: send an email with
> "unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
> Please read the FAQ at http://kernelnewbies.org/FAQ
>
>



-- 
Regards,
Sandeep.





 	
“By the time I realized that my father is wise, my son started
thinking that I am a fool”

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux