diff options
Diffstat (limited to 'xlators/performance')
-rw-r--r-- | xlators/performance/md-cache/src/md-cache.c | 80 | ||||
-rw-r--r-- | xlators/performance/quick-read/src/quick-read.c | 21 |
2 files changed, 94 insertions, 7 deletions
diff --git a/xlators/performance/md-cache/src/md-cache.c b/xlators/performance/md-cache/src/md-cache.c index 9ef599ad8ba..5fcb583db27 100644 --- a/xlators/performance/md-cache/src/md-cache.c +++ b/xlators/performance/md-cache/src/md-cache.c @@ -441,12 +441,70 @@ out: return ret; } +struct updatedict { + dict_t *dict; + int ret; +}; + +static void +updatefn(dict_t *dict, char *key, data_t *value, void *data) +{ + struct updatedict *u = data; + const char *mdc_key; + int i = 0; + + for (mdc_key = mdc_keys[i].name; (mdc_key = mdc_keys[i].name); i++) { + if (!mdc_keys[i].check) + continue; + if (strcmp(mdc_key, key)) + continue; + + if (!u->dict) { + u->dict = dict_new(); + if (!u->dict) { + u->ret = -1; + return; + } + } + + if (dict_set(u->dict, key, value) < 0) { + u->ret = -1; + return; + } + + break; + } +} + +static int +mdc_dict_update(dict_t **tgt, dict_t *src) +{ + struct updatedict u = { + .dict = *tgt, + .ret = 0, + }; + + dict_foreach(src, updatefn, &u); + + if (*tgt) + return u.ret; + + if ((u.ret < 0) && u.dict) { + dict_unref(u.dict); + return u.ret; + } + + *tgt = u.dict; + + return u.ret; +} int mdc_inode_xatt_set (xlator_t *this, inode_t *inode, dict_t *dict) { int ret = -1; struct md_cache *mdc = NULL; + dict_t *newdict = NULL; mdc = mdc_inode_prep (this, inode); if (!mdc) @@ -457,10 +515,19 @@ mdc_inode_xatt_set (xlator_t *this, inode_t *inode, dict_t *dict) LOCK (&mdc->lock); { - if (mdc->xattr) + if (mdc->xattr) { dict_unref (mdc->xattr); + mdc->xattr = NULL; + } + + ret = mdc_dict_update(&newdict, dict); + if (ret < 0) { + UNLOCK(&mdc->lock); + goto out; + } - mdc->xattr = dict_ref (dict); + if (newdict) + mdc->xattr = newdict; time (&mdc->xa_time); } @@ -486,10 +553,11 @@ mdc_inode_xatt_update (xlator_t *this, inode_t *inode, dict_t *dict) LOCK (&mdc->lock); { - if (!mdc->xattr) - mdc->xattr = dict_ref (dict); - else - dict_copy (dict, mdc->xattr); + ret = mdc_dict_update(&mdc->xattr, dict); + if (ret < 0) { + UNLOCK(&mdc->lock); + goto out; + } time (&mdc->xa_time); } diff --git a/xlators/performance/quick-read/src/quick-read.c b/xlators/performance/quick-read/src/quick-read.c index beddfd878a8..000dcb45400 100644 --- a/xlators/performance/quick-read/src/quick-read.c +++ b/xlators/performance/quick-read/src/quick-read.c @@ -429,13 +429,32 @@ qr_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this, } } + /* + * Create our own internal dict and migrate the file content + * over to it so it isn't floating around in other translator + * caches. + */ if (qr_inode->xattr) { dict_unref (qr_inode->xattr); qr_inode->xattr = NULL; table->cache_used -= qr_inode->stbuf.ia_size; } - qr_inode->xattr = dict_ref (xdata); + qr_inode->xattr = dict_new(); + if (!qr_inode->xattr) { + op_ret = -1; + op_errno = ENOMEM; + goto unlock; + } + + if (dict_set(qr_inode->xattr, GF_CONTENT_KEY, content) < 0) { + op_ret = -1; + op_errno = ENOMEM; + goto unlock; + } + + dict_del(xdata, GF_CONTENT_KEY); + qr_inode->stbuf = *buf; table->cache_used += buf->ia_size; |