summaryrefslogtreecommitdiffstats
path: root/xlators
diff options
context:
space:
mode:
authorVikas Gorur <vikas@zresearch.com>2009-02-23 19:36:26 +0530
committerAnand V. Avati <avati@amp.gluster.com>2009-02-23 21:01:56 +0530
commitf264f69ae96ade536dc6f5b8c1ce2579839d6222 (patch)
treef2b14407f8d2307b9412942a09178e146a7bc9f6 /xlators
parent8b1762971f8d18f73fa64a967c4cd2baa13d07fc (diff)
Deleted xattr caching code from posix in anticipation of the xattr-cache translator.
Signed-off-by: Anand V. Avati <avati@amp.gluster.com>
Diffstat (limited to 'xlators')
-rw-r--r--xlators/storage/posix/src/Makefile.am4
-rw-r--r--xlators/storage/posix/src/posix.c241
-rw-r--r--xlators/storage/posix/src/posix.h4
-rw-r--r--xlators/storage/posix/src/xattr-cache.c539
-rw-r--r--xlators/storage/posix/src/xattr-cache.h65
5 files changed, 152 insertions, 701 deletions
diff --git a/xlators/storage/posix/src/Makefile.am b/xlators/storage/posix/src/Makefile.am
index 2859e09aa49..9acaad65185 100644
--- a/xlators/storage/posix/src/Makefile.am
+++ b/xlators/storage/posix/src/Makefile.am
@@ -4,10 +4,10 @@ xlatordir = $(libdir)/glusterfs/$(PACKAGE_VERSION)/xlator/storage
posix_la_LDFLAGS = -module -avoidversion
-posix_la_SOURCES = posix.c xattr-cache.c
+posix_la_SOURCES = posix.c
posix_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la
-noinst_HEADERS = posix.h xattr-cache.h
+noinst_HEADERS = posix.h
AM_CFLAGS = -fPIC -fno-strict-aliasing -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -D$(GF_HOST_OS) -Wall \
-I$(top_srcdir)/libglusterfs/src -shared -nostartfiles \
diff --git a/xlators/storage/posix/src/posix.c b/xlators/storage/posix/src/posix.c
index fe59d64861a..9861d16cf57 100644
--- a/xlators/storage/posix/src/posix.c
+++ b/xlators/storage/posix/src/posix.c
@@ -590,7 +590,6 @@ posix_releasedir (xlator_t *this,
struct posix_fd * pfd = NULL;
uint64_t tmp_pfd = 0;
int ret = 0;
- xattr_cache_handle_t handle = {{0,},0};
VALIDATE_OR_GOTO (this, out);
VALIDATE_OR_GOTO (fd, out);
@@ -612,9 +611,6 @@ posix_releasedir (xlator_t *this,
goto out;
}
- handle.fd = fd;
- posix_xattr_cache_flush (this, &handle);
-
ret = closedir (pfd->dir);
if (ret == -1) {
op_errno = errno;
@@ -816,8 +812,6 @@ posix_unlink (call_frame_t *frame, xlator_t *this,
int32_t op_errno = 0;
char * real_path = NULL;
- xattr_cache_handle_t handle = {{0,}, 0};
-
DECLARE_OLD_FS_ID_VAR;
VALIDATE_OR_GOTO (frame, out);
@@ -827,12 +821,6 @@ posix_unlink (call_frame_t *frame, xlator_t *this,
SET_FS_ID (frame->root->uid, frame->root->gid);
MAKE_REAL_PATH (real_path, this, loc->path);
- loc_copy (&handle.loc, loc);
- {
- posix_xattr_cache_flush (this, &handle);
- }
- loc_wipe (&handle.loc);
-
op_ret = unlink (real_path);
if (op_ret == -1) {
op_errno = errno;
@@ -859,8 +847,6 @@ posix_rmdir (call_frame_t *frame, xlator_t *this,
int32_t op_errno = 0;
char * real_path = 0;
- xattr_cache_handle_t handle = {{0,}, 0};
-
DECLARE_OLD_FS_ID_VAR;
VALIDATE_OR_GOTO (frame, out);
@@ -870,12 +856,6 @@ posix_rmdir (call_frame_t *frame, xlator_t *this,
SET_FS_ID (frame->root->uid, frame->root->gid);
MAKE_REAL_PATH (real_path, this, loc->path);
- loc_copy (&handle.loc, loc);
- {
- posix_xattr_cache_flush (this, &handle);
- }
- loc_wipe (&handle.loc);
-
op_ret = rmdir (real_path);
op_errno = errno;
@@ -967,8 +947,6 @@ posix_rename (call_frame_t *frame, xlator_t *this,
char * real_newpath = NULL;
struct stat stbuf = {0, };
- xattr_cache_handle_t handle = {{0,}, 0};
-
DECLARE_OLD_FS_ID_VAR;
VALIDATE_OR_GOTO (frame, out);
@@ -980,12 +958,6 @@ posix_rename (call_frame_t *frame, xlator_t *this,
MAKE_REAL_PATH (real_oldpath, this, oldloc->path);
MAKE_REAL_PATH (real_newpath, this, newloc->path);
- loc_copy (&handle.loc, oldloc);
- {
- posix_xattr_cache_flush (this, &handle);
- }
- loc_wipe (&handle.loc);
-
op_ret = rename (real_oldpath, real_newpath);
if (op_ret == -1) {
op_errno = errno;
@@ -1811,7 +1783,6 @@ posix_flush (call_frame_t *frame, xlator_t *this,
_fd = pfd->fd;
/* do nothing */
- posix_xattr_cache_flush_all (this);
op_ret = 0;
@@ -1834,7 +1805,6 @@ posix_release (xlator_t *this,
struct posix_fd * pfd = NULL;
int ret = -1;
uint64_t tmp_pfd = 0;
- xattr_cache_handle_t handle = {{0,},0};
VALIDATE_OR_GOTO (this, out);
VALIDATE_OR_GOTO (fd, out);
@@ -1852,9 +1822,6 @@ posix_release (xlator_t *this,
}
pfd = (struct posix_fd *)(long)tmp_pfd;
- handle.fd = fd;
- posix_xattr_cache_flush (this, &handle);
-
_fd = pfd->fd;
op_ret = close (_fd);
@@ -2419,15 +2386,13 @@ __add_array (int32_t *dest, int32_t *src, int count)
* "key" ==> array of 32-bit numbers
*/
-
int
-posix_xattrop_common (call_frame_t *frame, xlator_t *this,
- xattr_cache_handle_t *handle,
- gf_xattrop_flags_t optype, dict_t *xattr)
+posix_xattrop (call_frame_t *frame, xlator_t *this,
+ loc_t *loc, gf_xattrop_flags_t optype, dict_t *xattr)
{
- int32_t *array = NULL;
-
- int ret = 0;
+ char *real_path = NULL;
+ int32_t *array = NULL;
+ int size = 0;
int count = 0;
int op_ret = 0;
@@ -2441,87 +2406,191 @@ posix_xattrop_common (call_frame_t *frame, xlator_t *this,
trav = xattr->members_list;
+ if (loc->path)
+ MAKE_REAL_PATH (real_path, this, loc->path);
+
while (trav) {
count = trav->value->len / sizeof (int32_t);
array = CALLOC (count, sizeof (int32_t));
-
- ret = posix_xattr_cache_read (this, handle, trav->key,
- array, trav->value->len);
+
+ size = lgetxattr (real_path, trav->key, (char *)array,
+ trav->value->len);
+
+ op_errno = errno;
+ if ((size == -1) && (op_errno != ENODATA) &&
+ (op_errno != ENOATTR)) {
+ if (op_errno == ENOTSUP) {
+ GF_LOG_OCCASIONALLY(gf_posix_xattr_enotsup_log,
+ this->name,GF_LOG_WARNING,
+ "extended attributes not "
+ "supported by filesystem");
+ } else {
+ gf_log (this->name, GF_LOG_ERROR,
+ "%s: %s", loc->path,
+ strerror (op_errno));
+ }
+ goto out;
+ }
switch (optype) {
case GF_XATTROP_ADD_ARRAY:
- __add_array (array, (int32_t *) trav->value->data,
- trav->value->len / 4);
+ __add_array (array, (int32_t *) trav->value->data,
+ trav->value->len / 4);
break;
default:
gf_log (this->name, GF_LOG_ERROR,
- "unknown xattrop type %d",
- optype);
-
+ "unknown xattrop type %d. path=%s",
+ optype, loc->path);
op_ret = -1;
op_errno = EINVAL;
goto out;
}
- ret = posix_xattr_cache_write (this, handle, trav->key,
- array, trav->value->len);
-
- ret = dict_set_bin (xattr, trav->key, array,
- trav->value->len);
+ size = lsetxattr (real_path, trav->key, array,
+ trav->value->len, 0);
- if (ret != 0) {
+ op_errno = errno;
+ if (size == -1) {
gf_log (this->name, GF_LOG_ERROR,
- "key=%s (%s)",
- trav->key, strerror (-ret));
+ "%s: key=%s (%s)", loc->path,
+ trav->key, strerror (op_errno));
op_ret = -1;
- op_errno = EINVAL;
goto out;
- }
+ } else {
+ size = dict_set_bin (xattr, trav->key, array,
+ trav->value->len);
- trav = trav->next;
+ if (size != 0) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "%s: key=%s (%s)", loc->path,
+ trav->key, strerror (-size));
+ op_ret = -1;
+ op_errno = EINVAL;
+ goto out;
+ }
+ array = NULL;
+ }
+
array = NULL;
+ trav = trav->next;
}
-
+
out:
if (array)
FREE (array);
-
STACK_UNWIND (frame, op_ret, op_errno, xattr);
return 0;
}
int
-posix_xattrop (call_frame_t *frame, xlator_t *this,
- loc_t *loc, gf_xattrop_flags_t optype, dict_t *xattr)
+posix_fxattrop (call_frame_t *frame, xlator_t *this,
+ fd_t *fd, gf_xattrop_flags_t optype, dict_t *xattr)
{
- xattr_cache_handle_t handle = {{0,}, 0};
- int ret = -1;
+ int32_t *array = NULL;
+ int size = 0;
+ int count = 0;
+
+ int op_ret = 0;
+ int op_errno = 0;
+
+ int _fd = -1;
+ struct posix_fd *pfd = NULL;
+
+ data_pair_t *trav = NULL;
+ int32_t ret = -1;
+
+ VALIDATE_OR_GOTO (frame, out);
+ VALIDATE_OR_GOTO (xattr, out);
+ VALIDATE_OR_GOTO (this, out);
- loc_copy (&handle.loc, loc);
- {
- ret = posix_xattrop_common (frame, this, &handle, optype, xattr);
+ trav = xattr->members_list;
+
+ if (fd) {
+ ret = fd_ctx_get (fd, this, (uint64_t *)&pfd);
+ if (ret < 0) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "failed to get pfd from fd=%p",
+ fd);
+ op_ret = -1;
+ op_errno = EBADFD;
+ goto out;
+ }
+ _fd = pfd->fd;
}
- loc_wipe (&handle.loc);
- return ret;
-}
+ while (trav) {
+ count = trav->value->len / sizeof (int32_t);
+ array = CALLOC (count, sizeof (int32_t));
+
+ size = fgetxattr (_fd, trav->key, (char *)array, trav->value->len);
+ op_errno = errno;
+ if ((size == -1) && ((op_errno != ENODATA) &&
+ (op_errno != ENOATTR))) {
+ if (op_errno == ENOTSUP) {
+ GF_LOG_OCCASIONALLY(gf_posix_xattr_enotsup_log,
+ this->name,GF_LOG_WARNING,
+ "extended attributes not "
+ "supported by filesystem");
+ } else {
+ gf_log (this->name, GF_LOG_ERROR,
+ "%d: %s", _fd,
+ strerror (op_errno));
+ }
+ goto out;
+ }
-int
-posix_fxattrop (call_frame_t *frame, xlator_t *this,
- fd_t *fd, gf_xattrop_flags_t optype, dict_t *xattr)
-{
- int ret = -1;
- xattr_cache_handle_t handle = {{0,}, 0};
-
- handle.fd = fd;
+ switch (optype) {
+ case GF_XATTROP_ADD_ARRAY:
+ __add_array (array, (int32_t *) trav->value->data,
+ trav->value->len / 4);
+ break;
+ default:
+ gf_log (this->name, GF_LOG_ERROR,
+ "unknown xattrop type %d. fd=%d",
+ optype, _fd);
+ op_ret = -1;
+ op_errno = EINVAL;
+ goto out;
+ }
- ret = posix_xattrop_common (frame, this, &handle, optype, xattr);
+ size = fsetxattr (_fd, trav->key, (char *)array,
+ trav->value->len, 0);
- return ret;
+ op_errno = errno;
+ if (size == -1) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "%d: key=%s (%s)", _fd,
+ trav->key, strerror (op_errno));
+ op_ret = -1;
+ goto out;
+ } else {
+ size = dict_set_bin (xattr, trav->key, array,
+ trav->value->len);
+
+ if (size != 0) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "%d: key=%s (%s)", _fd,
+ trav->key, strerror (-size));
+ op_ret = -1;
+ op_errno = EINVAL;
+ goto out;
+ }
+ array = NULL;
+ }
+
+ array = NULL;
+ trav = trav->next;
+ }
+
+out:
+ if (array)
+ FREE (array);
+ STACK_UNWIND (frame, op_ret, op_errno, xattr);
+ return 0;
}
@@ -2961,8 +3030,6 @@ posix_setdents (call_frame_t *frame, xlator_t *this,
strcpy (entry_path, real_path);
entry_path[real_path_len] = '/';
- posix_xattr_cache_flush_all (this);
-
/* fd exists, and everything looks fine */
/**
* create an entry for each one present in '@entries'
@@ -3563,14 +3630,6 @@ init (xlator_t *this)
_private->base_path_length = strlen (_private->base_path);
_private->base_stdev = buf.st_dev;
- _private->xattr_cache = posix_xattr_cache_init (16);
- if (!_private->xattr_cache) {
- gf_log (this->name, GF_LOG_ERROR,
- "out of memory :(");
- ret = -1;
- goto out;
- }
-
{
/* Stats related variables */
gettimeofday (&_private->init_time, NULL);
diff --git a/xlators/storage/posix/src/posix.h b/xlators/storage/posix/src/posix.h
index b162139c955..8bad6fd3006 100644
--- a/xlators/storage/posix/src/posix.h
+++ b/xlators/storage/posix/src/posix.h
@@ -50,8 +50,6 @@
#include "inode.h"
#include "compat.h"
-#include "xattr-cache.h"
-
/**
* posix_fd - internal structure common to file and directory fd's
*/
@@ -68,8 +66,6 @@ struct posix_private {
int32_t base_path_length;
dev_t base_stdev;
- xattr_cache_t *xattr_cache;
-
/* Statistics, provides activity of the server */
struct xlator_stats stats;
diff --git a/xlators/storage/posix/src/xattr-cache.c b/xlators/storage/posix/src/xattr-cache.c
deleted file mode 100644
index 0af4e353625..00000000000
--- a/xlators/storage/posix/src/xattr-cache.c
+++ /dev/null
@@ -1,539 +0,0 @@
-/*
- Copyright (c) 2009 Z RESEARCH, Inc. <http://www.zresearch.com>
- This file is part of GlusterFS.
-
- GlusterFS is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published
- by the Free Software Foundation; either version 3 of the License,
- or (at your option) any later version.
-
- GlusterFS is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see
- <http://www.gnu.org/licenses/>.
-*/
-
-#include "byte-order.h"
-
-#include "xattr-cache.h"
-#include "posix.h"
-#include "compat-errno.h"
-
-static int
-__hgetxattr (xattr_cache_handle_t *handle, xlator_t *this,
- const char *key, void *value, size_t len)
-{
- char * real_path = NULL;
- struct posix_fd * pfd = NULL;
- uint64_t tmp_pfd = 0;
- int op_ret = -1;
- int ret = -1;
- int _fd = -1;
-
- if (handle->loc.path) {
- MAKE_REAL_PATH (real_path, this, handle->loc.path);
- op_ret = lgetxattr (real_path, key, value, len);
-
- if (op_ret == -1)
- op_ret = -errno;
-
- if (errno == ERANGE) {
- /*
- * xattr array is bigger than expected.
- * This usually happens when user reduces
- * the number of AFR's children but continues
- * to use the old backend.
- */
-
- gf_log (this->name, GF_LOG_WARNING,
- "%s: Have you reduced the number of "
- "cluster/replicate's children but are "
- "continuing to use the same backend? "
- "Please populate the backend freshly "
- "when doing such a migration.",
- strerror (errno));
- }
-
- } else {
- ret = fd_ctx_get (handle->fd, this, &tmp_pfd);
- if (ret < 0) {
- gf_log (this->name, GF_LOG_ERROR,
- "failed to get pfd from fd=%p",
- handle->fd);
- op_ret = -EBADFD;
- goto out;
- }
- pfd = (struct posix_fd *)(long)tmp_pfd;
- _fd = pfd->fd;
-
- op_ret = fgetxattr (_fd, key, value, len);
- if (op_ret == -1)
- op_ret = -errno;
- }
-
-out:
- return op_ret;
-}
-
-
-static int
-__hsetxattr (xattr_cache_handle_t *handle, xlator_t *this,
- const char *key, void *value, size_t len, int flags)
-{
- char * real_path = NULL;
- struct posix_fd * pfd = NULL;
- uint64_t tmp_pfd = 0;
- int op_ret = -1;
- int ret = -1;
- int _fd = -1;
-
- if (handle->loc.path) {
- MAKE_REAL_PATH (real_path, this, handle->loc.path);
-
- op_ret = lsetxattr (real_path, key, value, len, flags);
- if (op_ret == -1)
- op_ret = -errno;
- } else {
- ret = fd_ctx_get (handle->fd, this, &tmp_pfd);
- if (ret < 0) {
- gf_log (this->name, GF_LOG_ERROR,
- "failed to get pfd from fd=%p",
- handle->fd);
-
- op_ret = -EBADFD;
- goto out;
- }
- pfd = (struct posix_fd *)(long)tmp_pfd;
-
- _fd = pfd->fd;
-
- op_ret = fsetxattr (_fd, key, value, len, flags);
- if (op_ret == -1)
- op_ret = -errno;
- }
-
-out:
- return op_ret;
-}
-
-
-static xattr_cache_entry_t *
-__cache_lookup (xattr_cache_t *cache, inode_t *inode, char *key)
-{
- int i = 0;
-
- for (i = 0; i < cache->size; i++) {
- if ((cache->entries[i]->inode == inode)
- && (!strcmp (cache->entries[i]->key, key))) {
- cache->entries[i]->nraccess++;
- return cache->entries[i];
- }
- }
-
- return NULL;
-}
-
-
-static xattr_cache_entry_t *
-__cache_least_used_entry (xattr_cache_t *cache)
-{
- xattr_cache_entry_t *lue = cache->entries[0];
- int i;
-
- for (i = 0; i < cache->size; i++) {
- if (cache->entries[i]->nraccess < lue->nraccess)
- lue = cache->entries[i];
- }
-
- lue->nraccess++;
- return lue;
-}
-
-
-static inode_t *
-__inode_for_handle (xattr_cache_handle_t *handle)
-{
- inode_t *inode = NULL;
-
- if (handle->loc.path)
- inode = handle->loc.inode;
- else if (handle->fd)
- inode = handle->fd->inode;
-
- return inode;
-}
-
-
-static void
-__free_handle (xattr_cache_handle_t *handle)
-{
- if (handle->loc.path)
- loc_wipe (&handle->loc);
-
- FREE (handle);
-}
-
-
-static xattr_cache_handle_t *
-__copy_handle (xattr_cache_handle_t *handle)
-{
- xattr_cache_handle_t *hnew = calloc (1, sizeof (xattr_cache_handle_t));
-
- if (handle->loc.path)
- loc_copy (&hnew->loc, &handle->loc);
- else
- hnew->fd = handle->fd;
-
- return hnew;
-}
-
-
-static int
-__cache_populate_entry (xattr_cache_entry_t *entry, xlator_t *this,
- xattr_cache_handle_t *handle, char *key, size_t len)
-{
- int op_ret = -1;
-
- entry->array = calloc (1, len);
- if (!entry->array) {
- op_ret = -ENOMEM;
- goto out;
- }
-
- op_ret = __hgetxattr (handle, this, key, entry->array, len);
-
- entry->key = strdup (key);
- entry->inode = __inode_for_handle (handle);
- entry->handle = __copy_handle (handle);
- entry->len = len;
- entry->nraccess = 1;
-
-out:
- return op_ret;
-}
-
-
-static int
-__cache_flush_entry (xattr_cache_entry_t *entry, xlator_t *this)
-{
- int ret = -1;
-
- if (entry->dirty) {
- ret = __hsetxattr (entry->handle, this,
- entry->key, entry->array, entry->len, 0);
- }
-
- entry->len = 0;
- entry->nraccess = 0;
- entry->dirty = 0;
- entry->inode = NULL;
-
- if (entry->key) {
- FREE (entry->key);
- entry->key = NULL;
- }
-
- if (entry->array) {
- FREE (entry->array);
- entry->array = NULL;
- }
-
- if (entry->handle) {
- __free_handle (entry->handle);
- entry->handle = NULL;
- }
-
- return 0;
-}
-
-
-static void
-__print_array (char *str, xlator_t *this, int32_t *array, size_t len)
-{
- char *ptr = NULL;
- char *buf = NULL;
-
- int i, count = -1;
-
- count = len / sizeof (int32_t);
-
- /* 10 digits per entry + 1 space + '[' and ']' */
- buf = malloc (count * 11 + 8);
-
- ptr = buf;
- ptr += sprintf (ptr, "[ ");
- for (i = 0; i < count; i++)
- ptr += sprintf (ptr, "%d ", ntoh32 (array[i]));
- ptr += sprintf (ptr, "]");
-
- gf_log (this->name, GF_LOG_DEBUG,
- "%s%s", str, buf);
-
- FREE (buf);
-}
-
-
-int
-posix_xattr_cache_read (xlator_t *this, xattr_cache_handle_t *handle,
- char *key, int32_t *array, size_t len)
-{
- xattr_cache_entry_t *entry = NULL;
- xattr_cache_entry_t *purgee = NULL;
-
- xattr_cache_t *cache = NULL;
- inode_t *inode = NULL;
-
- int op_ret = -1;
-
- inode = __inode_for_handle (handle);
-
- if (!inode) {
- gf_log (this->name, GF_LOG_DEBUG,
- "handle has no inode!");
- goto out;
- }
-
- cache = ((struct posix_private *) (this->private))->xattr_cache;
-
- pthread_mutex_lock (&cache->lock);
- {
- entry = __cache_lookup (cache, inode, key);
-
- if (entry) {
- if (handle->loc.path)
- gf_log (this->name, GF_LOG_DEBUG,
- "cache hit for %s", handle->loc.path);
- else if (handle->fd)
- gf_log (this->name, GF_LOG_DEBUG,
- "cache hit for fd=%p", handle->fd);
- }
-
- if (!entry) {
- purgee = __cache_least_used_entry (cache);
-
- if (purgee->handle && purgee->handle->loc.path)
- gf_log (this->name, GF_LOG_DEBUG,
- "flushing and purging entry for %s",
- purgee->handle->loc.path);
- else if (purgee->handle && purgee->handle->fd)
- gf_log (this->name, GF_LOG_DEBUG,
- "flushing and purging entry for fd=%p",
- purgee->handle->fd);
- __cache_flush_entry (purgee, this);
-
- if (handle->loc.path)
- gf_log (this->name, GF_LOG_DEBUG,
- "populating entry for %s",
- handle->loc.path);
- else if (handle->fd)
- gf_log (this->name, GF_LOG_DEBUG,
- "populating entry for fd=%p",
- handle->fd);
- __cache_populate_entry (purgee, this, handle, key, len);
-
- entry = purgee;
- }
-
- memcpy (array, entry->array, len);
-
- __print_array ("read array: ", this, array, len);
- }
- pthread_mutex_unlock (&cache->lock);
-
- op_ret = 0;
-out:
- return op_ret;
-}
-
-
-int posix_xattr_cache_write (xlator_t *this, xattr_cache_handle_t *handle,
- char *key, int32_t *array, size_t len)
-{
- xattr_cache_t * cache = NULL;
- xattr_cache_entry_t * entry = NULL;
-
- inode_t *inode = NULL;
-
- int op_ret = -1;
-
- inode = __inode_for_handle (handle);
-
- if (!inode) {
- gf_log (this->name, GF_LOG_DEBUG,
- "handle has no inode!");
- goto out;
- }
-
- cache = ((struct posix_private *) (this->private))->xattr_cache;
-
- pthread_mutex_lock (&cache->lock);
- {
- entry = __cache_lookup (cache, inode, key);
-
- if (entry) {
- entry->dirty = 1;
- memcpy (entry->array, array, len);
- } else {
- /*
- * This case shouldn't usually happen, since the
- * entry should have been brought into the cache
- * by the previous read (xattrop always does a read &
- * write).
- *
- * If we've reached here, it means things are happening
- * very quickly and the entry was flushed after read
- * but before this write. In that case, let's just
- * write this to disk
- */
-
- op_ret = __hsetxattr (handle, this, key, array,
- len, 0);
- }
-
- __print_array ("wrote array: ", this, array, len);
- }
- pthread_mutex_unlock (&cache->lock);
-
- op_ret = 0;
-out:
- return op_ret;
-}
-
-
-int posix_xattr_cache_flush (xlator_t *this, xattr_cache_handle_t *handle)
-{
- xattr_cache_t *cache = NULL;
- xattr_cache_entry_t *entry = NULL;
-
- int i;
- inode_t *inode = NULL;
-
- int op_ret = -1;
-
- inode = __inode_for_handle (handle);
- if (!inode) {
- gf_log (this->name, GF_LOG_DEBUG,
- "handle has no inode!");
- op_ret = -EINVAL;
- goto out;
- }
-
- cache = ((struct posix_private *) (this->private))->xattr_cache;
-
- pthread_mutex_lock (&cache->lock);
- {
- for (i = 0; i < cache->size; i++) {
- entry = cache->entries[i];
-
- if (entry->inode == inode) {
- if (entry->handle->loc.path)
- gf_log (this->name, GF_LOG_DEBUG,
- "force flushing entry for %s",
- entry->handle->loc.path);
-
- else if (cache->entries[i]->handle->fd)
- gf_log (this->name, GF_LOG_DEBUG,
- "force flushing entry for fd=%p",
- entry->handle->fd);
-
- __cache_flush_entry (entry, this);
- }
- }
- }
- pthread_mutex_unlock (&cache->lock);
-
- op_ret = 0;
-out:
- return op_ret;
-}
-
-
-int
-posix_xattr_cache_flush_all (xlator_t *this)
-{
- xattr_cache_t *cache = NULL;
- xattr_cache_entry_t *entry = NULL;
-
- int i;
- int op_ret = 0;
-
- cache = ((struct posix_private *) (this->private))->xattr_cache;
-
- pthread_mutex_lock (&cache->lock);
- {
- gf_log (this->name, GF_LOG_DEBUG,
- "flushing entire xattr cache: ");
-
- for (i = 0; i < cache->size; i++) {
- entry = cache->entries[i];
-
- if (!entry || !entry->handle)
- continue;
-
- if (entry->handle->loc.path)
- gf_log (this->name, GF_LOG_DEBUG,
- " force flushing entry for %s",
- entry->handle->loc.path);
-
- else if (cache->entries[i]->handle->fd)
- gf_log (this->name, GF_LOG_DEBUG,
- " force flushing entry for fd=%p",
- entry->handle->fd);
-
- __cache_flush_entry (entry, this);
- }
- }
- pthread_mutex_unlock (&cache->lock);
-
- return op_ret;
-}
-
-
-xattr_cache_t *
-posix_xattr_cache_init (size_t size)
-{
- int i = 0;
- xattr_cache_t * cache = NULL;
- int op_ret = -1;
-
- cache = CALLOC (1, sizeof (xattr_cache_t));
- if (!cache) {
- goto out;
- }
-
- cache->entries = CALLOC (size, sizeof (xattr_cache_entry_t *));
- if (!cache->entries)
- goto out;
-
- cache->size = size;
-
- for (i = 0; i < size; i++) {
- cache->entries[i] = calloc (1, sizeof (xattr_cache_entry_t));
- if (!cache->entries[i])
- goto out;
- }
-
- pthread_mutex_init (&cache->lock, NULL);
-
- op_ret = 0;
-out:
- if (op_ret == -1) {
- if (cache) {
- if (cache->entries) {
- for (i = 0; i < size; i++)
- if (cache->entries[i])
- FREE (cache->entries[i]);
-
- FREE (cache->entries);
- }
-
- FREE (cache);
- }
- }
-
- return cache;
-}
diff --git a/xlators/storage/posix/src/xattr-cache.h b/xlators/storage/posix/src/xattr-cache.h
deleted file mode 100644
index 3e12742a90f..00000000000
--- a/xlators/storage/posix/src/xattr-cache.h
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- Copyright (c) 2009 Z RESEARCH, Inc. <http://www.zresearch.com>
- This file is part of GlusterFS.
-
- GlusterFS is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published
- by the Free Software Foundation; either version 3 of the License,
- or (at your option) any later version.
-
- GlusterFS is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see
- <http://www.gnu.org/licenses/>.
-*/
-
-#ifndef __XATTR_CACHE_H__
-#define __XATTR_CACHE_H__
-
-
-#include "glusterfs.h"
-#include "inode.h"
-
-typedef struct __xattr_cache_handle {
- loc_t loc;
- fd_t *fd;
-} xattr_cache_handle_t;
-
-
-typedef struct __xattr_cache_entry {
- char *key; /* name of the xattr */
- int32_t *array; /* value */
- size_t len; /* length of array in bytes */
- inode_t *inode; /* inode for which the entry is for */
-
- xattr_cache_handle_t *handle;
- unsigned char dirty;
- unsigned long nraccess; /* number of times accessed */
-} xattr_cache_entry_t;
-
-
-typedef struct __xattr_cache {
- size_t size;
- pthread_mutex_t lock;
- xattr_cache_entry_t **entries;
-} xattr_cache_t;
-
-
-xattr_cache_t * posix_xattr_cache_init (size_t size);
-
-int posix_xattr_cache_read (xlator_t *this, xattr_cache_handle_t *handle,
- char *key, int32_t *array, size_t len);
-
-int posix_xattr_cache_write (xlator_t *this, xattr_cache_handle_t *handle,
- char *key, int32_t *array, size_t len);
-
-int posix_xattr_cache_flush (xlator_t *this, xattr_cache_handle_t *handle);
-
-int posix_xattr_cache_flush_all (xlator_t *this);
-
-
-#endif /* __XATTR_CACHE_H__ */