diff options
author | Raghavendra G <raghavendra@gluster.com> | 2011-06-14 01:41:11 +0000 |
---|---|---|
committer | Anand Avati <avati@gluster.com> | 2011-06-14 22:37:30 -0700 |
commit | 72d56ff2a8bd0eacfa8036f7583fc0dd4de460d0 (patch) | |
tree | 836276c76bcc5753c7064b8956031325fd13e714 /libglusterfs | |
parent | 837f172e8775c908cb90c14a956ed010d468a0ad (diff) |
libglusterfs/inode.c: Add version of inode_path which can be called holding inode->lock.
Signed-off-by: Raghavendra G <raghavendra@gluster.com>
Signed-off-by: Anand Avati <avati@gluster.com>
BUG: 1059 (enhancements for getting statistics from performance translators)
URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=1059
Diffstat (limited to 'libglusterfs')
-rw-r--r-- | libglusterfs/src/inode.c | 126 | ||||
-rw-r--r-- | libglusterfs/src/inode.h | 3 |
2 files changed, 75 insertions, 54 deletions
diff --git a/libglusterfs/src/inode.c b/libglusterfs/src/inode.c index d81fa6183d7..bfcc9e2bc4f 100644 --- a/libglusterfs/src/inode.c +++ b/libglusterfs/src/inode.c @@ -997,14 +997,14 @@ inode_parent (inode_t *inode, ino_t par, const char *name) int -inode_path (inode_t *inode, const char *name, char **bufp) +__inode_path (inode_t *inode, const char *name, char **bufp) { inode_table_t *table = NULL; - dentry_t *trav = NULL; - size_t i = 0, size = 0; - int64_t ret = 0; - int len = 0; - char *buf = NULL; + dentry_t *trav = NULL; + size_t i = 0, size = 0; + int64_t ret = 0; + int len = 0; + char *buf = NULL; if (!inode) { gf_log_callingfn ("", GF_LOG_WARNING, "inode not found"); @@ -1013,64 +1013,60 @@ inode_path (inode_t *inode, const char *name, char **bufp) table = inode->table; - pthread_mutex_lock (&table->lock); - { - for (trav = __dentry_search_arbit (inode); trav; - trav = __dentry_search_arbit (trav->parent)) { - i ++; /* "/" */ - i += strlen (trav->name); - if (i > PATH_MAX) { - gf_log (table->name, GF_LOG_CRITICAL, - "possible infinite loop detected, " - "forcing break. name=(%s)", name); - ret = -ENOENT; - goto unlock; - } - } - - if ((inode->ino != 1) && - (i == 0)) { - gf_log (table->name, GF_LOG_WARNING, - "no dentry for non-root inode %"PRId64": %s", - inode->ino, uuid_utoa (inode->gfid)); + for (trav = __dentry_search_arbit (inode); trav; + trav = __dentry_search_arbit (trav->parent)) { + i ++; /* "/" */ + i += strlen (trav->name); + if (i > PATH_MAX) { + gf_log (table->name, GF_LOG_CRITICAL, + "possible infinite loop detected, " + "forcing break. name=(%s)", name); ret = -ENOENT; - goto unlock; + goto out; } + } - if (name) { - i++; - i += strlen (name); - } + if ((inode->ino != 1) && + (i == 0)) { + gf_log (table->name, GF_LOG_WARNING, + "no dentry for non-root inode %"PRId64": %s", + inode->ino, uuid_utoa (inode->gfid)); + ret = -ENOENT; + goto out; + } - ret = i; - size = i + 1; - buf = GF_CALLOC (size, sizeof (char), gf_common_mt_char); - if (buf) { + if (name) { + i++; + i += strlen (name); + } - buf[size - 1] = 0; + ret = i; + size = i + 1; + buf = GF_CALLOC (size, sizeof (char), gf_common_mt_char); + if (buf) { - if (name) { - len = strlen (name); - strncpy (buf + (i - len), name, len); - buf[i-len-1] = '/'; - i -= (len + 1); - } + buf[size - 1] = 0; - for (trav = __dentry_search_arbit (inode); trav; - trav = __dentry_search_arbit (trav->parent)) { - len = strlen (trav->name); - strncpy (buf + (i - len), trav->name, len); - buf[i-len-1] = '/'; - i -= (len + 1); - } - *bufp = buf; - } else { - ret = -ENOMEM; + if (name) { + len = strlen (name); + strncpy (buf + (i - len), name, len); + buf[i-len-1] = '/'; + i -= (len + 1); } + + for (trav = __dentry_search_arbit (inode); trav; + trav = __dentry_search_arbit (trav->parent)) { + len = strlen (trav->name); + strncpy (buf + (i - len), trav->name, len); + buf[i-len-1] = '/'; + i -= (len + 1); + } + *bufp = buf; + } else { + ret = -ENOMEM; } -unlock: - pthread_mutex_unlock (&table->lock); +out: if (inode->ino == 1 && !name) { ret = 1; if (buf) { @@ -1088,6 +1084,28 @@ unlock: return ret; } + +int +inode_path (inode_t *inode, const char *name, char **bufp) +{ + inode_table_t *table = NULL; + int ret = -1; + + if (!inode) + return -1; + + table = inode->table; + + pthread_mutex_lock (&table->lock); + { + ret = __inode_path (inode, name, bufp); + } + pthread_mutex_unlock (&table->lock); + + return ret; +} + + static int inode_table_prune (inode_table_t *table) { diff --git a/libglusterfs/src/inode.h b/libglusterfs/src/inode.h index 375ff3ee4e5..7eea0c5a389 100644 --- a/libglusterfs/src/inode.h +++ b/libglusterfs/src/inode.h @@ -152,6 +152,9 @@ inode_find (inode_table_t *table, uuid_t gfid); int inode_path (inode_t *inode, const char *name, char **bufp); +int +__inode_path (inode_t *inode, const char *name, char **bufp); + inode_t * inode_from_path (inode_table_t *table, const char *path); |