summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--xlators/performance/quick-read/src/quick-read.c137
-rw-r--r--xlators/performance/quick-read/src/quick-read.h10
2 files changed, 147 insertions, 0 deletions
diff --git a/xlators/performance/quick-read/src/quick-read.c b/xlators/performance/quick-read/src/quick-read.c
index 4e85e6f377f..0e1ef147bfc 100644
--- a/xlators/performance/quick-read/src/quick-read.c
+++ b/xlators/performance/quick-read/src/quick-read.c
@@ -19,6 +19,142 @@
#include "quick-read.h"
+
+int32_t
+qr_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, inode_t *inode,
+ struct stat *buf, dict_t *dict)
+{
+ data_t *content = NULL;
+ qr_file_t *qr_file = NULL;
+ uint64_t value = 0;
+ int ret = -1;
+ qr_conf_t *conf = NULL;
+
+ if ((op_ret == -1) || (dict == NULL)) {
+ goto out;
+ }
+
+ conf = this->private;
+
+ content = dict_get (dict, GLUSTERFS_CONTENT_KEY);
+ if (content == NULL) {
+ goto out;
+ }
+
+ if (buf->st_size > conf->max_file_size) {
+ goto out;
+ }
+
+ if (S_ISDIR (buf->st_mode)) {
+ goto out;
+ }
+
+ ret = inode_ctx_get (inode, this, &value);
+ if (ret == -1) {
+ qr_file = CALLOC (1, sizeof (*qr_file));
+ if (qr_file == NULL) {
+ op_ret = -1;
+ op_errno = ENOMEM;
+ goto out;
+ }
+
+ LOCK_INIT (&qr_file->lock);
+ inode_ctx_put (inode, this, (uint64_t)(long)qr_file);
+ } else {
+ qr_file = (qr_file_t *)(long)value;
+ if (qr_file == NULL) {
+ op_ret = -1;
+ op_errno = EINVAL;
+ goto out;
+ }
+ }
+
+ LOCK (&qr_file->lock);
+ {
+ if (qr_file->xattr) {
+ dict_unref (qr_file->xattr);
+ qr_file->xattr = NULL;
+ }
+
+ qr_file->xattr = dict_ref (dict);
+ qr_file->stbuf = *buf;
+ gettimeofday (&qr_file->tv, NULL);
+ }
+ UNLOCK (&qr_file->lock);
+
+out:
+ STACK_UNWIND (frame, op_ret, op_errno, inode, buf, dict);
+ return 0;
+}
+
+
+int32_t
+qr_lookup (call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xattr_req)
+{
+ qr_conf_t *conf = NULL;
+ dict_t *new_req_dict = NULL;
+ int32_t op_ret = -1, op_errno = -1;
+ data_t *content = NULL;
+ uint64_t requested_size = 0, size = 0;
+
+ conf = this->private;
+ if (conf == NULL) {
+ op_ret = -1;
+ op_errno = EINVAL;
+ goto unwind;
+ }
+
+ if ((xattr_req == NULL) && (conf->max_file_size > 0)) {
+ new_req_dict = xattr_req = dict_new ();
+ if (xattr_req == NULL) {
+ op_ret = -1;
+ op_errno = ENOMEM;
+ gf_log (this->name, GF_LOG_ERROR, "out of memory");
+ goto unwind;
+ }
+ }
+
+ if (xattr_req) {
+ content = dict_get (xattr_req, GLUSTERFS_CONTENT_KEY);
+ if (content) {
+ requested_size = data_to_uint64 (content);
+ }
+ }
+
+ if (((conf->max_file_size > 0) && (content == NULL))
+ || (conf->max_file_size != requested_size)) {
+ size = (conf->max_file_size > requested_size) ?
+ conf->max_file_size : requested_size;
+
+ op_ret = dict_set (xattr_req, GLUSTERFS_CONTENT_KEY,
+ data_from_uint64 (size));
+ if (op_ret < 0) {
+ op_ret = -1;
+ op_errno = ENOMEM;
+ goto unwind;
+ }
+ }
+
+ STACK_WIND (frame, qr_lookup_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->lookup, loc, xattr_req);
+
+ if (new_req_dict) {
+ dict_unref (new_req_dict);
+ }
+
+ return 0;
+
+unwind:
+ STACK_UNWIND (frame, op_ret, op_errno, NULL, NULL, NULL);
+
+ if (new_req_dict) {
+ dict_unref (new_req_dict);
+ }
+
+ return 0;
+}
+
int32_t
init (xlator_t *this)
@@ -92,6 +228,7 @@ fini (xlator_t *this)
struct xlator_fops fops = {
+ .lookup = qr_lookup,
};
diff --git a/xlators/performance/quick-read/src/quick-read.h b/xlators/performance/quick-read/src/quick-read.h
index d3f4ecf0ca2..44db762437b 100644
--- a/xlators/performance/quick-read/src/quick-read.h
+++ b/xlators/performance/quick-read/src/quick-read.h
@@ -41,6 +41,16 @@
#include <sys/stat.h>
#include <unistd.h>
+#define GLUSTERFS_CONTENT_KEY "glusterfs.content"
+
+struct qr_file {
+ dict_t *xattr;
+ struct stat stbuf;
+ struct timeval tv;
+ gf_lock_t lock;
+};
+typedef struct qr_file qr_file_t;
+
struct qr_conf {
uint64_t max_file_size;
int32_t cache_timeout;