/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
* vim:expandtab:shiftwidth=8:tabstop=8:
*
- * Copyright (C) 2002, 2003 Cluster File Systems, Inc.
+ * Copyright (C) 2002, 2003, 2004, 2005, 2006 Cluster File Systems, Inc.
*
* This file is part of Lustre, http://www.lustre.org.
*
#include <liblustre.h>
#endif
-#include <linux/obd_support.h>
-#include <linux/lustre_lib.h>
-#include <linux/lustre_net.h>
-#include <linux/lustre_idl.h>
-#include <linux/lustre_dlm.h>
-#include <linux/obd_class.h>
-#include <linux/lprocfs_status.h>
+#include <lustre/lustre_idl.h>
+#include <obd_support.h>
+#include <lustre_lib.h>
+#include <lustre_net.h>
+#include <lustre_dlm.h>
+#include <obd_class.h>
+#include <lprocfs_status.h>
#include "lmv_internal.h"
/* objects cache. */
-extern kmem_cache_t *obj_cache;
+extern cfs_mem_cache_t *obj_cache;
extern atomic_t obj_cache_count;
/* object list and its guard. */
/* creates new obj on passed @fid and @mea. */
struct lmv_obj *
lmv_obj_alloc(struct obd_device *obd,
- struct lu_fid *fid,
+ const struct lu_fid *fid,
struct lmv_stripe_md *mea)
{
int i;
struct lmv_obd *lmv = &obd->u.lmv;
LASSERT(mea->mea_magic == MEA_MAGIC_LAST_CHAR
- || mea->mea_magic == MEA_MAGIC_ALL_CHARS);
+ || mea->mea_magic == MEA_MAGIC_ALL_CHARS
+ || mea->mea_magic == MEA_MAGIC_HASH_SEGMENT);
- OBD_SLAB_ALLOC(obj, obj_cache, GFP_NOFS,
+ OBD_SLAB_ALLOC(obj, obj_cache, CFS_ALLOC_STD,
sizeof(*obj));
if (!obj)
return NULL;
atomic_inc(&obj_cache_count);
-
+
obj->lo_fid = *fid;
obj->lo_obd = obd;
obj->lo_state = 0;
obj_size = sizeof(struct lmv_inode) *
lmv->desc.ld_tgt_count;
-
+
OBD_ALLOC(obj->lo_inodes, obj_size);
if (!obj->lo_inodes)
goto err_obj;
/* put all ids in */
for (i = 0; i < mea->mea_count; i++) {
- CDEBUG(D_OTHER, "subobj "DFID3"\n",
- PFID3(&mea->mea_ids[i]));
+ int rc;
+
+ CDEBUG(D_OTHER, "subobj "DFID"\n",
+ PFID(&mea->mea_ids[i]));
obj->lo_inodes[i].li_fid = mea->mea_ids[i];
- LASSERT(fid_num(&obj->lo_inodes[i].li_fid));
+ LASSERT(fid_is_sane(&obj->lo_inodes[i].li_fid));
+
+ /*
+ * Cache slave mds number to use it in all cases it is needed
+ * instead of constant lookup.
+ */
+ rc = lmv_fld_lookup(lmv, &obj->lo_inodes[i].li_fid,
+ &obj->lo_inodes[i].li_mds);
+ if (rc)
+ goto err_obj;
}
return obj;
-
+
err_obj:
OBD_FREE(obj, sizeof(*obj));
return NULL;
{
struct lmv_obd *lmv = &obj->lo_obd->u.lmv;
unsigned int obj_size;
-
+
LASSERT(!atomic_read(&obj->lo_count));
-
+
obj_size = sizeof(struct lmv_inode) *
lmv->desc.ld_tgt_count;
-
+
OBD_FREE(obj->lo_inodes, obj_size);
OBD_SLAB_FREE(obj, obj_cache, sizeof(*obj));
atomic_dec(&obj_cache_count);
if (atomic_dec_and_test(&obj->lo_count)) {
struct lu_fid *fid = &obj->lo_fid;
- CDEBUG(D_OTHER, "last reference to "DFID3" - "
- "destroying\n", PFID3(fid));
+ CDEBUG(D_OTHER, "last reference to "DFID" - "
+ "destroying\n", PFID(fid));
__lmv_obj_del(obj);
}
}
}
static struct lmv_obj *
-__lmv_obj_grab(struct obd_device *obd, struct lu_fid *fid)
+__lmv_obj_grab(struct obd_device *obd, const struct lu_fid *fid)
{
struct lmv_obj *obj;
struct list_head *cur;
if (obj->lo_state & O_FREEING)
continue;
- /*
+ /*
* we should make sure, that we have found object belong to
* passed obd. It is possible that, object manager will have two
* objects with the same fid belong to different obds, if client
* and mds runs on the same host. May be it is good idea to have
- * objects list assosiated with obd.
+ * objects list associated with obd.
*/
if (obj->lo_obd != obd)
continue;
}
struct lmv_obj *
-lmv_obj_grab(struct obd_device *obd, struct lu_fid *fid)
+lmv_obj_grab(struct obd_device *obd, const struct lu_fid *fid)
{
struct lmv_obj *obj;
ENTRY;
-
+
spin_lock(&obj_list_lock);
obj = __lmv_obj_grab(obd, fid);
spin_unlock(&obj_list_lock);
-
+
RETURN(obj);
}
/* looks in objects list for an object that matches passed @fid. If it is not
* found -- creates it using passed @mea and puts onto list. */
static struct lmv_obj *
-__lmv_obj_create(struct obd_device *obd, struct lu_fid *fid,
+__lmv_obj_create(struct obd_device *obd, const struct lu_fid *fid,
struct lmv_stripe_md *mea)
{
struct lmv_obj *new, *obj;
obj = __lmv_obj_grab(obd, fid);
if (obj) {
/* someone created it already - put @obj and getting out. */
- lmv_obj_free(new);
spin_unlock(&obj_list_lock);
+ lmv_obj_free(new);
RETURN(obj);
}
__lmv_obj_add(new);
__lmv_obj_get(new);
-
+
spin_unlock(&obj_list_lock);
- CDEBUG(D_OTHER, "new obj in lmv cache: "DFID3"\n",
- PFID3(fid));
+ CDEBUG(D_OTHER, "new obj in lmv cache: "DFID"\n",
+ PFID(fid));
RETURN(new);
-
+
}
/* creates object from passed @fid and @mea. If @mea is NULL, it will be
* obtained from correct MDT and used for constructing the object. */
struct lmv_obj *
-lmv_obj_create(struct obd_export *exp, struct lu_fid *fid,
+lmv_obj_create(struct obd_export *exp, const struct lu_fid *fid,
struct lmv_stripe_md *mea)
{
struct obd_device *obd = exp->exp_obd;
struct lmv_obd *lmv = &obd->u.lmv;
struct ptlrpc_request *req = NULL;
+ struct obd_export *tgt_exp;
struct lmv_obj *obj;
struct lustre_md md;
- int mealen, rc, mds;
+ int mealen, rc;
ENTRY;
- CDEBUG(D_OTHER, "get mea for "DFID3" and create lmv obj\n",
- PFID3(fid));
+ CDEBUG(D_OTHER, "get mea for "DFID" and create lmv obj\n",
+ PFID(fid));
md.mea = NULL;
if (mea == NULL) {
__u64 valid;
-
+
CDEBUG(D_OTHER, "mea isn't passed in, get it now\n");
- mealen = MEA_SIZE_LMV(lmv);
-
+ mealen = lmv_get_easize(lmv);
+
/* time to update mea of parent fid */
md.mea = NULL;
valid = OBD_MD_FLEASIZE | OBD_MD_FLDIREA | OBD_MD_MEA;
- mds = lmv_fld_lookup(obd, fid);
+ tgt_exp = lmv_find_export(lmv, fid);
+ if (IS_ERR(tgt_exp))
+ GOTO(cleanup, obj = (void *)tgt_exp);
- rc = md_getattr(lmv->tgts[mds].ltd_exp, fid, valid, mealen, &req);
+ rc = md_getattr(tgt_exp, fid, NULL, valid, mealen, &req);
if (rc) {
CERROR("md_getattr() failed, error %d\n", rc);
GOTO(cleanup, obj = ERR_PTR(rc));
}
- rc = md_get_lustre_md(exp, req, 0, NULL, &md);
+ rc = md_get_lustre_md(exp, req, 0, NULL, exp, &md);
if (rc) {
CERROR("mdc_get_lustre_md() failed, error %d\n", rc);
GOTO(cleanup, obj = ERR_PTR(rc));
if (md.mea == NULL)
GOTO(cleanup, obj = ERR_PTR(-ENODATA));
-
+
mea = md.mea;
}
/* got mea, now create obj for it. */
obj = __lmv_obj_create(obd, fid, mea);
if (!obj) {
- CERROR("Can't create new object "DFID3"\n",
- PFID3(fid));
+ CERROR("Can't create new object "DFID"\n",
+ PFID(fid));
GOTO(cleanup, obj = ERR_PTR(-ENOMEM));
}
if (md.mea != NULL)
obd_free_memmd(exp, (struct lov_stripe_md **)&md.mea);
-
+
EXIT;
cleanup:
if (req)
* for subsequent callers of lmv_obj_grab().
*/
int
-lmv_obj_delete(struct obd_export *exp, struct lu_fid *fid)
+lmv_obj_delete(struct obd_export *exp, const struct lu_fid *fid)
{
struct obd_device *obd = exp->exp_obd;
struct lmv_obj *obj;
}
int
-lmv_mgr_setup(struct obd_device *obd)
+lmv_obj_setup(struct obd_device *obd)
{
ENTRY;
LASSERT(obd != NULL);
-
+
CDEBUG(D_INFO, "LMV object manager setup (%s)\n",
obd->obd_uuid.uuid);
}
void
-lmv_mgr_cleanup(struct obd_device *obd)
+lmv_obj_cleanup(struct obd_device *obd)
{
struct list_head *cur, *tmp;
struct lmv_obj *obj;
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_obj, lo_list);
-
+
if (obj->lo_obd != obd)
continue;
obj->lo_state |= O_FREEING;
if (atomic_read(&obj->lo_count) > 1) {
- CERROR("obj "DFID3" has count > 1 (%d)\n",
- PFID3(&obj->lo_fid), atomic_read(&obj->lo_count));
+ CERROR("obj "DFID" has count > 1 (%d)\n",
+ PFID(&obj->lo_fid), atomic_read(&obj->lo_count));
}
__lmv_obj_put(obj);
}