* GPL HEADER END
*/
/*
- * Copyright 2008 Sun Microsystems, Inc. All rights reserved
+ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
* Use is subject to license terms.
*/
/*
+ * Copyright (c) 2011 Whamcloud, Inc.
+ */
+/*
* This file is part of Lustre, http://www.lustre.org/
* Lustre is a trademark of Sun Microsystems, Inc.
*/
#include <liblustre.h>
#endif
-#include <lustre/lustre_idl.h>
#include <obd_support.h>
+#include <lustre/lustre_idl.h>
#include <lustre_lib.h>
#include <lustre_net.h>
#include <lustre_dlm.h>
#include "lmv_internal.h"
extern cfs_mem_cache_t *lmv_object_cache;
-extern atomic_t lmv_object_count;
+extern cfs_atomic_t lmv_object_count;
static CFS_LIST_HEAD(obj_list);
-static spinlock_t obj_list_lock = SPIN_LOCK_UNLOCKED;
+static cfs_spinlock_t obj_list_lock = CFS_SPIN_LOCK_UNLOCKED;
struct lmv_object *lmv_object_alloc(struct obd_device *obd,
const struct lu_fid *fid,
if (!obj)
return NULL;
- atomic_inc(&lmv_object_count);
+ cfs_atomic_inc(&lmv_object_count);
obj->lo_fid = *fid;
obj->lo_obd = obd;
obj->lo_state = 0;
obj->lo_hashtype = mea->mea_magic;
- init_MUTEX(&obj->lo_guard);
- atomic_set(&obj->lo_count, 0);
+ cfs_init_mutex(&obj->lo_guard);
+ cfs_atomic_set(&obj->lo_count, 0);
obj->lo_objcount = mea->mea_count;
obj_size = sizeof(struct lmv_stripe) *
lmv->desc.ld_tgt_count;
- OBD_ALLOC(obj->lo_stripes, obj_size);
+ OBD_ALLOC_LARGE(obj->lo_stripes, obj_size);
if (!obj->lo_stripes)
goto err_obj;
- memset(obj->lo_stripes, 0, obj_size);
-
CDEBUG(D_INODE, "Allocate object for "DFID"\n",
PFID(fid));
for (i = 0; i < mea->mea_count; i++) {
struct lmv_obd *lmv = &obj->lo_obd->u.lmv;
unsigned int obj_size;
- LASSERT(!atomic_read(&obj->lo_count));
+ LASSERT(!cfs_atomic_read(&obj->lo_count));
obj_size = sizeof(struct lmv_stripe) *
lmv->desc.ld_tgt_count;
- OBD_FREE(obj->lo_stripes, obj_size);
+ OBD_FREE_LARGE(obj->lo_stripes, obj_size);
OBD_SLAB_FREE(obj, lmv_object_cache, sizeof(*obj));
- atomic_dec(&lmv_object_count);
+ cfs_atomic_dec(&lmv_object_count);
}
static void __lmv_object_add(struct lmv_object *obj)
{
- atomic_inc(&obj->lo_count);
- list_add(&obj->lo_list, &obj_list);
+ cfs_atomic_inc(&obj->lo_count);
+ cfs_list_add(&obj->lo_list, &obj_list);
}
void lmv_object_add(struct lmv_object *obj)
{
- spin_lock(&obj_list_lock);
+ cfs_spin_lock(&obj_list_lock);
__lmv_object_add(obj);
- spin_unlock(&obj_list_lock);
+ cfs_spin_unlock(&obj_list_lock);
}
static void __lmv_object_del(struct lmv_object *obj)
{
- list_del(&obj->lo_list);
+ cfs_list_del(&obj->lo_list);
lmv_object_free(obj);
}
void lmv_object_del(struct lmv_object *obj)
{
- spin_lock(&obj_list_lock);
+ cfs_spin_lock(&obj_list_lock);
__lmv_object_del(obj);
- spin_unlock(&obj_list_lock);
+ cfs_spin_unlock(&obj_list_lock);
}
static struct lmv_object *__lmv_object_get(struct lmv_object *obj)
{
LASSERT(obj != NULL);
- atomic_inc(&obj->lo_count);
+ cfs_atomic_inc(&obj->lo_count);
return obj;
}
struct lmv_object *lmv_object_get(struct lmv_object *obj)
{
- spin_lock(&obj_list_lock);
+ cfs_spin_lock(&obj_list_lock);
__lmv_object_get(obj);
- spin_unlock(&obj_list_lock);
+ cfs_spin_unlock(&obj_list_lock);
return obj;
}
{
LASSERT(obj);
- if (atomic_dec_and_test(&obj->lo_count)) {
+ if (cfs_atomic_dec_and_test(&obj->lo_count)) {
CDEBUG(D_INODE, "Last reference to "DFID" - "
"destroying\n", PFID(&obj->lo_fid));
__lmv_object_del(obj);
void lmv_object_put(struct lmv_object *obj)
{
- spin_lock(&obj_list_lock);
+ cfs_spin_lock(&obj_list_lock);
__lmv_object_put(obj);
- spin_unlock(&obj_list_lock);
+ cfs_spin_unlock(&obj_list_lock);
}
void lmv_object_put_unlock(struct lmv_object *obj)
static struct lmv_object *__lmv_object_find(struct obd_device *obd, const struct lu_fid *fid)
{
struct lmv_object *obj;
- struct list_head *cur;
+ cfs_list_t *cur;
- list_for_each(cur, &obj_list) {
- obj = list_entry(cur, struct lmv_object, lo_list);
+ cfs_list_for_each(cur, &obj_list) {
+ obj = cfs_list_entry(cur, struct lmv_object, lo_list);
- /*
+ /*
* Check if object is in destroying phase. If so - skip
- * it.
+ * it.
*/
if (obj->lo_state & O_FREEING)
continue;
if (obj->lo_obd != obd)
continue;
- /*
- * Check if this is what we're looking for.
+ /*
+ * Check if this is what we're looking for.
*/
if (lu_fid_eq(&obj->lo_fid, fid))
return __lmv_object_get(obj);
return NULL;
}
-struct lmv_object *lmv_object_find(struct obd_device *obd,
+struct lmv_object *lmv_object_find(struct obd_device *obd,
const struct lu_fid *fid)
{
- struct lmv_object *obj;
+ struct lmv_obd *lmv = &obd->u.lmv;
+ struct lmv_object *obj = NULL;
ENTRY;
- spin_lock(&obj_list_lock);
- obj = __lmv_object_find(obd, fid);
- spin_unlock(&obj_list_lock);
+ /* For single MDT case, lmv_object list is always empty. */
+ if (lmv->desc.ld_tgt_count > 1) {
+ cfs_spin_lock(&obj_list_lock);
+ obj = __lmv_object_find(obd, fid);
+ cfs_spin_unlock(&obj_list_lock);
+ }
RETURN(obj);
}
* Check if someone created it already while we were dealing with
* allocating @obj.
*/
- spin_lock(&obj_list_lock);
+ cfs_spin_lock(&obj_list_lock);
obj = __lmv_object_find(obd, fid);
if (obj) {
/*
* Someone created it already - put @obj and getting out.
*/
- spin_unlock(&obj_list_lock);
+ cfs_spin_unlock(&obj_list_lock);
lmv_object_free(new);
RETURN(obj);
}
__lmv_object_add(new);
__lmv_object_get(new);
- spin_unlock(&obj_list_lock);
+ cfs_spin_unlock(&obj_list_lock);
CDEBUG(D_INODE, "New obj in lmv cache: "DFID"\n",
PFID(fid));
PFID(fid));
md.mea = NULL;
-
+
if (mea == NULL) {
+ struct md_op_data *op_data;
__u64 valid;
CDEBUG(D_INODE, "Mea isn't passed in, get it now\n");
mealen = lmv_get_easize(lmv);
- /*
- * Time to update mea of parent fid.
+ /*
+ * Time to update mea of parent fid.
*/
md.mea = NULL;
valid = OBD_MD_FLEASIZE | OBD_MD_FLDIREA | OBD_MD_MEA;
if (IS_ERR(tgt))
GOTO(cleanup, obj = (void *)tgt);
- rc = md_getattr(tgt->ltd_exp, fid, NULL, valid, mealen, &req);
+ OBD_ALLOC_PTR(op_data);
+ if (op_data == NULL)
+ GOTO(cleanup, obj = ERR_PTR(-ENOMEM));
+
+ op_data->op_fid1 = *fid;
+ op_data->op_mode = mealen;
+ op_data->op_valid = valid;
+ rc = md_getattr(tgt->ltd_exp, op_data, &req);
+ OBD_FREE_PTR(op_data);
if (rc) {
CERROR("md_getattr() failed, error %d\n", rc);
GOTO(cleanup, obj = ERR_PTR(rc));
mea = md.mea;
}
- /*
- * Got mea, now create obj for it.
+ /*
+ * Got mea, now create obj for it.
*/
obj = __lmv_object_create(obd, fid, mea);
if (!obj) {
int rc = 0;
ENTRY;
- spin_lock(&obj_list_lock);
+ cfs_spin_lock(&obj_list_lock);
obj = __lmv_object_find(obd, fid);
if (obj) {
obj->lo_state |= O_FREEING;
__lmv_object_put(obj);
rc = 1;
}
- spin_unlock(&obj_list_lock);
+ cfs_spin_unlock(&obj_list_lock);
RETURN(rc);
}
void lmv_object_cleanup(struct obd_device *obd)
{
- struct list_head *cur;
- struct list_head *tmp;
+ cfs_list_t *cur;
+ cfs_list_t *tmp;
struct lmv_object *obj;
ENTRY;
CDEBUG(D_INFO, "LMV object manager cleanup (%s)\n",
obd->obd_uuid.uuid);
- spin_lock(&obj_list_lock);
- list_for_each_safe(cur, tmp, &obj_list) {
- obj = list_entry(cur, struct lmv_object, lo_list);
+ cfs_spin_lock(&obj_list_lock);
+ cfs_list_for_each_safe(cur, tmp, &obj_list) {
+ obj = cfs_list_entry(cur, struct lmv_object, lo_list);
if (obj->lo_obd != obd)
continue;
obj->lo_state |= O_FREEING;
- if (atomic_read(&obj->lo_count) > 1) {
+ if (cfs_atomic_read(&obj->lo_count) > 1) {
CERROR("Object "DFID" has count (%d)\n",
- PFID(&obj->lo_fid), atomic_read(&obj->lo_count));
+ PFID(&obj->lo_fid),
+ cfs_atomic_read(&obj->lo_count));
}
__lmv_object_put(obj);
}
- spin_unlock(&obj_list_lock);
+ cfs_spin_unlock(&obj_list_lock);
EXIT;
}