This is the mail archive of the systemtap@sourceware.org mailing list for the systemtap project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: dereferencing filenames from a vfs_write probe


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]