summaryrefslogtreecommitdiffstats
path: root/xlators/protocol/server/src/server-resolve.c
diff options
context:
space:
mode:
authorAnand Avati <avati@gluster.com>2012-01-13 13:27:15 +0530
committerAnand Avati <avati@gluster.com>2012-01-20 05:03:42 -0800
commit7e1f8e3bac201f88e2d9ef62fc69a044716dfced (patch)
tree77540dbf1def2c864f8ae55f2293dba4a1d47488 /xlators/protocol/server/src/server-resolve.c
parent33c568ce1a28c1739f095611b40b7acf40e4e6df (diff)
core: GFID filehandle based backend and anonymous FDs
1. What -------- This change introduces an infrastructure change in the filesystem which lets filesystem operation address objects (inodes) just by its GFID. Thus far GFID has been a unique identifier of a user-visible inode. But in terms of addressability the only mechanism thus far has been the backend filesystem path, which could be derived from the GFID only if it was cached in the inode table along with the entire set of dentry ancestry leading up to the root. This change essentially decouples addressability from the namespace. It is no more necessary to be aware of the parent directory to address a file or directory. 2. Why ------- The biggest use case for such a feature is NFS for generating persistent filehandles. So far the technique for generating filehandles in NFS has been to encode path components so that the appropriate inode_t can be repopulated into the inode table by means of a recursive lookup of each component top-down. Another use case is the ability to perform more intelligent self-healing and rebalancing of inodes with hardlinks and also to detect renames. A derived feature from GFID filehandles is anonymous FDs. An anonymous FD is an internal USABLE "fd_t" which does not map to a user opened file descriptor or to an internal ->open()'d fd. The ability to address a file by the GFID eliminates the need to have a persistent ->open()'d fd for the purpose of avoiding the namespace. This improves NFS read/write performance significantly eliminating open/close calls and also fixes some of today's limitations (like keeping an FD open longer than necessary resulting in disk space leakage) 3. How ------- At each storage/posix translator level, every file is hardlinked inside a hidden .glusterfs directory (under the top level export) with the name as the ascii-encoded standard UUID format string. For reasons of performance and scalability there is a two-tier classification of those hardlinks under directories with the initial parts of the UUID string as the directory names. For directories (which cannot be hardlinked), the approach is to use a symlink which dereferences the parent GFID path along with basename of the directory. The parent GFID dereference will in turn be a dereference of the grandparent with the parent's basename, and so on recursively up to the root export. 4. Development --------------- 4a. To leverage the ability to address an inode by its GFID, the technique is to perform a "nameless lookup". This means, to populate a loc_t structure as: loc_t { pargfid: NULL parent: NULL name: NULL path: NULL gfid: GFID to be looked up [out parameter] inode: inode_new () result [in parameter] } and performing such lookup will return in its callback an inode_t populated with the right contexts and a struct iatt which can be used to perform an inode_link () on the inode (without a parent and basename). The inode will now be hashed and linked in the inode table and findable via inode_find(). A fundamental change moving forward is that the primary fields in a loc_t structure are now going to be (pargfid, name) and (gfid) depending on the kind of FOP. So far path had been the primary field for operations. The remaining fields only serve as hints/helpers. 4b. If read/write is to be performed on an inode_t, the approach so far has been to: fd_create(), STACK_WIND(open, fd), fd_bind (in callback) and then perform STACK_WIND(read, fd) etc. With anonymous fds now you can do fd_anonymous (inode), STACK_WIND (read, fd). This results in great boost in performance in the inbuilt NFS server. 5. Misc ------- The inode_ctx_put[2] has been renamed to inode_ctx_set[2] to be consistent with the rest of the codebase. Change-Id: Ie4629edf6bd32a595f4d7f01e90c0a01f16fb12f BUG: 781318 Reviewed-on: http://review.gluster.com/669 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Anand Avati <avati@gluster.com>
Diffstat (limited to 'xlators/protocol/server/src/server-resolve.c')
-rw-r--r--xlators/protocol/server/src/server-resolve.c388
1 files changed, 166 insertions, 222 deletions
diff --git a/xlators/protocol/server/src/server-resolve.c b/xlators/protocol/server/src/server-resolve.c
index 50ae9231c33..38ab368c3f0 100644
--- a/xlators/protocol/server/src/server-resolve.c
+++ b/xlators/protocol/server/src/server-resolve.c
@@ -33,72 +33,9 @@ resolve_entry_simple (call_frame_t *frame);
int
resolve_inode_simple (call_frame_t *frame);
int
-resolve_path_simple (call_frame_t *frame);
-
+resolve_continue (call_frame_t *frame);
int
-component_count (const char *path)
-{
- int count = 0;
- const char *trav = NULL;
-
- for (trav = path; *trav; trav++) {
- if (*trav == '/')
- count++;
- }
-
- return count + 2;
-}
-
-
-int
-prepare_components (call_frame_t *frame)
-{
- server_state_t *state = NULL;
- server_resolve_t *resolve = NULL;
- char *resolved = NULL;
- int count = 0;
- struct resolve_comp *components = NULL;
- int i = 0;
- char *trav = NULL;
-
- state = CALL_STATE (frame);
- resolve = state->resolve_now;
-
- resolved = gf_strdup (resolve->path);
- resolve->resolved = resolved;
-
- count = component_count (resolve->path);
- components = GF_CALLOC (sizeof (*components), count,
- gf_server_mt_resolv_comp_t);
- if (!components)
- goto out;
-
- resolve->components = components;
-
- components[0].basename = "";
- components[0].inode = state->itable->root;
-
- i = 1;
- for (trav = resolved; *trav; trav++) {
- if (*trav == '/') {
- *trav = 0;
-
- if (!(*(trav + 1))) {
- /* Skip trailing "/" in a path.
- This is the check which prevents
- inode_link'age of itable->root
- */
- break;
- }
-
- components[i].basename = trav + 1;
- i++;
- }
- }
-out:
- return 0;
-}
-
+resolve_anonfd_simple (call_frame_t *frame);
int
resolve_loc_touchup (call_frame_t *frame)
@@ -123,231 +60,177 @@ resolve_loc_touchup (call_frame_t *frame)
if (ret)
gf_log (frame->this->name, GF_LOG_TRACE,
"return value inode_path %d", ret);
-
- 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;
}
int
-resolve_deep_continue (call_frame_t *frame)
+resolve_gfid_entry_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
+ int op_ret, int op_errno, inode_t *inode,
+ struct iatt *buf, dict_t *xattr, struct iatt *postparent)
{
server_state_t *state = NULL;
- xlator_t *this = NULL;
server_resolve_t *resolve = NULL;
- int ret = 0;
+ inode_t *link_inode = NULL;
+ loc_t *resolve_loc = NULL;
state = CALL_STATE (frame);
- this = frame->this;
resolve = state->resolve_now;
+ resolve_loc = &resolve->resolve_loc;
- resolve->op_ret = 0;
- resolve->op_errno = 0;
+ if (op_ret == -1) {
+ gf_log (this->name, ((op_errno == ENOENT) ? GF_LOG_DEBUG :
+ GF_LOG_WARNING),
+ "%s/%s: failed to resolve (%s)",
+ uuid_utoa (resolve_loc->pargfid), resolve_loc->name,
+ strerror (op_errno));
+ goto out;
+ }
- if (!uuid_is_null (resolve->pargfid))
- ret = resolve_entry_simple (frame);
- else if (!uuid_is_null (resolve->gfid))
- ret = resolve_inode_simple (frame);
- else if (resolve->path)
- ret = resolve_path_simple (frame);
- if (ret)
- gf_log (this->name, GF_LOG_DEBUG,
- "return value of resolve_*_simple %d", ret);
+ link_inode = inode_link (inode, resolve_loc->parent,
+ resolve_loc->name, buf);
- resolve_loc_touchup (frame);
+ if (!link_inode)
+ goto out;
- server_resolve_all (frame);
+ inode_lookup (link_inode);
+
+ inode_unref (link_inode);
+out:
+ loc_wipe (resolve_loc);
+
+ resolve_continue (frame);
return 0;
}
int
-resolve_deep_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
+resolve_gfid_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
int op_ret, int op_errno, inode_t *inode, struct iatt *buf,
dict_t *xattr, struct iatt *postparent)
{
server_state_t *state = NULL;
server_resolve_t *resolve = NULL;
- struct resolve_comp *components = NULL;
- int i = 0;
inode_t *link_inode = NULL;
+ loc_t *resolve_loc = NULL;
state = CALL_STATE (frame);
resolve = state->resolve_now;
- components = resolve->components;
-
- i = (long) cookie;
+ resolve_loc = &resolve->resolve_loc;
if (op_ret == -1) {
gf_log (this->name, ((op_errno == ENOENT) ? GF_LOG_DEBUG :
GF_LOG_WARNING),
"%s: failed to resolve (%s)",
- resolve->resolved, strerror (op_errno));
- goto get_out_of_here;
+ uuid_utoa (resolve_loc->gfid), strerror (op_errno));
+ loc_wipe (&resolve->resolve_loc);
+ goto out;
}
- if (i != 0) {
- /* no linking for root inode */
- link_inode = inode_link (inode, resolve->deep_loc.parent,
- resolve->deep_loc.name, buf);
- inode_lookup (link_inode);
- components[i].inode = link_inode;
- link_inode = NULL;
- }
+ loc_wipe (resolve_loc);
- loc_wipe (&resolve->deep_loc);
+ link_inode = inode_link (inode, NULL, NULL, buf);
- i++; /* next component */
+ if (!link_inode)
+ goto out;
- if (!components[i].basename) {
- /* all components of the path are resolved */
- goto get_out_of_here;
+ inode_lookup (link_inode);
+
+ if (uuid_is_null (resolve->pargfid)) {
+ inode_unref (link_inode);
+ goto out;
}
- /* join the current component with the path resolved until now */
- *(components[i].basename - 1) = '/';
+ resolve_loc->parent = link_inode;
+ uuid_copy (resolve_loc->pargfid, resolve_loc->parent->gfid);
- resolve->deep_loc.path = gf_strdup (resolve->resolved);
- resolve->deep_loc.parent = inode_ref (components[i-1].inode);
- resolve->deep_loc.inode = inode_new (state->itable);
- resolve->deep_loc.name = components[i].basename;
+ resolve_loc->name = resolve->bname;
- if (frame && frame->root->state && BOUND_XL (frame)) {
- STACK_WIND_COOKIE (frame, resolve_deep_cbk, (void *) (long) i,
- BOUND_XL (frame), BOUND_XL (frame)->fops->lookup,
- &resolve->deep_loc, NULL);
- return 0;
- }
+ resolve_loc->inode = inode_new (state->itable);
+ inode_path (resolve_loc->parent, resolve_loc->name,
+ (char **) &resolve_loc->path);
-get_out_of_here:
- resolve_deep_continue (frame);
+ STACK_WIND (frame, resolve_gfid_entry_cbk,
+ BOUND_XL (frame), BOUND_XL (frame)->fops->lookup,
+ &resolve->resolve_loc, NULL);
+ return 0;
+out:
+ resolve_continue (frame);
return 0;
}
int
-resolve_path_deep (call_frame_t *frame)
+resolve_gfid (call_frame_t *frame)
{
- server_state_t *state = NULL;
- server_resolve_t *resolve = NULL;
- int i = 0;
+ server_state_t *state = NULL;
+ xlator_t *this = NULL;
+ server_resolve_t *resolve = NULL;
+ loc_t *resolve_loc = NULL;
+ int ret = 0;
state = CALL_STATE (frame);
+ this = frame->this;
resolve = state->resolve_now;
+ resolve_loc = &resolve->resolve_loc;
- gf_log (BOUND_XL (frame)->name, GF_LOG_DEBUG,
- "RESOLVE %s() seeking deep resolution of %s",
- gf_fop_list[frame->root->op], resolve->path);
-
- prepare_components (frame);
-
- /* start from the root */
- resolve->deep_loc.inode = state->itable->root;
- resolve->deep_loc.path = gf_strdup ("/");
- resolve->deep_loc.name = "";
-
- if (frame && frame->root->state && BOUND_XL (frame)) {
- STACK_WIND_COOKIE (frame, resolve_deep_cbk, (void *) (long) i,
- BOUND_XL (frame), BOUND_XL (frame)->fops->lookup,
- &resolve->deep_loc, NULL);
- return 0;
+ if (!uuid_is_null (resolve->pargfid)) {
+ uuid_copy (resolve_loc->gfid, resolve->pargfid);
+ resolve_loc->inode = inode_new (state->itable);
+ ret = inode_path (resolve_loc->inode, NULL,
+ (char **)&resolve_loc->path);
+ } else if (!uuid_is_null (resolve->gfid)) {
+ uuid_copy (resolve_loc->gfid, resolve->gfid);
+ resolve_loc->inode = inode_new (state->itable);
+ ret = inode_path (resolve_loc->inode, NULL,
+ (char **)&resolve_loc->path);
}
- resolve_deep_continue (frame);
+ STACK_WIND (frame, resolve_gfid_cbk,
+ BOUND_XL (frame), BOUND_XL (frame)->fops->lookup,
+ &resolve->resolve_loc, NULL);
return 0;
}
int
-resolve_path_simple (call_frame_t *frame)
+resolve_continue (call_frame_t *frame)
{
server_state_t *state = NULL;
+ xlator_t *this = NULL;
server_resolve_t *resolve = NULL;
- struct resolve_comp *components = NULL;
- int ret = -1;
- int par_idx = -1;
- int ino_idx = -1;
- int i = 0;
+ int ret = 0;
state = CALL_STATE (frame);
+ this = frame->this;
resolve = state->resolve_now;
- components = resolve->components;
-
- if (!components) {
- gf_log ("", GF_LOG_INFO,
- "failed to resolve, component not found");
- resolve->op_ret = -1;
- resolve->op_errno = ENOENT;
- goto out;
- }
- for (i = 0; components[i].basename; i++) {
- par_idx = ino_idx;
- ino_idx = i;
- }
-
- if (ino_idx == -1) {
- gf_log ("", GF_LOG_INFO,
- "failed to resolve, inode index not found");
- resolve->op_ret = -1;
- resolve->op_errno = EINVAL;
- goto out;
- }
-
- if (par_idx == -1)
- /* "/" will not have a parent */
- goto noparent;
-
- if (!components[par_idx].inode) {
- gf_log ("", GF_LOG_INFO,
- "failed to resolve, parent inode not found");
- resolve->op_ret = -1;
- resolve->op_errno = ENOENT;
- goto out;
- }
- state->loc_now->parent = inode_ref (components[par_idx].inode);
-noparent:
-
- if (!components[ino_idx].inode &&
- (resolve->type == RESOLVE_MUST || resolve->type == RESOLVE_EXACT)) {
- gf_log ("", GF_LOG_INFO,
- "failed to resolve, inode not found");
- resolve->op_ret = -1;
- resolve->op_errno = ENOENT;
- goto out;
- }
+ resolve->op_ret = 0;
+ resolve->op_errno = 0;
- if (components[ino_idx].inode && resolve->type == RESOLVE_NOT) {
- gf_log ("", GF_LOG_INFO,
- "failed to resolve, inode found");
- resolve->op_ret = -1;
- resolve->op_errno = EEXIST;
+ if (resolve->fd_no != -1) {
+ ret = resolve_anonfd_simple (frame);
goto out;
- }
-
- if (components[ino_idx].inode)
- state->loc_now->inode = inode_ref (components[ino_idx].inode);
-
- ret = 0;
+ } else if (!uuid_is_null (resolve->pargfid))
+ ret = resolve_entry_simple (frame);
+ else if (!uuid_is_null (resolve->gfid))
+ ret = resolve_inode_simple (frame);
+ if (ret)
+ gf_log (this->name, GF_LOG_DEBUG,
+ "return value of resolve_*_simple %d", ret);
+ resolve_loc_touchup (frame);
out:
- return ret;
+ server_resolve_all (frame);
+
+ return 0;
}
+
/*
Check if the requirements are fulfilled by entries in the inode cache itself
Return value:
@@ -380,7 +263,9 @@ resolve_entry_simple (call_frame_t *frame)
}
/* expected @parent was found from the inode cache */
+ uuid_copy (state->loc_now->pargfid, resolve->pargfid);
state->loc_now->parent = inode_ref (parent);
+ state->loc_now->name = resolve->bname;
inode = inode_grep (state->itable, parent, resolve->bname);
if (!inode) {
@@ -441,7 +326,7 @@ server_resolve_entry (call_frame_t *frame)
if (ret > 0) {
loc_wipe (loc);
- resolve_path_deep (frame);
+ resolve_gfid (frame);
return 0;
}
@@ -477,6 +362,7 @@ resolve_inode_simple (call_frame_t *frame)
ret = 0;
state->loc_now->inode = inode_ref (inode);
+ uuid_copy (state->loc_now->gfid, resolve->gfid);
out:
if (inode)
@@ -500,7 +386,7 @@ server_resolve_inode (call_frame_t *frame)
if (ret > 0) {
loc_wipe (loc);
- resolve_path_deep (frame);
+ resolve_gfid (frame);
return 0;
}
@@ -514,6 +400,62 @@ server_resolve_inode (call_frame_t *frame)
int
+resolve_anonfd_simple (call_frame_t *frame)
+{
+ server_state_t *state = NULL;
+ server_resolve_t *resolve = NULL;
+ inode_t *inode = NULL;
+ int ret = 0;
+
+ state = CALL_STATE (frame);
+ resolve = state->resolve_now;
+
+ inode = inode_find (state->itable, resolve->gfid);
+
+ if (!inode) {
+ resolve->op_ret = -1;
+ resolve->op_errno = ENOENT;
+ ret = 1;
+ goto out;
+ }
+
+ ret = 0;
+
+ state->fd = fd_anonymous (inode);
+out:
+ if (inode)
+ inode_unref (inode);
+
+ return ret;
+}
+
+
+int
+server_resolve_anonfd (call_frame_t *frame)
+{
+ server_state_t *state = NULL;
+ int ret = 0;
+ loc_t *loc = NULL;
+
+ state = CALL_STATE (frame);
+ loc = state->loc_now;
+
+ ret = resolve_anonfd_simple (frame);
+
+ if (ret > 0) {
+ loc_wipe (loc);
+ resolve_gfid (frame);
+ return 0;
+ }
+
+ server_resolve_all (frame);
+
+ return 0;
+
+}
+
+
+int
server_resolve_fd (call_frame_t *frame)
{
server_state_t *state = NULL;
@@ -527,6 +469,11 @@ server_resolve_fd (call_frame_t *frame)
fd_no = resolve->fd_no;
+ if (fd_no == -2) {
+ server_resolve_anonfd (frame);
+ return 0;
+ }
+
state->fd = gf_fd_fdptr_get (conn->fdtable, fd_no);
if (!state->fd) {
@@ -562,14 +509,11 @@ server_resolve (call_frame_t *frame)
server_resolve_inode (frame);
- } else if (resolve->path) {
-
- gf_log (frame->this->name, GF_LOG_INFO,
- "pure path resolution for %s (%s)",
- resolve->path, gf_fop_list[frame->root->op]);
- resolve_path_deep (frame);
-
- } else {
+ } else {
+ if (resolve == &state->resolve)
+ gf_log (frame->this->name, GF_LOG_WARNING,
+ "no resolution type for %s (%s)",
+ resolve->path, gf_fop_list[frame->root->op]);
resolve->op_ret = -1;
resolve->op_errno = EINVAL;