Created
August 21, 2014 05:54
-
-
Save harshavardhana/b5d3c69db5312b84022f to your computer and use it in GitHub Desktop.
Find-inum.stp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# cat find_same_inode.stap | |
#!/usr/bin/stap -g | |
# Copyright (c) 2014 Brad Hubbard <[email protected]> | |
%{ | |
#include <linux/file.h> | |
%} | |
function find_same_inode:string (path:string) %{ | |
struct nameidata *nd; | |
struct path* p; | |
struct dentry* dent; | |
struct inode* node; | |
struct vfsmount* mnt; | |
int err; | |
char* path; | |
nd = kmalloc(sizeof(*nd), GFP_KERNEL); | |
err = path_lookup(STAP_ARG_path, 0, nd); | |
if (err) { | |
kfree(nd); | |
nd = NULL; | |
STAP_ERROR("FATAL ERROR: Path lookup failed"); | |
STAP_RETURN(1); | |
} | |
p = &nd->path; | |
path = kmalloc(PAGE_SIZE, GFP_KERNEL); | |
tmp = kmalloc(PAGE_SIZE, GFP_KERNEL); | |
path = d_path(p, path, PAGE_SIZE); | |
strlcpy(STAP_RETVALUE, "Finding all paths for file: ", MAXSTRINGLEN); | |
strlcpy(STAP_RETVALUE, path, MAXSTRINGLEN); | |
strlcpy(STAP_RETVALUE, "\n\n", MAXSTRINGLEN); | |
if(dent = kread(&p->dentry) && node = kread(&dent->d_inode) && mnt = kread(&p->mnt)) { | |
spin_lock(&dcache_lock); | |
list_for_each_entry(dent, &node->i_dentry, d_alias) { | |
struct path pth; | |
pth.dentry = dent; | |
pth.mnt = mnt; | |
spin_unlock(&dcache_lock); | |
path = d_path(&pth, path, PAGE_SIZE); | |
spin_lock(&dcache_lock); | |
strlcpy(STAP_RETVALUE, path, MAXSTRINGLEN); | |
strlcpy(STAP_RETVALUE, "\n\n", MAXSTRINGLEN); | |
} | |
spin_unlock(&dcache_lock); | |
} | |
//snprintf(STAP_RETVALUE, MAXSTRINGLEN, "%s", path); | |
CATCH_DEREF_FAULT(); | |
kfree(nd); | |
kfree(path); | |
%} | |
probe begin { | |
printf( "%s", find_same_inode(@1)); | |
exit(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment