示例#1
0
static int orphan_object_destroy(const struct lu_env *env,
                                 struct mdd_object *obj,
                                 struct dt_key *key)
{
        struct thandle *th = NULL;
        struct mdd_device *mdd = mdo2mdd(&obj->mod_obj);
        int rc = 0;
        ENTRY;

        mdd_txn_param_build(env, mdd, MDD_TXN_UNLINK_OP);
        th = mdd_trans_start(env, mdd);
        if (IS_ERR(th)) {
                CERROR("Cannot get thandle\n");
                RETURN(-ENOMEM);
        }

        mdd_write_lock(env, obj, MOR_TGT_CHILD);
        if (likely(obj->mod_count == 0)) {
                mdd_orphan_write_lock(env, mdd);
                rc = mdd_orphan_delete_obj(env, mdd, key, th);
                if (!rc)
                        orphan_object_kill(env, obj, mdd, th);
                else
                        CERROR("could not delete object: rc = %d\n",rc);
                mdd_orphan_write_unlock(env, mdd);
        }
        mdd_write_unlock(env, obj);
        mdd_trans_stop(env, mdd, 0, th);

        RETURN(rc);
}
示例#2
0
int orph_declare_index_delete(const struct lu_env *env,
                              struct mdd_object *obj,

                              struct thandle *th)
{
        struct mdd_device *mdd = mdo2mdd(&obj->mod_obj);
	struct dt_key	  *key;
        int                rc;

	key = orph_key_fill(env, mdo2fid(obj), ORPH_OP_UNLINK);

	rc = dt_declare_delete(env, mdd->mdd_orphans, key, th);
        if (rc)
                return rc;

        rc = mdo_declare_ref_del(env, obj, th);
        if (rc)
                return rc;

        if (S_ISDIR(mdd_object_type(obj))) {
                rc = mdo_declare_ref_del(env, obj, th);
                if (rc)
                        return rc;

                rc = dt_declare_ref_del(env, mdd->mdd_orphans, th);
        }

        return rc;
}
示例#3
0
int mdd_orphan_declare_delete(const struct lu_env *env, struct mdd_object *obj,
			      struct thandle *th)
{
	struct mdd_device *mdd = mdo2mdd(&obj->mod_obj);
	struct dt_key *key;
	int rc;

	key = mdd_orphan_key_fill(env, mdo2fid(obj));

	rc = dt_declare_delete(env, mdd->mdd_orphans, key, th);
	if (rc)
		return rc;

	if (!mdd_object_exists(obj))
		return -ENOENT;

        rc = mdo_declare_ref_del(env, obj, th);
        if (rc)
                return rc;

        if (S_ISDIR(mdd_object_type(obj))) {
                rc = mdo_declare_ref_del(env, obj, th);
                if (rc)
                        return rc;

                rc = dt_declare_ref_del(env, mdd->mdd_orphans, th);
        }

        return rc;
}
示例#4
0
static int orph_index_insert(const struct lu_env *env,
                             struct mdd_object *obj,
                             __u32 op,
                             struct thandle *th)
{
        struct mdd_device       *mdd    = mdo2mdd(&obj->mod_obj);
        struct dt_object        *dor    = mdd->mdd_orphans;
        const struct lu_fid     *lf_dor = lu_object_fid(&dor->do_lu);
        struct dt_object        *next   = mdd_object_child(obj);
        int rc;
        ENTRY;

        LASSERT(mdd_write_locked(env, obj) != 0);
        LASSERT(!(obj->mod_flags & ORPHAN_OBJ));

        mdd_orphan_write_lock(env, mdd);

        rc = mdd_orphan_insert_obj(env, mdd, obj, op, th);
        if (rc)
                GOTO(out, rc);

        mdo_ref_add(env, obj, th);
        if (!S_ISDIR(mdd_object_type(obj)))
                goto out;

        mdo_ref_add(env, obj, th);
        mdd_orphan_ref_add(env, mdd, th);

        /* try best to fixup directory, dont return errors
         * from here */
        if (!dt_try_as_dir(env, next))
                goto out;
        next->do_index_ops->dio_delete(env, next,
                                       (const struct dt_key *)dotdot,
                                       th, BYPASS_CAPA);

        next->do_index_ops->dio_insert(env, next,
                                       (struct dt_rec *)lf_dor,
                                       (const struct dt_key *)dotdot,
                                       th, BYPASS_CAPA, 1);

out:
        if (rc == 0)
                obj->mod_flags |= ORPHAN_OBJ;

        mdd_orphan_write_unlock(env, mdd);

        RETURN(rc);
}
示例#5
0
static int orphan_object_destroy(const struct lu_env *env,
				 struct mdd_object *obj,
				 struct dt_key *key)
{
	struct thandle *th = NULL;
	struct mdd_device *mdd = mdo2mdd(&obj->mod_obj);
	int rc = 0;
	ENTRY;

	th = mdd_trans_create(env, mdd);
	if (IS_ERR(th)) {
		CERROR("Cannot get thandle\n");
		RETURN(PTR_ERR(th));
	}

	rc = orph_declare_index_delete(env, obj, th);
	if (rc)
		GOTO(stop, rc);

	rc = mdo_declare_destroy(env, obj, th);
	if (rc)
		GOTO(stop, rc);

	rc = mdd_trans_start(env, mdd, th);
	if (rc)
		GOTO(stop, rc);

	mdd_write_lock(env, obj, MOR_TGT_CHILD);
	if (likely(obj->mod_count == 0)) {
		mdd_orphan_write_lock(env, mdd);
		rc = mdd_orphan_delete_obj(env, mdd, key, th);
		if (rc == 0) {
			mdo_ref_del(env, obj, th);
			if (S_ISDIR(mdd_object_type(obj))) {
				mdo_ref_del(env, obj, th);
				mdd_orphan_ref_del(env, mdd, th);
			}
			rc = mdo_destroy(env, obj, th);
		} else
			CERROR("could not delete object: rc = %d\n", rc);
		mdd_orphan_write_unlock(env, mdd);
	}
	mdd_write_unlock(env, obj);

stop:
	rc = mdd_trans_stop(env, mdd, 0, th);

	RETURN(rc);
}
示例#6
0
/**
 * Lookup method for "fid" object. Only filenames with correct SEQ:OID format
 * are valid. We also check if object with passed fid exists or not.
 */
static int obf_lookup(const struct lu_env *env, struct md_object *p,
                      const struct lu_name *lname, struct lu_fid *f,
                      struct md_op_spec *spec)
{
        char *name = (char *)lname->ln_name;
        struct mdd_device *mdd = mdo2mdd(p);
        struct mdd_object *child;
        int rc = 0;

        while (*name == '[')
                name++;

        sscanf(name, SFID, RFID(f));
        if (!fid_is_sane(f)) {
		CWARN("%s: Trying to lookup invalid FID [%s] in %s/%s, FID "
		      "format should be "DFID"\n", mdd2obd_dev(mdd)->obd_name,
		      lname->ln_name, dot_lustre_name, mdd_obf_dir_name,
		      (__u64)FID_SEQ_NORMAL, 1, 0);
                GOTO(out, rc = -EINVAL);
        }

	if (!fid_is_norm(f) && !fid_is_igif(f) && !fid_is_root(f) &&
	    !fid_seq_is_dot(f->f_seq)) {
		CWARN("%s: Trying to lookup invalid FID "DFID" in %s/%s, "
		      "sequence should be >= "LPX64" or within ["LPX64","
		      ""LPX64"].\n", mdd2obd_dev(mdd)->obd_name, PFID(f),
		      dot_lustre_name, mdd_obf_dir_name, (__u64)FID_SEQ_NORMAL,
		      (__u64)FID_SEQ_IGIF, (__u64)FID_SEQ_IGIF_MAX);
		GOTO(out, rc = -EINVAL);
	}

        /* Check if object with this fid exists */
        child = mdd_object_find(env, mdd, f);
        if (child == NULL)
                GOTO(out, rc = 0);
        if (IS_ERR(child))
                GOTO(out, rc = PTR_ERR(child));

        if (mdd_object_exists(child) == 0)
                rc = -ENOENT;

        mdd_object_put(env, child);

out:
        return rc;
}
示例#7
0
/**
 *  add an orphan \a obj to the orphan index.
 *  \param obj file or directory.
 *  \param th  transaction for index insert.
 *
 *  \pre obj nlink == 0 && obj->mod_count != 0
 *
 *  \retval 0  success
 *  \retval  -ve index operation error.
 */
int mdd_orphan_insert(const struct lu_env *env, struct mdd_object *obj,
		      struct thandle *th)
{
	struct mdd_device *mdd = mdo2mdd(&obj->mod_obj);
	struct dt_object *dor = mdd->mdd_orphans;
	const struct lu_fid *lf_dor = lu_object_fid(&dor->do_lu);
	struct dt_object *next = mdd_object_child(obj);
	struct dt_insert_rec *rec = &mdd_env_info(env)->mti_dt_rec;
	int rc;
	ENTRY;

	LASSERT(mdd_write_locked(env, obj) != 0);
	LASSERT(!(obj->mod_flags & ORPHAN_OBJ));

	dt_write_lock(env, mdd->mdd_orphans, MOR_TGT_ORPHAN);

	rc = mdd_orphan_insert_obj(env, mdd, obj, th);
	if (rc)
		GOTO(out, rc);

	mdo_ref_add(env, obj, th);
	if (!S_ISDIR(mdd_object_type(obj)))
		GOTO(out, rc = 0);

	mdo_ref_add(env, obj, th);
	dt_ref_add(env, mdd->mdd_orphans, th);

	/* try best to fixup directory, do not return errors from here */
	if (!dt_try_as_dir(env, next))
		GOTO(out, rc = 0);

	dt_delete(env, next, (const struct dt_key *)dotdot, th);

	rec->rec_fid = lf_dor;
	rec->rec_type = S_IFDIR;
	dt_insert(env, next, (const struct dt_rec *)rec,
		  (const struct dt_key *)dotdot, th);

out:
	if (rc == 0)
		obj->mod_flags |= ORPHAN_OBJ;

	dt_write_unlock(env, mdd->mdd_orphans);

	RETURN(rc);
}
示例#8
0
/**
 *  delete an orphan \a obj from orphan index.
 *  \param obj file or directory.
 *  \param th  transaction for index deletion and object destruction.
 *
 *  \pre obj->mod_count == 0 && ORPHAN_OBJ is set for obj.
 *
 *  \retval 0  success
 *  \retval  -ve index operation error.
 */
int mdd_orphan_delete(const struct lu_env *env, struct mdd_object *obj,
		      struct thandle *th)
{
	struct mdd_device *mdd = mdo2mdd(&obj->mod_obj);
	struct dt_object *dor = mdd->mdd_orphans;
	struct dt_key *key;
	int rc = 0;

	ENTRY;

	LASSERT(mdd_write_locked(env, obj) != 0);
	LASSERT(obj->mod_flags & ORPHAN_OBJ);
	LASSERT(obj->mod_count == 0);

	LASSERT(dor);

	key = mdd_orphan_key_fill(env, mdo2fid(obj));
	dt_write_lock(env, mdd->mdd_orphans, MOR_TGT_ORPHAN);

	if (OBD_FAIL_CHECK(OBD_FAIL_MDS_ORPHAN_DELETE))
		goto ref_del;

	rc = dt_delete(env, mdd->mdd_orphans, key, th);
	if (rc == -ENOENT) {
		key = mdd_orphan_key_fill_20(env, mdo2fid(obj));
		rc = dt_delete(env, mdd->mdd_orphans, key, th);
	}

ref_del:
	if (!rc) {
		/* lov objects will be destroyed by caller */
		mdo_ref_del(env, obj, th);
		if (S_ISDIR(mdd_object_type(obj))) {
			mdo_ref_del(env, obj, th);
			dt_ref_del(env, mdd->mdd_orphans, th);
		}
		obj->mod_flags &= ~ORPHAN_OBJ;
	} else {
		CERROR("%s: could not delete orphan object "DFID": rc = %d\n",
		       mdd2obd_dev(mdd)->obd_name, PFID(mdo2fid(obj)), rc);
	}

	dt_write_unlock(env, mdd->mdd_orphans);
	RETURN(rc);
}
示例#9
0
static int orph_index_delete(const struct lu_env *env,
                             struct mdd_object *obj,
                             __u32 op,
                             struct thandle *th)
{
        struct mdd_device *mdd = mdo2mdd(&obj->mod_obj);
        struct dt_object *dor = mdd->mdd_orphans;
        struct dt_key *key;
        int rc;

        ENTRY;

        LASSERT(mdd_write_locked(env, obj) != 0);
        LASSERT(obj->mod_flags & ORPHAN_OBJ);
        LASSERT(obj->mod_count == 0);

        LASSERT(dor);

        key = orph_key_fill(env, mdo2fid(obj), op);
        mdd_orphan_write_lock(env, mdd);

        rc = mdd_orphan_delete_obj(env, mdd, key, th);

        if (rc == -ENOENT) {
                key = orph_key_fill_18(env, mdo2fid(obj));
                rc = mdd_orphan_delete_obj(env, mdd, key, th);
        }

        if (!rc) {
                /* lov objects will be destroyed by caller */
                mdo_ref_del(env, obj, th);
                if (S_ISDIR(mdd_object_type(obj))) {
                        mdo_ref_del(env, obj, th);
                        mdd_orphan_ref_del(env, mdd, th);
                }
                obj->mod_flags &= ~ORPHAN_OBJ;
        } else {
                CERROR("could not delete object: rc = %d\n",rc);
        }

        mdd_orphan_write_unlock(env, mdd);
        RETURN(rc);
}
示例#10
0
int orph_declare_index_insert(const struct lu_env *env,
			      struct mdd_object *obj,
			      umode_t mode, struct thandle *th)
{
	struct dt_insert_rec	*rec = &mdd_env_info(env)->mti_dt_rec;
	struct mdd_device	*mdd = mdo2mdd(&obj->mod_obj);
	struct dt_key		*key;
	int			rc;

	key = orph_key_fill(env, mdo2fid(obj), ORPH_OP_UNLINK);

	rec->rec_fid = mdo2fid(obj);
	rec->rec_type = mode;
	rc = dt_declare_insert(env, mdd->mdd_orphans,
			       (const struct dt_rec *)rec, key, th);
	if (rc != 0)
		return rc;

	rc = mdo_declare_ref_add(env, obj, th);
	if (rc)
		return rc;

	if (!S_ISDIR(mode))
		return 0;

	rc = mdo_declare_ref_add(env, obj, th);
	if (rc)
		return rc;

	rc = dt_declare_ref_add(env, mdd->mdd_orphans, th);
	if (rc)
		return rc;

	rc = mdo_declare_index_delete(env, obj, dotdot, th);
	if (rc)
		return rc;

	rc = mdo_declare_index_insert(env, obj,
				      lu_object_fid(&mdd->mdd_orphans->do_lu),
				      S_IFDIR, dotdot, th);

	return rc;
}
示例#11
0
int orph_declare_index_insert(const struct lu_env *env,
			      struct mdd_object *obj,
			      cfs_umode_t mode, struct thandle *th)
{
	struct mdd_device	*mdd = mdo2mdd(&obj->mod_obj);
	struct dt_key		*key;
	int			rc;

	key = orph_key_fill(env, mdo2fid(obj), ORPH_OP_UNLINK);

	rc = dt_declare_insert(env, mdd->mdd_orphans, NULL, key, th);
	if (rc)
		return rc;

	rc = mdo_declare_ref_add(env, obj, th);
	if (rc)
		return rc;

	if (!S_ISDIR(mode))
		return 0;

	rc = mdo_declare_ref_add(env, obj, th);
	if (rc)
		return rc;

	rc = dt_declare_ref_add(env, mdd->mdd_orphans, th);
	if (rc)
		return rc;

	rc = mdo_declare_index_delete(env, obj, dotdot, th);
	if (rc)
		return rc;

	rc = mdo_declare_index_insert(env, obj, NULL, dotdot, th);

	return rc;
}
示例#12
0
static int mdd_orphan_destroy(const struct lu_env *env, struct mdd_object *obj,
			      struct dt_key *key)
{
	struct thandle *th = NULL;
	struct mdd_device *mdd = mdo2mdd(&obj->mod_obj);
	bool orphan_exists = true;
	int rc = 0;
	ENTRY;

	th = mdd_trans_create(env, mdd);
	if (IS_ERR(th)) {
		rc = PTR_ERR(th);
		if (rc != -EINPROGRESS)
			CERROR("%s: cannot get orphan thandle: rc = %d\n",
			       mdd2obd_dev(mdd)->obd_name, rc);
		RETURN(rc);
	}

	mdd_write_lock(env, obj, MOR_TGT_CHILD);
	rc = mdd_orphan_declare_delete(env, obj, th);
	if (rc == -ENOENT)
		orphan_exists = false;
	else if (rc)
		GOTO(unlock, rc);

	if (orphan_exists) {
		rc = mdo_declare_destroy(env, obj, th);
		if (rc)
			GOTO(unlock, rc);
	}

	rc = mdd_trans_start(env, mdd, th);
	if (rc)
		GOTO(unlock, rc);

	if (likely(obj->mod_count == 0)) {
		dt_write_lock(env, mdd->mdd_orphans, MOR_TGT_ORPHAN);
		rc = dt_delete(env, mdd->mdd_orphans, key, th);
		if (rc) {
			CERROR("%s: could not delete orphan "DFID": rc = %d\n",
			       mdd2obd_dev(mdd)->obd_name, PFID(mdo2fid(obj)),
			       rc);
		} else if (orphan_exists) {
			mdo_ref_del(env, obj, th);
			if (S_ISDIR(mdd_object_type(obj))) {
				mdo_ref_del(env, obj, th);
				dt_ref_del(env, mdd->mdd_orphans, th);
			}
			rc = mdo_destroy(env, obj, th);
		} else {
			CWARN("%s: orphan %s "DFID" doesn't exist\n",
			      mdd2obd_dev(mdd)->obd_name, (char *)key,
			      PFID(mdo2fid(obj)));
		}
		dt_write_unlock(env, mdd->mdd_orphans);
	}
unlock:
	mdd_write_unlock(env, obj);

	rc = mdd_trans_stop(env, mdd, 0, th);

	RETURN(rc);
}