* 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.
*/
/*
int rc;
LASSERT(key);
- rc = snprintf(key, NAME_MAX + 1, ORPHAN_FILE_NAME_FORMAT, fid_seq(lf),
+ rc = snprintf(key, NAME_MAX + 1, ORPHAN_FILE_NAME_FORMAT,
+ (long long unsigned int)fid_seq(lf),
fid_oid(lf), fid_ver(lf), op);
if (rc > 0)
return (struct dt_key*) key;
int rc = 0;
unsigned int op;
- rc = sscanf(key, ORPHAN_FILE_NAME_FORMAT, &lf->f_seq, &lf->f_oid,
+ rc = sscanf(key, ORPHAN_FILE_NAME_FORMAT,
+ (long long unsigned int *)&lf->f_seq, &lf->f_oid,
&lf->f_ver, &op);
if (rc == 4)
return 0;
/* build igif */
rc = sscanf(key, ORPHAN_FILE_NAME_FORMAT_18,
- &lf->f_seq, &lf->f_oid);
+ (long long unsigned int *)&lf->f_seq, &lf->f_oid);
if (rc == 2) {
lf->f_ver = 0;
return 0;
{
struct dt_object *dor = mdd->mdd_orphans;
- dor->do_ops->do_write_lock(env, dor, MOR_TGT_CHILD);
+ dor->do_ops->do_write_lock(env, dor, MOR_TGT_ORPHAN);
}
static inline void mdd_orphan_write_unlock(const struct lu_env *env,
ENTRY;
return dor->do_index_ops->dio_insert(env, dor,
- __mdd_fid_rec(env, lf),
+ (struct dt_rec *)lf,
key, th,
BYPASS_CAPA, 1);
}
int rc;
ENTRY;
+ LASSERT(mdd_write_locked(env, obj) != 0);
+ LASSERT(!(obj->mod_flags & ORPHAN_OBJ));
+ LASSERT(obj->mod_count > 0);
+
mdd_orphan_write_lock(env, mdd);
rc = mdd_orphan_insert_obj(env, mdd, obj, op, th);
dotdot, th, BYPASS_CAPA);
next->do_index_ops->dio_insert(env, next,
- __mdd_fid_rec(env, lf_dor),
+ (struct dt_rec *) lf_dor,
dotdot, th, BYPASS_CAPA, 1);
out:
+ if (rc == 0)
+ obj->mod_flags |= ORPHAN_OBJ;
+
mdd_orphan_write_unlock(env, mdd);
RETURN(rc);
struct thandle *th)
{
struct lu_attr *la = &mdd_env_info(env)->mti_la;
- int rc;
+ int rc = 0;
+ ENTRY;
/* No need to lock this object as its recovery phase, and
* no other thread can access it. But we need to lock it
* as its precondition for osd api we using. */
- mdd_write_lock(env, obj, MOR_TGT_CHILD);
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);
- mdd_write_unlock(env, obj);
} else {
/* regular file , cleanup linked ost objects */
rc = mdd_la_get(env, obj, la, BYPASS_CAPA);
- mdd_write_unlock(env, obj);
- if (rc)
- RETURN(rc);
-
- mdd_lov_destroy(env, mdd, obj, la);
+ if (rc == 0)
+ rc = mdd_lov_destroy(env, mdd, obj, la);
}
- return 0;
+ RETURN(rc);
}
static int orph_index_delete(const struct lu_env *env,
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);
mdo_ref_del(env, obj, th);
mdd_orphan_ref_del(env, mdd, th);
}
- } else
+ obj->mod_flags &= ~ORPHAN_OBJ;
+ } else {
CERROR("could not delete object: rc = %d\n",rc);
+ }
- obj->mod_flags &= ~ORPHAN_OBJ;
mdd_orphan_write_unlock(env, mdd);
RETURN(rc);
}
{
struct thandle *th = NULL;
struct mdd_device *mdd = mdo2mdd(&obj->mod_obj);
- int rc;
+ int rc = 0;
ENTRY;
mdd_txn_param_build(env, mdd, MDD_TXN_UNLINK_OP);
RETURN(-ENOMEM);
}
- 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_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);
rc = -EBUSY;
if (mdo->mod_count == 0) {
- CWARN("Found orphan!\n");
+ CWARN("Found orphan! Delete it\n");
rc = orphan_object_destroy(env, mdo, key);
} else {
- mdo->mod_flags |= ORPHAN_OBJ;
+ mdd_write_lock(env, mdo, MOR_TGT_CHILD);
+ if (likely(mdo->mod_count > 0)) {
+ CDEBUG(D_HA, "Found orphan, open count = %d\n",
+ mdo->mod_count);
+ mdo->mod_flags |= ORPHAN_OBJ;
+ }
+ mdd_write_unlock(env, mdo);
}
mdd_object_put(env, mdo);
iops = &dor->do_index_ops->dio_it;
it = iops->init(env, dor, BYPASS_CAPA);
if (it != NULL) {
- result = iops->get(env, it, (const void *)"");
+ result = iops->load(env, it, 0);
if (result > 0) {
/* main cycle */
do {
key = (void *)iops->key(env, it);
- if (IS_ERR(key))
+ if (IS_ERR(key)) {
+ CERROR("key failed when clean pending.\n");
goto next;
+ }
key_sz = iops->key_size(env, it);
/* filter out "." and ".." entries from
if (orphan_key_to_fid(mti_key, &fid))
goto next;
- if (!fid_is_sane(&fid))
+ if (!fid_is_sane(&fid)) {
+ CERROR("fid is not sane when clean pending.\n");
goto next;
+ }
/* kill orphan object */
cookie = iops->store(env, it);
result = iops->next(env, it);
} while (result == 0);
result = 0;
- } else if (result == 0)
+ } else if (result == 0) {
+ CERROR("Input/Output for clean pending.\n");
/* Index contains no zero key? */
result = -EIO;
+ }
iops->put(env, it);
iops->fini(env, it);
- } else
+ } else {
+ CERROR("not enough memory for clean pending.\n");
result = -ENOMEM;
+ }
RETURN(result);
}
* \pre obj nlink == 0 && obj->mod_count != 0
*
* \retval 0 success
- * \retva -ve index operation error.
+ * \retval -ve index operation error.
*/
int __mdd_orphan_add(const struct lu_env *env,
* \pre obj->mod_count == 0 && ORPHAN_OBJ is set for obj.
*
* \retval 0 success
- * \retva -ve index operation error.
+ * \retval -ve index operation error.
*/
int __mdd_orphan_del(const struct lu_env *env,