* get vfsmount from dentry
@ 2006-03-12 13:44 Ashish Khurange
2006-03-12 13:55 ` Al Viro
2006-03-12 19:10 ` Jamie Lokier
0 siblings, 2 replies; 13+ messages in thread
From: Ashish Khurange @ 2006-03-12 13:44 UTC (permalink / raw)
To: linux-fsdevel
Hi,
I'm trying to develop a fmon (file monitor) patch. For that I'm trying
to find complete pathname of the file/directory being changed. If you
have dentry of a file and a corresponding vfsmount struct, I can find
out its entire pathname using following code. Which works exactly the
way I want.
static char * mirror_path (struct dentry *dentry, struct vfsmount
*vfsmnt, char *buffer, int buflen)
{
char * end = buffer+buflen;
char * retval;
int namelen;
*--end = '\0';
buflen--;
if (buflen < 1)
goto Elong;
/* Get '/' right */
retval = end-1;
*retval = '/';
for (;;) {
struct dentry * parent;
if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
/* Global root? */
spin_lock(&vfsmount_lock);
if (vfsmnt->mnt_parent == vfsmnt) {
spin_unlock(&vfsmount_lock);
break;
}
dentry = vfsmnt->mnt_mountpoint;
vfsmnt = vfsmnt->mnt_parent;
spin_unlock(&vfsmount_lock);
continue;
}
parent = dentry->d_parent;
prefetch(parent);
namelen = dentry->d_name.len;
buflen -= namelen + 1;
if (buflen < 0)
goto Elong;
end -= namelen;
memcpy(end, dentry->d_name.name, namelen);
*--end = '/';
retval = end;
dentry = parent;
}
namelen = dentry->d_name.len;
buflen -= namelen;
if (buflen < 0)
goto Elong;
retval -= namelen-1; /* hit the slash */
memcpy(retval, dentry->d_name.name, namelen);
return retval;
Elong:
return NULL;
}
Now the only problem is in many functions in the filesystem code, I have
access only to the dentry and not to its vfsmount. I can do one thing I
can change the function definition and pass corresponding vfsmount as a
parameter to the function, but this will lead to lot of changes.
Is there any way by which I can found the vfsmount structure of a file
represented by dentry structure?
Regards,
- Ashish
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: get vfsmount from dentry
2006-03-12 13:44 get vfsmount from dentry Ashish Khurange
@ 2006-03-12 13:55 ` Al Viro
2006-03-12 17:20 ` Ashish Khurange
2006-03-12 19:10 ` Jamie Lokier
1 sibling, 1 reply; 13+ messages in thread
From: Al Viro @ 2006-03-12 13:55 UTC (permalink / raw)
To: Ashish Khurange; +Cc: linux-fsdevel
On Sun, Mar 12, 2006 at 07:14:27PM +0530, Ashish Khurange wrote:
> Hi,
> I'm trying to develop a fmon (file monitor) patch. For that I'm trying
> to find complete pathname of the file/directory being changed. If you
> have dentry of a file and a corresponding vfsmount struct, I can find
> out its entire pathname using following code. Which works exactly the
> way I want.
> Now the only problem is in many functions in the filesystem code, I have
> access only to the dentry and not to its vfsmount. I can do one thing I
> can change the function definition and pass corresponding vfsmount as a
> parameter to the function, but this will lead to lot of changes.
>
> Is there any way by which I can found the vfsmount structure of a file
> represented by dentry structure?
Which one?
There is no such thing as pathname of a file. It can be present in any
number of places, including 0. Moreover, the pathname that makes sense
for one process doesn't have to resolve to the same file (or even resolve
at all) for others.
So what are you really trying to achieve?
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: get vfsmount from dentry
2006-03-12 13:55 ` Al Viro
@ 2006-03-12 17:20 ` Ashish Khurange
2006-03-12 17:41 ` Al Viro
0 siblings, 1 reply; 13+ messages in thread
From: Ashish Khurange @ 2006-03-12 17:20 UTC (permalink / raw)
To: Al Viro; +Cc: linux-fsdevel
Al Viro wrote:
>Which one?
>
>
>
The name used by a process to access the file.
>There is no such thing as pathname of a file.
>
Please do not confuse me in jargon of words. I may not be clear in
terminology.
>Moreover, the pathname that makes sense
>for one process doesn't have to resolve to the same file (or even resolve
>at all) for others.
>
>
>
Yes thats it, the pathname that is used by a process to access a file, I
want to that pathname.
>So what are you really trying to achieve?
>
>
To get that pathname along with dentry of the file I need the vfsmount
of that file also.
Is there any way to get vfsmount of a file, when you have its dentry
with you.
- Ashish
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: get vfsmount from dentry
2006-03-12 17:20 ` Ashish Khurange
@ 2006-03-12 17:41 ` Al Viro
2006-03-12 18:00 ` Ashish Khurange
0 siblings, 1 reply; 13+ messages in thread
From: Al Viro @ 2006-03-12 17:41 UTC (permalink / raw)
To: Ashish Khurange; +Cc: linux-fsdevel
On Sun, Mar 12, 2006 at 10:50:51PM +0530, Ashish Khurange wrote:
> Yes thats it, the pathname that is used by a process to access a file, I
> want to that pathname.
Which process?
> >So what are you really trying to achieve?
>
> To get that pathname along with dentry of the file I need the vfsmount
> of that file also.
> Is there any way to get vfsmount of a file, when you have its dentry
> with you.
No. Simply because there may be many pathnames giving the same dentry.
mkdir /tmp/1
mkdir /tmp/2
mkdir /tmp/3
mount -t ramfs none /tmp/1
mount --bind /tmp/1 /tmp/2
mount --bind /tmp/1 /tmp/3
touch /tmp/1/foo
umount /tmp/1
Now /tmp/2/foo and /tmp/3/foo have exact same dentry. They do have different
vfsmounts. In other words, dentry alone is simply not enough to find the
pathname. Moreover, if you do
mkdir /tmp/1
mount -t ramfs none /tmp/1
exec >/tmp/1/foo
umount -l /tmp/1
echo a
you will have a written into file that has no pathname. I.e. there is no
such pathname that opening it at that point would result in that file. At all.
It's the same situation as with getting pathname by inode - there may be many
(hardlinks), there may be none (unlinked but still open).
In other words, the answer to your question above is "no, there is no way
to find vfsmount by dentry and that is in principle impossible". So unless
you can give higher-level description of what you want to get, you are
out of luck.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: get vfsmount from dentry
2006-03-12 17:41 ` Al Viro
@ 2006-03-12 18:00 ` Ashish Khurange
2006-03-12 18:23 ` Shaya Potter
2006-03-12 18:24 ` Al Viro
0 siblings, 2 replies; 13+ messages in thread
From: Ashish Khurange @ 2006-03-12 18:00 UTC (permalink / raw)
To: Al Viro; +Cc: linux-fsdevel
Al Viro wrote:
>On Sun, Mar 12, 2006 at 10:50:51PM +0530, Ashish Khurange wrote:
>
>
>
>>Yes thats it, the pathname that is used by a process to access a file, I
>>want to that pathname.
>>
>>
>
>Which process?
>
>
>
come on ...
As per my knowledge in vfs layer file is either accessed by pathname or
file structure pointer. In file struct you have both dentry of the file
and vfsmount. When a file is accessed by a name first path look up
happens and its nameidata is created which holds both dentry and
vfsmount. In may function calls only dentry is passed as an argument.
Now I want the path name of the file (forget what I want, as term
pathname is not clear between us). For some reason, I need vfsmount of
the file as well.
Regards,
- Ashish
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: get vfsmount from dentry
2006-03-12 18:00 ` Ashish Khurange
@ 2006-03-12 18:23 ` Shaya Potter
2006-03-12 18:54 ` Ashish Khurange
2006-03-12 18:24 ` Al Viro
1 sibling, 1 reply; 13+ messages in thread
From: Shaya Potter @ 2006-03-12 18:23 UTC (permalink / raw)
To: Ashish Khurange; +Cc: Al Viro, linux-fsdevel
On Sun, 2006-03-12 at 23:30 +0530, Ashish Khurange wrote:
> >
> come on ...
> As per my knowledge in vfs layer file is either accessed by pathname or
> file structure pointer. In file struct you have both dentry of the file
> and vfsmount. When a file is accessed by a name first path look up
> happens and its nameidata is created which holds both dentry and
> vfsmount. In may function calls only dentry is passed as an argument.
> Now I want the path name of the file (forget what I want, as term
> pathname is not clear between us). For some reason, I need vfsmount of
> the file as well.
you don't get it.
case a.
1. fd1 = open("/tmp/123")
2. mount bind "/tmp/456" -> "/tmp/123"
3. fd2 = open("/tmp/123")
both have the same exact "same" path, but 2 separate dentry.
case b.
1. fd1 = open("/tmp/123")
2. mount bind "/tmp/123" -> "/tmp/456"
3. fd2 = open("/tmp/456")
both have different paths, but will share the same dentry.
linux (and possibly other modern OSs) let us muck with the file system
namespace without modifying the underlying file systems.
The question is, what are you trying to do? Why can't you use a "struct
file" (which will have the relevant vfsmnt). If you can't say, then its
hard for people to help you, most people here want to solve something
"right", and without knowing the real problem don't feel its worth
giving a half ass solution.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: get vfsmount from dentry
2006-03-12 18:00 ` Ashish Khurange
2006-03-12 18:23 ` Shaya Potter
@ 2006-03-12 18:24 ` Al Viro
1 sibling, 0 replies; 13+ messages in thread
From: Al Viro @ 2006-03-12 18:24 UTC (permalink / raw)
To: Ashish Khurange; +Cc: linux-fsdevel
On Sun, Mar 12, 2006 at 11:30:49PM +0530, Ashish Khurange wrote:
> As per my knowledge in vfs layer file is either accessed by pathname or
> file structure pointer. In file struct you have both dentry of the file
> and vfsmount. When a file is accessed by a name first path look up
> happens and its nameidata is created which holds both dentry and
> vfsmount. In may function calls only dentry is passed as an argument.
> Now I want the path name of the file (forget what I want, as term
> pathname is not clear between us). For some reason, I need vfsmount of
> the file as well.
And I am telling you that dentry alone is not enough to find vfsmount.
So unless the thing you need it for can't be done in other way, you
are out of luck. See the previous mail for the reasons...
Again, if for some reason you really need to find vfsmount inside a function
that gets only dentry, you are stuck. Without knowing _why_ you need to
find it and need to do that inside such function, there's nothing I (or
anybody else) can do - as far as I know nobody here is a telepath.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: get vfsmount from dentry
2006-03-12 18:23 ` Shaya Potter
@ 2006-03-12 18:54 ` Ashish Khurange
2006-03-12 19:13 ` Al Viro
0 siblings, 1 reply; 13+ messages in thread
From: Ashish Khurange @ 2006-03-12 18:54 UTC (permalink / raw)
To: Shaya Potter; +Cc: Al Viro, linux-fsdevel
Shaya Potter wrote:
>
>The question is, what are you trying to do? Why can't you use a "struct
>file" (which will have the relevant vfsmnt). If you can't say, then its
>hard for people to help you, most people here want to solve something
>"right", and without knowing the real problem don't feel its worth
>giving a half ass solution.
>
>
>
I'm trying to build file monitor patch. I want to detect all the changes
happening to file system. For this I need to insert my code in various
functions in fs/open.c, fs/ nami.c.
Functions like vfs_mkdir, vfs_rmdir, notify_change, sys_write etc.
Whenever a change to file system happens I want to track that change
with the name of of the file and the change happened to it.
The function which I send in my previous mail can be used to get the
full pathname of the file being changed (pathname : lets say the name
with which file is accessed). Now for this function I need both dentry
and vfsmount struct of the file.
In few functions (like sys_fchmod) I have file struct as an argument,
which provides me both vfsmount and dentry, hence I can find out
pathname of the file being changed.
Where as in few functions (like vfs_mkdir) I have only dentry and inode
of the directory, which are not sufficient to find the pathname.
I hope I am clear now.
- Ashish
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: get vfsmount from dentry
2006-03-12 13:44 get vfsmount from dentry Ashish Khurange
2006-03-12 13:55 ` Al Viro
@ 2006-03-12 19:10 ` Jamie Lokier
1 sibling, 0 replies; 13+ messages in thread
From: Jamie Lokier @ 2006-03-12 19:10 UTC (permalink / raw)
To: Ashish Khurange; +Cc: linux-fsdevel
Ashish Khurange wrote:
> Is there any way by which I can found the vfsmount structure of a file
> represented by dentry structure?
No, it's not possible, because one dentry can refer to multiple paths
which have different vfsmount structures.
-- Jamie
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: get vfsmount from dentry
2006-03-12 18:54 ` Ashish Khurange
@ 2006-03-12 19:13 ` Al Viro
2006-03-12 20:34 ` Ashish Khurange
0 siblings, 1 reply; 13+ messages in thread
From: Al Viro @ 2006-03-12 19:13 UTC (permalink / raw)
To: Ashish Khurange; +Cc: Shaya Potter, linux-fsdevel
On Mon, Mar 13, 2006 at 12:24:54AM +0530, Ashish Khurange wrote:
> In few functions (like sys_fchmod) I have file struct as an argument,
> which provides me both vfsmount and dentry, hence I can find out
> pathname of the file being changed.
> Where as in few functions (like vfs_mkdir) I have only dentry and inode
> of the directory, which are not sufficient to find the pathname.
>
> I hope I am clear now.
mkdir /tmp/1
mkdir /tmp/2
mkdir /tmp/3
mount --bind /tmp/2 /tmp/1
mkdir /tmp/1/a
umount /tmp/1
mount --bind /tmp/3 /tmp/1
mkdir /tmp/1/a
umount /tmp/1
What output do you want to get from the last two mkdir() calls, assuming
you do have vfsmounts? What is this output useful for?
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: get vfsmount from dentry
2006-03-12 19:13 ` Al Viro
@ 2006-03-12 20:34 ` Ashish Khurange
2006-03-12 20:45 ` Shaya Potter
2006-03-13 7:24 ` Jan Hudec
0 siblings, 2 replies; 13+ messages in thread
From: Ashish Khurange @ 2006-03-12 20:34 UTC (permalink / raw)
To: Al Viro; +Cc: Shaya Potter, linux-fsdevel
Al Viro wrote:
>mkdir /tmp/1
>mkdir /tmp/2
>mkdir /tmp/3
>mount --bind /tmp/2 /tmp/1
>mkdir /tmp/1/a
>umount /tmp/1
>mount --bind /tmp/3 /tmp/1
>mkdir /tmp/1/a
>umount /tmp/1
>
>What output do you want to get from the last two mkdir() calls, assuming
>you do have vfsmounts? What is this output useful for?
>
>
Well, forget about this particualr case.
My final aim is to build online file system mirroring tool for home
directories. And lets assuming that no other user have superuser
privilage to use mount or make symbolic links to directories.
I want entire pathname of changed file to replicate that change on the
corresponding file in the mirror site.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: get vfsmount from dentry
2006-03-12 20:34 ` Ashish Khurange
@ 2006-03-12 20:45 ` Shaya Potter
2006-03-13 7:24 ` Jan Hudec
1 sibling, 0 replies; 13+ messages in thread
From: Shaya Potter @ 2006-03-12 20:45 UTC (permalink / raw)
To: Ashish Khurange; +Cc: Al Viro, linux-fsdevel
On Mon, 2006-03-13 at 02:04 +0530, Ashish Khurange wrote:
> Al Viro wrote:
>
> >mkdir /tmp/1
> >mkdir /tmp/2
> >mkdir /tmp/3
> >mount --bind /tmp/2 /tmp/1
> >mkdir /tmp/1/a
> >umount /tmp/1
> >mount --bind /tmp/3 /tmp/1
> >mkdir /tmp/1/a
> >umount /tmp/1
> >
> >What output do you want to get from the last two mkdir() calls, assuming
> >you do have vfsmounts? What is this output useful for?
> >
> >
> Well, forget about this particualr case.
> My final aim is to build online file system mirroring tool for home
> directories. And lets assuming that no other user have superuser
> privilage to use mount or make symbolic links to directories.
> I want entire pathname of changed file to replicate that change on the
> corresponding file in the mirror site.
look at inotify. beagle monitors entire home directory via inotify.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: get vfsmount from dentry
2006-03-12 20:34 ` Ashish Khurange
2006-03-12 20:45 ` Shaya Potter
@ 2006-03-13 7:24 ` Jan Hudec
1 sibling, 0 replies; 13+ messages in thread
From: Jan Hudec @ 2006-03-13 7:24 UTC (permalink / raw)
To: Ashish Khurange; +Cc: Al Viro, Shaya Potter, linux-fsdevel
[-- Attachment #1: Type: text/plain, Size: 994 bytes --]
On Mon, Mar 13, 2006 at 02:04:13 +0530, Ashish Khurange wrote:
> Al Viro wrote:
>
> >mkdir /tmp/1
> >mkdir /tmp/2
> >mkdir /tmp/3
> >mount --bind /tmp/2 /tmp/1
> >mkdir /tmp/1/a
> >umount /tmp/1
> >mount --bind /tmp/3 /tmp/1
> >mkdir /tmp/1/a
> >umount /tmp/1
> >
> >What output do you want to get from the last two mkdir() calls, assuming
> >you do have vfsmounts? What is this output useful for?
> >
> Well, forget about this particualr case.
> My final aim is to build online file system mirroring tool for home
> directories. And lets assuming that no other user have superuser
> privilage to use mount or make symbolic links to directories.
> I want entire pathname of changed file to replicate that change on the
> corresponding file in the mirror site.
And why do you need abvolute paths for that? You only need paths
relative to root of that particular filesystem -- and you can get those
without vfsmount.
--
Jan 'Bulb' Hudec <bulb@ucw.cz>
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2006-03-13 7:24 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-03-12 13:44 get vfsmount from dentry Ashish Khurange
2006-03-12 13:55 ` Al Viro
2006-03-12 17:20 ` Ashish Khurange
2006-03-12 17:41 ` Al Viro
2006-03-12 18:00 ` Ashish Khurange
2006-03-12 18:23 ` Shaya Potter
2006-03-12 18:54 ` Ashish Khurange
2006-03-12 19:13 ` Al Viro
2006-03-12 20:34 ` Ashish Khurange
2006-03-12 20:45 ` Shaya Potter
2006-03-13 7:24 ` Jan Hudec
2006-03-12 18:24 ` Al Viro
2006-03-12 19:10 ` Jamie Lokier
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).