X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Flmv%2Flmv_objmgr.c;h=ce054c74721c0db1ad2e6833f47e1e36cbdd0e68;hb=95b0089f355d73a695c209d4126b9cc4f1d60c9c;hp=1deb5f34ae666def178093fa6c430c00466f0ba9;hpb=5fc7f259c7d962d36132281f2eaac9f071aaad6a;p=fs%2Flustre-release.git diff --git a/lustre/lmv/lmv_objmgr.c b/lustre/lmv/lmv_objmgr.c index 1deb5f3..ce054c7 100644 --- a/lustre/lmv/lmv_objmgr.c +++ b/lustre/lmv/lmv_objmgr.c @@ -48,12 +48,18 @@ #include #include "lmv_internal.h" -static LIST_HEAD(lmv_obj_list); -static spinlock_t lmv_obj_list_lock = SPIN_LOCK_UNLOCKED; +/* objects cache. */ +extern kmem_cache_t *obj_cache; +extern atomic_t obj_cache_count; -/* creates new obj on passed @fid and @mea. */ +/* object list and its guard. */ +static LIST_HEAD(obj_list); +static spinlock_t obj_list_lock = SPIN_LOCK_UNLOCKED; + +/* creates new obj on passed @id and @mea. */ struct lmv_obj * -lmv_alloc_obj(struct obd_device *obd, struct ll_fid *fid, +lmv_alloc_obj(struct obd_device *obd, + struct lustre_id *id, struct mea *mea) { int i; @@ -61,14 +67,21 @@ lmv_alloc_obj(struct obd_device *obd, struct ll_fid *fid, unsigned int obj_size; struct lmv_obd *lmv = &obd->u.lmv; - OBD_ALLOC(obj, sizeof(*obj)); + LASSERT(mea->mea_magic == MEA_MAGIC_LAST_CHAR + || mea->mea_magic == MEA_MAGIC_ALL_CHARS); + + OBD_SLAB_ALLOC(obj, obj_cache, GFP_NOFS, + sizeof(*obj)); if (!obj) return NULL; + atomic_inc(&obj_cache_count); + + obj->id = *id; obj->obd = obd; - obj->fid = *fid; - obj->freeing = 0; - + obj->state = 0; + obj->hashtype = mea->mea_magic; + init_MUTEX(&obj->guard); atomic_set(&obj->count, 0); obj->objcount = mea->mea_count; @@ -82,13 +95,13 @@ lmv_alloc_obj(struct obd_device *obd, struct ll_fid *fid, memset(obj->objs, 0, obj_size); - /* put all fids in */ + /* put all ids in */ for (i = 0; i < mea->mea_count; i++) { - CDEBUG(D_OTHER, "subobj %lu/%lu/%lu\n", - (unsigned long)mea->mea_fids[i].mds, - (unsigned long)mea->mea_fids[i].id, - (unsigned long)mea->mea_fids[i].generation); - obj->objs[i].fid = mea->mea_fids[i]; + CDEBUG(D_OTHER, "subobj "DLID4"\n", + OLID4(&mea->mea_ids[i])); + obj->objs[i].id = mea->mea_ids[i]; + LASSERT(id_ino(&obj->objs[i].id)); + LASSERT(id_fid(&obj->objs[i].id)); } return obj; @@ -98,37 +111,40 @@ err_obj: return NULL; } -/* destroys passed @obj. */ +/* destroy passed @obj. */ void lmv_free_obj(struct lmv_obj *obj) { unsigned int obj_size; struct lmv_obd *lmv = &obj->obd->u.lmv; + LASSERT(!atomic_read(&obj->count)); + obj_size = sizeof(struct lmv_inode) * lmv->desc.ld_tgt_count; OBD_FREE(obj->objs, obj_size); - OBD_FREE(obj, sizeof(*obj)); + OBD_SLAB_FREE(obj, obj_cache, sizeof(*obj)); + atomic_dec(&obj_cache_count); } static void -__lmv_add_obj(struct lmv_obj *obj) +__add_obj(struct lmv_obj *obj) { atomic_inc(&obj->count); - list_add(&obj->list, &lmv_obj_list); + list_add(&obj->list, &obj_list); } void lmv_add_obj(struct lmv_obj *obj) { - spin_lock(&lmv_obj_list_lock); - __lmv_add_obj(obj); - spin_unlock(&lmv_obj_list_lock); + spin_lock(&obj_list_lock); + __add_obj(obj); + spin_unlock(&obj_list_lock); } static void -__lmv_del_obj(struct lmv_obj *obj) +__del_obj(struct lmv_obj *obj) { list_del(&obj->list); lmv_free_obj(obj); @@ -137,15 +153,15 @@ __lmv_del_obj(struct lmv_obj *obj) void lmv_del_obj(struct lmv_obj *obj) { - spin_lock(&lmv_obj_list_lock); - __lmv_del_obj(obj); - spin_unlock(&lmv_obj_list_lock); + spin_lock(&obj_list_lock); + __del_obj(obj); + spin_unlock(&obj_list_lock); } static struct lmv_obj * -__lmv_get_obj(struct lmv_obj *obj) +__get_obj(struct lmv_obj *obj) { - LASSERT(obj); + LASSERT(obj != NULL); atomic_inc(&obj->count); return obj; } @@ -153,151 +169,146 @@ __lmv_get_obj(struct lmv_obj *obj) struct lmv_obj * lmv_get_obj(struct lmv_obj *obj) { - spin_lock(&lmv_obj_list_lock); - __lmv_get_obj(obj); - spin_unlock(&lmv_obj_list_lock); - + spin_lock(&obj_list_lock); + __get_obj(obj); + spin_unlock(&obj_list_lock); return obj; } static void -__lmv_put_obj(struct lmv_obj *obj) +__put_obj(struct lmv_obj *obj) { LASSERT(obj); if (atomic_dec_and_test(&obj->count)) { - struct ll_fid *fid = &obj->fid; - CDEBUG(D_OTHER, "last reference to %lu/%lu/%lu - destroying\n", - (unsigned long)fid->mds, (unsigned long)fid->id, - (unsigned long)fid->generation); - __lmv_del_obj(obj); + struct lustre_id *id = &obj->id; + CDEBUG(D_OTHER, "last reference to "DLID4" - " + "destroying\n", OLID4(id)); + __del_obj(obj); } } void lmv_put_obj(struct lmv_obj *obj) { - spin_lock(&lmv_obj_list_lock); - __lmv_put_obj(obj); - spin_unlock(&lmv_obj_list_lock); + spin_lock(&obj_list_lock); + __put_obj(obj); + spin_unlock(&obj_list_lock); } static struct lmv_obj * -__lmv_grab_obj(struct obd_device *obd, struct ll_fid *fid) +__grab_obj(struct obd_device *obd, struct lustre_id *id) { struct lmv_obj *obj; struct list_head *cur; - list_for_each(cur, &lmv_obj_list) { + list_for_each(cur, &obj_list) { obj = list_entry(cur, struct lmv_obj, list); /* check if object is in progress of destroying. If so - skip * it. */ - lmv_lock_obj(obj); + if (obj->state & O_FREEING) + continue; - if (obj->freeing) { - lmv_unlock_obj(obj); + /* + * 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. + */ + if (obj->obd != obd) continue; - } - /* check if this is waht we're looking for. */ - if (fid_equal(&obj->fid, fid)) { - __lmv_get_obj(obj); - lmv_unlock_obj(obj); - return obj; - } - lmv_unlock_obj(obj); + /* check if this is what we're looking for. */ + if (id_equal_fid(&obj->id, id)) + return __get_obj(obj); } return NULL; } struct lmv_obj * -lmv_grab_obj(struct obd_device *obd, struct ll_fid *fid) +lmv_grab_obj(struct obd_device *obd, struct lustre_id *id) { struct lmv_obj *obj; ENTRY; - spin_lock(&lmv_obj_list_lock); - obj = __lmv_grab_obj(obd, fid); - spin_unlock(&lmv_obj_list_lock); + spin_lock(&obj_list_lock); + obj = __grab_obj(obd, id); + spin_unlock(&obj_list_lock); RETURN(obj); } -/* looks in objects list for an object that matches passed @fid. If it is not +/* looks in objects list for an object that matches passed @id. If it is not * found -- creates it using passed @mea and puts onto list. */ static struct lmv_obj * -__lmv_create_obj(struct obd_device *obd, struct ll_fid *fid, - struct mea *mea) +__create_obj(struct obd_device *obd, struct lustre_id *id, struct mea *mea) { struct lmv_obj *new, *obj; ENTRY; - obj = lmv_grab_obj(obd, fid); + obj = lmv_grab_obj(obd, id); if (obj) RETURN(obj); /* no such object yet, allocate and initialize it. */ - new = lmv_alloc_obj(obd, fid, mea); + new = lmv_alloc_obj(obd, id, mea); if (!new) RETURN(NULL); /* check if someone create it already while we were dealing with * allocating @obj. */ - spin_lock(&lmv_obj_list_lock); - obj = __lmv_grab_obj(obd, fid); + spin_lock(&obj_list_lock); + obj = __grab_obj(obd, id); if (obj) { /* someone created it already - put @obj and getting out. */ lmv_free_obj(new); - spin_unlock(&lmv_obj_list_lock); + spin_unlock(&obj_list_lock); RETURN(obj); } - __lmv_add_obj(new); - __lmv_get_obj(new); + __add_obj(new); + __get_obj(new); - spin_unlock(&lmv_obj_list_lock); + spin_unlock(&obj_list_lock); - CDEBUG(D_OTHER, "new obj in lmv cache: %lu/%lu/%lu\n", - (unsigned long)fid->mds, (unsigned long)fid->id, - (unsigned long)fid->generation); + CDEBUG(D_OTHER, "new obj in lmv cache: "DLID4"\n", + OLID4(id)); RETURN(new); } -/* creates object from passed @fid and @mea. If @mea is NULL, it will be +/* creates object from passed @id and @mea. If @mea is NULL, it will be * obtained from correct MDT and used for constructing the object. */ struct lmv_obj * -lmv_create_obj(struct obd_export *exp, - struct ll_fid *fid, struct mea *mea) +lmv_create_obj(struct obd_export *exp, struct lustre_id *id, struct mea *mea) { struct obd_device *obd = exp->exp_obd; struct lmv_obd *lmv = &obd->u.lmv; struct ptlrpc_request *req = NULL; struct lmv_obj *obj; struct lustre_md md; - int mealen, i, rc; + int mealen, rc; ENTRY; - CDEBUG(D_OTHER, "get mea for %lu/%lu/%lu and create lmv obj\n", - (unsigned long)fid->mds, (unsigned long)fid->id, - (unsigned long)fid->generation); + CDEBUG(D_OTHER, "get mea for "DLID4" and create lmv obj\n", + OLID4(id)); if (!mea) { - unsigned long valid; + __u64 valid; CDEBUG(D_OTHER, "mea isn't passed in, get it now\n"); mealen = MEA_SIZE_LMV(lmv); - /* time to update mea of parent fid */ - i = fid->mds; + /* time to update mea of parent id */ md.mea = NULL; - valid = OBD_MD_FLEASIZE | OBD_MD_FLDIREA; - rc = md_getattr(lmv->tgts[fid->mds].ltd_exp, fid, - valid, mealen, &req); + + rc = md_getattr(lmv->tgts[id_group(id)].ltd_exp, + id, valid, mealen, &req); if (rc) { CERROR("md_getattr() failed, error %d\n", rc); GOTO(cleanup, obj = ERR_PTR(rc)); @@ -316,71 +327,82 @@ lmv_create_obj(struct obd_export *exp, } /* got mea, now create obj for it. */ - obj = __lmv_create_obj(obd, fid, mea); + obj = __create_obj(obd, id, mea); if (!obj) { - CERROR("Can't create new object %lu/%lu/%lu\n", - (unsigned long)fid->mds, (unsigned long)fid->id, - (unsigned long)fid->generation); + CERROR("Can't create new object "DLID4"\n", + OLID4(id)); GOTO(cleanup, obj = ERR_PTR(-ENOMEM)); } - - lmv_put_obj(obj); + EXIT; cleanup: - if (req) + if (req) ptlrpc_req_finished(req); - RETURN(obj); + return obj; } -/* looks for object with @fid and orders to destroy it. It possible the object +/* + * looks for object with @id and orders to destroy it. It is possible the object * will not be destroyed right now, because it is still using by someone. In * this case it will be marked as "freeing" and will not be accessible anymore - * for subsequent callers of lmv_grab_obj(). */ + * for subsequent callers of lmv_grab_obj(). + */ int -lmv_destroy_obj(struct obd_export *exp, struct ll_fid *fid) +lmv_delete_obj(struct obd_export *exp, struct lustre_id *id) { struct obd_device *obd = exp->exp_obd; struct lmv_obj *obj; + int rc = 0; ENTRY; - obj = lmv_grab_obj(obd, fid); + spin_lock(&obj_list_lock); + obj = __grab_obj(obd, id); if (obj) { - lmv_lock_obj(obj); - obj->freeing = 1; - lmv_unlock_obj(obj); - - lmv_put_obj(obj); - lmv_put_obj(obj); - RETURN(1); + obj->state |= O_FREEING; + __put_obj(obj); + __put_obj(obj); + rc = 1; } + spin_unlock(&obj_list_lock); - RETURN(0); + RETURN(rc); } int lmv_setup_mgr(struct obd_device *obd) { - CWARN("LMV object manager setup (%s)\n", - obd->obd_uuid.uuid); - return 0; + ENTRY; + LASSERT(obd != NULL); + + CDEBUG(D_INFO, "LMV object manager setup (%s)\n", + obd->obd_uuid.uuid); + + RETURN(0); } void lmv_cleanup_mgr(struct obd_device *obd) { - struct lmv_obj *obj; struct list_head *cur, *tmp; + struct lmv_obj *obj; + ENTRY; - CWARN("LMV object manager cleanup (%s)\n", - obd->obd_uuid.uuid); + CDEBUG(D_INFO, "LMV object manager cleanup (%s)\n", + obd->obd_uuid.uuid); - spin_lock(&lmv_obj_list_lock); - list_for_each_safe(cur, tmp, &lmv_obj_list) { + spin_lock(&obj_list_lock); + list_for_each_safe(cur, tmp, &obj_list) { obj = list_entry(cur, struct lmv_obj, list); if (obj->obd != obd) continue; - __lmv_put_obj(obj); + obj->state |= O_FREEING; + if (atomic_read(&obj->count) > 1) { + CERROR("obj "DLID4" has count > 1 (%d)\n", + OLID4(&obj->id), atomic_read(&obj->count)); + } + __put_obj(obj); } - spin_unlock(&lmv_obj_list_lock); + spin_unlock(&obj_list_lock); + EXIT; }