Skip to contentSkip to conversation

kernel panic in inode_lookup

DISCUSSION Marcos Dione 4 participants 6 messages May 30, 2002 – May 31, 2002 VFS

lore
Share & tools
lore
#0 lore raw

I'm trying to implement the ilookup function. the problem I face is
a kernel panic. after long hours of debugging, I found out that get_new_inode:871 tries to use sb->s_op->read_inode(inode);. the problem is that sb->s_op exists but all pointers are NULL. my function is the following:

struct dentry *ogt_inode_lookup (struct inode *dir, struct dentry *dentry) {
int ret;
struct inode *inode;
ino_t ino;

  printk ("looking for %s in %d\n", dentry->d_name.name, dir->i_ino);
  ret= ogt_client_call ("ILOOKUP,%d,%s\n", dir->i_ino, dentry->d_name.name);

  if (ret==200) {
    ino= ogt_client_get_ulong ();
    printk ("dir's superblock's read_inode is %p\n", dir->i_sb->s_op->read_inode);
    inode= iget (dir->i_sb, ino);
    if (inode!=NULL) {
      d_add (dentry, inode);
    } else {
      /* taken from ext2/namei.c:81 */
      printk ("%s failed\n", dentry->d_name.name);
      return ERR_PTR (-EACCES);
    }

}

  /* hook our dentry_ops */
  dentry->d_op= &ogt_dentry_ops;

return dentry;
/* ext2 does something like this */
return NULL;
}

the ogt_client_* calls are functions I define to talk to the server
(it's a network distributed filesystem). I guess the error is in the iget call. I don't know if it's right or wrong to call iget. shoul I use another way of getting a inode? should I set the i_sb member in read_inode? the printk line before calling iget tells me that i_sb is already bad. I mean, it exists, but its ops are all NULL.

any hints?

#1 lore raw
Quoted 7 lines · Marcos Dione

I'm trying to implement the ilookup function. the problem I face is
a kernel panic. after long hours of debugging, I found out that get_new_inode:871 tries to use sb->s_op->read_inode(inode);. the problem is that sb->s_op exists but all pointers are NULL. my function is the following:

[Sniped the code]

Quoted 9 lines

the ogt_client_* calls are functions I define to talk to the server
(it's a network distributed filesystem). I guess the error is in the iget call. I don't know if it's right or wrong to call iget. shoul I use another way of getting a inode? should I set the i_sb member in read_inode? the printk line before calling iget tells me that i_sb is already bad. I mean, it exists, but its ops are all NULL.

any hints?

It is'n clear to me where you get the inode number, ie. if the function you call just allocates next free number or somehow compute it from the request. Anyway, in network filesystem calls to iget DONT make much sense. iget is method for looking up inodes by some key. It goe through the inode hash and then fall back to read_inode to create it. If your inode numer happens to be a sane lookup key, you have to implement the read_inode method (it should create new inode using get_new_inode or get_empty_inode and initialize it). If your ino is just a unique key, then you know you will end up creating a new inode, so go ahead and call get_new_inode directly.

--------------------------------------------------------------------------------
- Jan Hudec `Bulb' <[email protected]>

#2 lore raw
Quoted 12 lines · Jan Hudec

On Thu, May 30, 2002 at 01:45:22PM -0300, Marcos Dione wrote:

It is'n clear to me where you get the inode number, ie. if the function you call just allocates next free number or somehow compute it from the request. Anyway, in network filesystem calls to iget DONT make much sense. iget is method for looking up inodes by some key. It goe through the inode hash and then fall back to read_inode to create it. If your inode numer happens to be a sane lookup key, you have to implement the read_inode method (it should create new inode using get_new_inode or get_empty_inode and initialize it). If your ino is just a unique key, then you know you will end up creating a new inode, so go ahead and call get_new_inode directly.

ok. first, the ino is get from the real filesystem, in the server.
second, in read_super I call new_inode. I guess its better to add some context.

I can mount my file system, and even read the root inode. I can even
list the contents of my root dir. in read_super, for returning the root inode, I call new_inode (sb), where sb is the superblock structure I'm filling. I think something must be wrong, because then inode->i_sb->s_op function pointers are all NULL ATM of calling inode_lookup. I mean, why these two line, taken from my read_super, are wrong?:

      sb->s_op= &ogt_super_operations;
      inode= new_inode (sb);

after the second call, inode->i_sb->s_op functions should be ok, but
they're NULL! the ogt_super_opertions... shit! could you believe it? it was a wrong definition of the sb's ops! shite, sometimes I hate C so much... ok, I learn.

zanx for your help, anyways.

#3 lore raw
Quoted 7 lines
      sb->s_op= &ogt_super_operations;
      inode= new_inode (sb);

after the second call, inode->i_sb->s_op functions should be ok, but
they're NULL! the ogt_super_opertions... shit! could you believe it? it was a wrong definition of the sb's ops! shite, sometimes I hate C so much... ok, I learn.

As I understand the system, all the new_inode() function does is allocate the memory out of the pages that have already been dedicated to inodes. It doesn't actually fill in the data you need. Most of the filesystems I have examined use iget() in read_super() with a known value to find the root directory, and your read_inode() function must know how to handle that special value as well as normal files. The iget() function does some extra management tasks like adding your inode into the hash tables after it has been filled in. By using iget() for everything, you can also take advantage of the hash tables to get a copy of an inode that has already been loaded into memory without the system having to call your read_inode() function again.

Basics of iget():

inode iget(sb, ino)

{
	found=search(ino);
	if(found)
		return found;
	found=new_inode();
	read_inode(found);
	return found;
}

Obviously, it's a little more complex, as well as in real C code, but that should be enough to get the idea.

Brad Boyer
[email protected]

#4 lore raw
In reply to Marcos Dione
Quoted 4 lines · Marcos Dione

return dentry;
/* ext2 does something like this */
return NULL;
}

This could be your problem. real_lookup assumes that if you return anything it is a new dentry that you found in some magical way and drops the refcount on the old dentry (which happens to be the one you are returning). If the refcount drops to zero the dentry is up for grabs at which point you've lost any sanity in the kernel's data structures.

Jan

#5 lore raw
Quoted 11 lines · Jan Harkes
Quoted 4 lines · Marcos Dione

return dentry;
/* ext2 does something like this */
return NULL;
}

This could be your problem. real_lookup assumes that if you return anything it is a new dentry that you found in some magical way and drops the refcount on the old dentry (which happens to be the one you are returning). If the refcount drops to zero the dentry is up for grabs at which point you've lost any sanity in the kernel's data structures.

zanx for the hint. and don't cc: me, I'm subscribed to the list.