*
* You should have received a copy of the GNU General Public License
* version 2 along with this program; If not, see
- * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
+ * http://www.gnu.org/licenses/gpl-2.0.html
*
* GPL HEADER END
*/
* Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
* Use is subject to license terms.
*
- * Copyright (c) 2012, 2015, Intel Corporation.
+ * Copyright (c) 2012, 2016, Intel Corporation.
*/
/*
* lustre/osp/osp_object.c
* char oxe_buf[0];
* };
*
- * struct osp_object_attr {
- * struct lu_attr ooa_attr;
- * struct list_head ooa_xattr_list;
- * };
- *
* struct osp_object {
* ...
- * struct osp_object_attr *opo_ooa;
+ * struct lu_attr opo_attr;
+ * struct list_head opo_xattr_list;
* spinlock_t opo_lock;
* ...
* };
*
* The basic attributes, such as owner/mode/flags, are stored in the
- * osp_object_attr::ooa_attr. The extended attributes will be stored
+ * osp_object::opo_attr. The extended attributes will be stored
* as osp_xattr_entry. Every extended attribute has an independent
* osp_xattr_entry, and all the osp_xattr_entry are linked into the
- * osp_object_attr::ooa_xattr_list. The OSP object attributes cache
+ * osp_object::opo_xattr_list. The OSP object attributes cache
* is protected by the osp_object::opo_lock.
*
* Not all OSP objects have an attributes cache because maintaining
#define DEBUG_SUBSYSTEM S_MDS
+#include <lustre_obdo.h>
+#include <lustre_swab.h>
+
#include "osp_internal.h"
static inline __u32 osp_dev2node(struct osp_device *osp)
}
/**
- * Initialize the OSP object attributes cache.
- *
- * \param[in] obj pointer to the OSP object
- *
- * \retval 0 for success
- * \retval negative error number on failure
- */
-int osp_oac_init(struct osp_object *obj)
-{
- struct osp_object_attr *ooa;
-
- OBD_ALLOC_PTR(ooa);
- if (ooa == NULL)
- return -ENOMEM;
-
- INIT_LIST_HEAD(&ooa->ooa_xattr_list);
- spin_lock(&obj->opo_lock);
- if (likely(obj->opo_ooa == NULL)) {
- obj->opo_ooa = ooa;
- spin_unlock(&obj->opo_lock);
- } else {
- spin_unlock(&obj->opo_lock);
- OBD_FREE_PTR(ooa);
- }
-
- return 0;
-}
-
-/**
* Find the named extended attribute in the OSP object attributes cache.
*
* The caller should take the osp_object::opo_lock before calling
* this function.
*
- * \param[in] ooa pointer to the OSP object attributes cache
+ * \param[in] obj pointer to the OSP object
* \param[in] name the name of the extended attribute
* \param[in] namelen the name length of the extended attribute
*
* in the cache
*/
static struct osp_xattr_entry *
-osp_oac_xattr_find_locked(struct osp_object_attr *ooa,
- const char *name, size_t namelen)
+osp_oac_xattr_find_locked(struct osp_object *obj, const char *name,
+ size_t namelen)
{
struct osp_xattr_entry *oxe;
- list_for_each_entry(oxe, &ooa->ooa_xattr_list, oxe_list) {
+ list_for_each_entry(oxe, &obj->opo_xattr_list, oxe_list) {
if (namelen == oxe->oxe_namelen &&
strncmp(name, oxe->oxe_buf, namelen) == 0)
return oxe;
struct osp_xattr_entry *oxe = NULL;
spin_lock(&obj->opo_lock);
- if (obj->opo_ooa != NULL) {
- oxe = osp_oac_xattr_find_locked(obj->opo_ooa, name,
- strlen(name));
- if (oxe != NULL) {
- if (unlink)
- list_del_init(&oxe->oxe_list);
- else
- atomic_inc(&oxe->oxe_ref);
- }
+ oxe = osp_oac_xattr_find_locked(obj, name, strlen(name));
+ if (oxe != NULL) {
+ if (unlink)
+ list_del_init(&oxe->oxe_list);
+ else
+ atomic_inc(&oxe->oxe_ref);
}
spin_unlock(&obj->opo_lock);
static struct osp_xattr_entry *
osp_oac_xattr_find_or_add(struct osp_object *obj, const char *name, size_t len)
{
- struct osp_object_attr *ooa = obj->opo_ooa;
struct osp_xattr_entry *oxe;
struct osp_xattr_entry *tmp = NULL;
size_t namelen = strlen(name);
size_t size = sizeof(*oxe) + namelen + 1 + len;
- LASSERT(ooa != NULL);
-
oxe = osp_oac_xattr_find(obj, name, false);
if (oxe != NULL)
return oxe;
atomic_set(&oxe->oxe_ref, 2);
spin_lock(&obj->opo_lock);
- tmp = osp_oac_xattr_find_locked(ooa, name, namelen);
+ tmp = osp_oac_xattr_find_locked(obj, name, namelen);
if (tmp == NULL)
- list_add_tail(&oxe->oxe_list, &ooa->ooa_xattr_list);
+ list_add_tail(&oxe->oxe_list, &obj->opo_xattr_list);
else
atomic_inc(&tmp->oxe_ref);
spin_unlock(&obj->opo_lock);
osp_oac_xattr_replace(struct osp_object *obj,
struct osp_xattr_entry **poxe, size_t len)
{
- struct osp_object_attr *ooa = obj->opo_ooa;
struct osp_xattr_entry *oxe;
size_t namelen = (*poxe)->oxe_namelen;
size_t size = sizeof(*oxe) + namelen + 1 + len;
- LASSERT(ooa != NULL);
-
OBD_ALLOC(oxe, size);
if (unlikely(oxe == NULL))
return NULL;
atomic_set(&oxe->oxe_ref, 2);
spin_lock(&obj->opo_lock);
- *poxe = osp_oac_xattr_find_locked(ooa, oxe->oxe_buf, namelen);
+ *poxe = osp_oac_xattr_find_locked(obj, oxe->oxe_buf, namelen);
LASSERT(*poxe != NULL);
list_del_init(&(*poxe)->oxe_list);
- list_add_tail(&oxe->oxe_list, &ooa->ooa_xattr_list);
+ list_add_tail(&oxe->oxe_list, &obj->opo_xattr_list);
spin_unlock(&obj->opo_lock);
return oxe;
lustre_get_wire_obdo(NULL, lobdo, wobdo);
spin_lock(&obj->opo_lock);
- if (obj->opo_ooa != NULL) {
- la_from_obdo(&obj->opo_ooa->ooa_attr, lobdo, lobdo->o_valid);
- if (attr != NULL)
- *attr = obj->opo_ooa->ooa_attr;
- } else {
- LASSERT(attr != NULL);
-
- la_from_obdo(attr, lobdo, lobdo->o_valid);
- }
+ la_from_obdo(&obj->opo_attr, lobdo, lobdo->o_valid);
+ if (attr != NULL)
+ *attr = obj->opo_attr;
spin_unlock(&obj->opo_lock);
return 0;
{
struct lu_attr *attr = data;
- LASSERT(obj->opo_ooa != NULL);
-
if (rc == 0) {
osp2lu_obj(obj)->lo_header->loh_attr |= LOHA_EXISTS;
obj->opo_non_exist = 0;
struct osp_device *osp = lu2osp_dev(dt->do_lu.lo_dev);
int rc = 0;
- if (obj->opo_ooa == NULL) {
- rc = osp_oac_init(obj);
- if (rc != 0)
- return rc;
- }
-
mutex_lock(&osp->opd_async_requests_mutex);
rc = osp_insert_async_request(env, OUT_ATTR_GET, obj, 0, NULL, NULL,
- &obj->opo_ooa->ooa_attr,
+ &obj->opo_attr, sizeof(struct obdo),
osp_attr_get_interpterer);
mutex_unlock(&osp->opd_async_requests_mutex);
if (is_ost_obj(&dt->do_lu) && obj->opo_non_exist)
RETURN(-ENOENT);
- if (obj->opo_ooa != NULL) {
- spin_lock(&obj->opo_lock);
- if (obj->opo_ooa->ooa_attr.la_valid != 0) {
- *attr = obj->opo_ooa->ooa_attr;
- spin_unlock(&obj->opo_lock);
-
- RETURN(0);
- }
+ spin_lock(&obj->opo_lock);
+ if (obj->opo_attr.la_valid != 0 && !obj->opo_stale) {
+ *attr = obj->opo_attr;
spin_unlock(&obj->opo_lock);
+
+ RETURN(0);
}
+ spin_unlock(&obj->opo_lock);
update = osp_update_request_create(dev);
if (IS_ERR(update))
if (rc != 0)
GOTO(out, rc);
- GOTO(out, rc = 0);
+ spin_lock(&obj->opo_lock);
+ obj->opo_stale = 0;
+ spin_unlock(&obj->opo_lock);
+
+ GOTO(out, rc);
out:
if (req != NULL)
ptlrpc_req_finished(req);
- osp_update_request_destroy(update);
+ osp_update_request_destroy(env, update);
return rc;
}
CDEBUG(D_INFO, "(1) set attr "DFID": rc = %d\n",
PFID(&dt->do_lu.lo_header->loh_fid), rc);
- if (rc != 0 || o->opo_ooa == NULL)
+ if (rc != 0)
RETURN(rc);
/* Update the OSP object attributes cache. */
- la = &o->opo_ooa->ooa_attr;
+ la = &o->opo_attr;
spin_lock(&o->opo_lock);
if (attr->la_valid & LA_UID) {
la->la_uid = attr->la_uid;
struct osp_object *obj,
void *data, int index, int rc)
{
- struct osp_object_attr *ooa = obj->opo_ooa;
struct osp_xattr_entry *oxe = data;
struct lu_buf *rbuf = &osp_env_info(env)->osi_lb2;
- LASSERT(ooa != NULL);
-
if (rc == 0) {
size_t len = sizeof(*oxe) + oxe->oxe_namelen + 1;
struct osp_object *obj = dt2osp_obj(dt);
struct osp_device *osp = lu2osp_dev(dt->do_lu.lo_dev);
struct osp_xattr_entry *oxe;
- __u16 namelen = strlen(name);
+ __u16 namelen;
int rc = 0;
LASSERT(buf != NULL);
LASSERT(name != NULL);
+ namelen = strlen(name);
+
/* If only for xattr size, return directly. */
if (unlikely(buf->lb_len == 0))
return 0;
- if (obj->opo_ooa == NULL) {
- rc = osp_oac_init(obj);
- if (rc != 0)
- return rc;
- }
-
oxe = osp_oac_xattr_find_or_add(obj, name, buf->lb_len);
if (oxe == NULL)
return -ENOMEM;
mutex_lock(&osp->opd_async_requests_mutex);
rc = osp_insert_async_request(env, OUT_XATTR_GET, obj, 1,
- &namelen, (const void **)&name, oxe,
+ &namelen, (const void **)&name,
+ oxe, buf->lb_len,
osp_xattr_get_interpterer);
if (rc != 0) {
mutex_unlock(&osp->opd_async_requests_mutex);
if (unlikely(obj->opo_non_exist))
RETURN(-ENOENT);
- /* Only cache xattr for OST object */
- if (!osp->opd_connect_mdt) {
- oxe = osp_oac_xattr_find(obj, name, false);
- if (oxe != NULL) {
- spin_lock(&obj->opo_lock);
- if (oxe->oxe_ready) {
- if (!oxe->oxe_exist)
- GOTO(unlock, rc = -ENODATA);
+ oxe = osp_oac_xattr_find(obj, name, false);
+ if (oxe != NULL) {
+ spin_lock(&obj->opo_lock);
+ if (oxe->oxe_ready) {
+ if (!oxe->oxe_exist)
+ GOTO(unlock, rc = -ENODATA);
- if (buf->lb_buf == NULL)
- GOTO(unlock, rc = oxe->oxe_vallen);
+ if (buf->lb_buf == NULL)
+ GOTO(unlock, rc = oxe->oxe_vallen);
- if (buf->lb_len < oxe->oxe_vallen)
- GOTO(unlock, rc = -ERANGE);
+ if (buf->lb_len < oxe->oxe_vallen)
+ GOTO(unlock, rc = -ERANGE);
- memcpy(buf->lb_buf, oxe->oxe_value,
- oxe->oxe_vallen);
+ memcpy(buf->lb_buf, oxe->oxe_value,
+ oxe->oxe_vallen);
- GOTO(unlock, rc = oxe->oxe_vallen);
+ GOTO(unlock, rc = oxe->oxe_vallen);
unlock:
- spin_unlock(&obj->opo_lock);
- osp_oac_xattr_put(oxe);
-
- return rc;
- }
spin_unlock(&obj->opo_lock);
+ osp_oac_xattr_put(oxe);
+
+ return rc;
}
+ spin_unlock(&obj->opo_lock);
}
update = osp_update_request_create(dev);
if (IS_ERR(update))
GOTO(out, rc = PTR_ERR(update));
rc = osp_update_rpc_pack(env, xattr_get, update, OUT_XATTR_GET,
- lu_object_fid(&dt->do_lu), name);
+ lu_object_fid(&dt->do_lu), name, buf->lb_len);
if (rc != 0) {
CERROR("%s: Insert update error "DFID": rc = %d\n",
dname, PFID(lu_object_fid(&dt->do_lu)), rc);
}
rc = osp_remote_sync(env, osp, update, &req);
- if (rc != 0) {
+ if (rc < 0) {
if (rc == -ENOENT) {
dt->do_lu.lo_header->loh_attr &= ~LOHA_EXISTS;
obj->opo_non_exist = 1;
}
- if (obj->opo_ooa == NULL)
- GOTO(out, rc);
-
if (oxe == NULL)
oxe = osp_oac_xattr_find_or_add(obj, name, buf->lb_len);
GOTO(out, rc);
if (buf->lb_buf == NULL)
- GOTO(out, rc = rbuf->lb_len);
+ GOTO(out, rc);
if (unlikely(buf->lb_len < rbuf->lb_len))
GOTO(out, rc = -ERANGE);
memcpy(buf->lb_buf, rbuf->lb_buf, rbuf->lb_len);
- rc = rbuf->lb_len;
- if (obj->opo_ooa == NULL || osp->opd_connect_mdt)
- GOTO(out, rc);
if (oxe == NULL) {
oxe = osp_oac_xattr_find_or_add(obj, name, rbuf->lb_len);
ptlrpc_req_finished(req);
if (update != NULL && !IS_ERR(update))
- osp_update_request_destroy(update);
+ osp_update_request_destroy(env, update);
if (oxe != NULL)
osp_oac_xattr_put(oxe);
struct thandle *th)
{
struct osp_object *o = dt2osp_obj(dt);
- struct osp_device *osp = lu2osp_dev(dt->do_lu.lo_dev);
struct osp_update_request *update;
struct osp_xattr_entry *oxe;
int rc;
rc = osp_update_rpc_pack(env, xattr_set, update, OUT_XATTR_SET,
lu_object_fid(&dt->do_lu), buf, name, fl);
- if (rc != 0 || o->opo_ooa == NULL || osp->opd_connect_mdt)
+ if (rc != 0)
RETURN(rc);
+ /* Do not cache linkEA that may be self-adjusted by peers
+ * under EA overflow case. */
+ if (strcmp(name, XATTR_NAME_LINK) == 0) {
+ oxe = osp_oac_xattr_find(o, name, true);
+ if (oxe != NULL)
+ osp_oac_xattr_put(oxe);
+
+ RETURN(0);
+ }
+
oxe = osp_oac_xattr_find_or_add(o, name, buf->lb_len);
if (oxe == NULL) {
CWARN("%s: cannot cache xattr '%s' of "DFID"\n",
rc = osp_update_rpc_pack(env, xattr_del, update, OUT_XATTR_DEL,
fid, name);
- if (rc != 0 || o->opo_ooa == NULL)
+ if (rc != 0)
return rc;
oxe = osp_oac_xattr_find(o, name, true);
return 0;
}
+void osp_obj_invalidate_cache(struct osp_object *obj)
+{
+ struct osp_xattr_entry *oxe;
+ struct osp_xattr_entry *tmp;
+
+ spin_lock(&obj->opo_lock);
+ list_for_each_entry_safe(oxe, tmp, &obj->opo_xattr_list, oxe_list) {
+ oxe->oxe_ready = 0;
+ list_del_init(&oxe->oxe_list);
+ osp_oac_xattr_put(oxe);
+ }
+ obj->opo_attr.la_valid = 0;
+ spin_unlock(&obj->opo_lock);
+}
+
+/**
+ * Implement OSP layer dt_object_operations::do_invalidate() interface.
+ *
+ * Invalidate attributes cached on the specified MDT/OST object.
+ *
+ * \param[in] env pointer to the thread context
+ * \param[in] dt pointer to the OSP layer dt_object
+ *
+ * \retval 0 for success
+ * \retval negative error number on failure
+ */
+int osp_invalidate(const struct lu_env *env, struct dt_object *dt)
+{
+ struct osp_object *obj = dt2osp_obj(dt);
+ ENTRY;
+
+ CDEBUG(D_HA, "Invalidate osp_object "DFID"\n",
+ PFID(lu_object_fid(&dt->do_lu)));
+ osp_obj_invalidate_cache(obj);
+
+ spin_lock(&obj->opo_lock);
+ obj->opo_stale = 1;
+ spin_unlock(&obj->opo_lock);
+
+ RETURN(0);
+}
+
/**
* Implement OSP layer dt_object_operations::do_declare_create() interface.
*
/* 1MB bulk */
npages = min_t(unsigned int, OFD_MAX_BRW_SIZE, 1 << 20);
- npages /= PAGE_CACHE_SIZE;
+ npages /= PAGE_SIZE;
OBD_ALLOC(pages, npages * sizeof(*pages));
if (pages == NULL)
it->ooi_pages = pages;
it->ooi_total_npages = npages;
for (i = 0; i < npages; i++) {
- pages[i] = alloc_page(GFP_IOFS);
+ pages[i] = alloc_page(GFP_NOFS);
if (pages[i] == NULL)
RETURN(-ENOMEM);
}
RETURN(rc);
}
+ osp_set_req_replay(osp, req);
req->rq_request_portal = OUT_PORTAL;
ii = req_capsule_client_get(&req->rq_pill, &RMF_IDX_INFO);
memset(ii, 0, sizeof(*ii));
for (i = 0; i < npages; i++)
desc->bd_frag_ops->add_kiov_frag(desc, pages[i], 0,
- PAGE_CACHE_SIZE);
+ PAGE_SIZE);
ptlrpc_request_set_replen(req);
rc = ptlrpc_queue_wait(req);
GOTO(out, rc = -EPROTO);
npages = (ii->ii_count + LU_PAGE_COUNT - 1) >>
- (PAGE_CACHE_SHIFT - LU_PAGE_SHIFT);
+ (PAGE_SHIFT - LU_PAGE_SHIFT);
if (npages > it->ooi_total_npages) {
CERROR("%s: returned more pages than expected, %u > %u\n",
osp->opd_obd->obd_name, npages, it->ooi_total_npages);
spin_lock_init(&po->opo_lock);
o->lo_header->loh_attr |= LOHA_REMOTE;
+ INIT_LIST_HEAD(&po->opo_xattr_list);
+ INIT_LIST_HEAD(&po->opo_invalidate_cb_list);
if (is_ost_obj(o)) {
po->opo_obj.do_ops = &osp_obj_ops;
po->opo_obj.do_ops = &osp_md_obj_ops;
po->opo_obj.do_body_ops = &osp_md_body_ops;
+
if (conf != NULL && conf->loc_flags & LOC_F_NEW) {
po->opo_non_exist = 1;
} else {
{
struct osp_object *obj = lu2osp_obj(o);
struct lu_object_header *h = o->lo_header;
+ struct osp_xattr_entry *oxe;
+ struct osp_xattr_entry *tmp;
+ int count;
dt_object_fini(&obj->opo_obj);
lu_object_header_fini(h);
- if (obj->opo_ooa != NULL) {
- struct osp_xattr_entry *oxe;
- struct osp_xattr_entry *tmp;
- int count;
-
- list_for_each_entry_safe(oxe, tmp,
- &obj->opo_ooa->ooa_xattr_list,
- oxe_list) {
- list_del(&oxe->oxe_list);
- count = atomic_read(&oxe->oxe_ref);
- LASSERTF(count == 1,
- "Still has %d users on the xattr entry %.*s\n",
- count-1, (int)oxe->oxe_namelen, oxe->oxe_buf);
-
- OBD_FREE(oxe, oxe->oxe_buflen);
- }
- OBD_FREE_PTR(obj->opo_ooa);
+ list_for_each_entry_safe(oxe, tmp, &obj->opo_xattr_list, oxe_list) {
+ list_del(&oxe->oxe_list);
+ count = atomic_read(&oxe->oxe_ref);
+ LASSERTF(count == 1,
+ "Still has %d users on the xattr entry %.*s\n",
+ count-1, (int)oxe->oxe_namelen, oxe->oxe_buf);
+
+ OBD_FREE(oxe, oxe->oxe_buflen);
}
OBD_SLAB_FREE_PTR(obj, osp_object_kmem);
}