int nfs_inode_loc_fill (inode_t *inode, loc_t *loc, int how) { char *resolvedpath = NULL; inode_t *parent = NULL; int ret = -EFAULT; if ((!inode) || (!loc)) return ret; /* If gfid is not null, then the inode is already linked to * the inode table, and not a newly created one. For newly * created inode, inode_path returns null gfid as the path. */ if (!gf_uuid_is_null (inode->gfid)) { ret = inode_path (inode, NULL, &resolvedpath); if (ret < 0) { gf_msg (GF_NFS, GF_LOG_ERROR, 0, NFS_MSG_PATH_RESOLVE_FAIL, "path resolution " "failed %s", resolvedpath); goto err; } } if (resolvedpath == NULL) { char tmp_path[GFID_STR_PFX_LEN + 1] = {0,}; snprintf (tmp_path, sizeof (tmp_path), "<gfid:%s>", uuid_utoa (loc->gfid)); resolvedpath = gf_strdup (tmp_path); } else { parent = inode_parent (inode, loc->pargfid, NULL); } ret = nfs_loc_fill (loc, inode, parent, resolvedpath); if (ret < 0) { gf_msg (GF_NFS, GF_LOG_ERROR, -ret, NFS_MSG_LOC_FILL_RESOLVE_FAIL, "loc fill resolution failed %s", resolvedpath); goto err; } ret = 0; err: if (parent) inode_unref (parent); GF_FREE (resolvedpath); return ret; }
int32_t ida_fd_to_loc(ida_local_t * local, loc_t * loc, fd_t * fd) { int32_t error; error = inode_path(fd->inode, NULL, (char **)&loc->path); if (unlikely(error < 0)) { return -error; } loc->name = strrchr(loc->path, '/'); if (loc->name != NULL) { loc->name++; } error = ida_inode_assign(local, &loc->inode, fd->inode); if (unlikely(error != 0)) { goto failed; } if (!uuid_is_null(loc->inode->gfid)) { uuid_copy(loc->gfid, loc->inode->gfid); } loc->parent = inode_parent(loc->inode, 0, NULL); if (loc->parent != NULL) { if (!uuid_is_null(loc->parent->gfid)) { uuid_copy(loc->pargfid, loc->parent->gfid); } } return 0; failed: GF_FREE((char *)loc->path); return ENOMEM; }
void afr_build_parent_loc (loc_t *parent, loc_t *child) { char *tmp = NULL; if (!child->parent) { loc_copy (parent, child); return; } tmp = gf_strdup (child->path); parent->path = gf_strdup (dirname (tmp)); GF_FREE (tmp); parent->name = strrchr (parent->path, '/'); if (parent->name) parent->name++; parent->inode = inode_ref (child->parent); parent->parent = inode_parent (parent->inode, 0, NULL); parent->ino = parent->inode->ino; }
static int resolve_loc_touchup (call_frame_t *frame) { server_state_t *state = NULL; server_resolve_t *resolve = NULL; loc_t *loc = NULL; char *path = NULL; int ret = 0; state = CALL_STATE (frame); resolve = state->resolve_now; loc = state->loc_now; if (!loc->path) { if (loc->parent && resolve->bname) { ret = inode_path (loc->parent, resolve->bname, &path); } else if (loc->inode) { ret = inode_path (loc->inode, NULL, &path); } if (!path) path = gf_strdup (resolve->path); loc->path = path; } loc->name = strrchr (loc->path, '/'); if (loc->name) loc->name++; if (!loc->parent && loc->inode) { loc->parent = inode_parent (loc->inode, 0, NULL); } return 0; }