This is the mail archive of the
systemtap@sourceware.org
mailing list for the systemtap project.
Re: dereferencing filenames from a vfs_write probe
- From: "Stone, Joshua I" <joshua dot i dot stone at intel dot com>
- To: Eugene Teo <eugeneteo at kernel dot sg>
- Cc: systemtap at sourceware dot org
- Date: Thu, 20 Mar 2008 09:00:04 -0700
- Subject: Re: dereferencing filenames from a vfs_write probe
- References: <1205982759.13969.ezmlm@sourceware.org> <20080320033734.GA32122@homer> <20080320041758.GA3542@kernel.sg>
Eugene Teo wrote:
> I have not tested it, but I have a piece of code I used in a script
> elsewhere that you can probably amend and reuse:
>
> function get_d_path_info:string (task:long, fd:long) %{
> struct task_struct *p = (struct task_struct *)((long)THIS->task);
> struct files_struct *files = kread(&p->files);
> char *page = (char *)__get_free_page(GFP_KERNEL);
> struct file *filp;
> struct dentry *dentry;
> struct vfsmount *vfsmnt;
>
> spin_lock(&files->file_lock);
> filp = fcheck_files(files, THIS->fd);
> dentry = kread(&filp->f_path.dentry);
> vfsmnt = kread(&filp->f_path.mnt);
> snprintf(THIS->__retvalue, MAXSTRINGLEN, " %s",
> d_path(dentry, vfsmnt, page, PAGE_SIZE));
> free_page((unsigned long)page);
> spin_unlock(&files->file_lock);
> CATCH_DEREF_FAULT();
> %}
You should careful - each kread() will jump to the CATCH_DEREF_FAULT()
block if there's an error. You may end up leaving this function with
the page not freed or the lock still held!
Josh