summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libglusterfs/src/inode.c126
-rw-r--r--libglusterfs/src/inode.h3
2 files changed, 75 insertions, 54 deletions
diff --git a/libglusterfs/src/inode.c b/libglusterfs/src/inode.c
index d81fa6183..bfcc9e2bc 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 375ff3ee4..7eea0c5a3 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);