* Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
* Use is subject to license terms.
*
- * Copyright (c) 2011, 2012, Intel, Inc.
+ * Copyright (c) 2012, Intel Corporation.
*/
/*
* This file is part of Lustre, http://www.lustre.org/
#include "osp_internal.h"
-static __u64 osp_object_assign_id(const struct lu_env *env,
- struct osp_device *d, struct osp_object *o)
+static void osp_object_assign_fid(const struct lu_env *env,
+ struct osp_device *d, struct osp_object *o)
{
- struct osp_thread_info *osi = osp_env_info(env);
- const struct lu_fid *f = lu_object_fid(&o->opo_obj.do_lu);
+ struct osp_thread_info *osi = osp_env_info(env);
- LASSERT(fid_is_zero(f));
+ LASSERT(fid_is_zero(lu_object_fid(&o->opo_obj.do_lu)));
LASSERT(o->opo_reserved);
o->opo_reserved = 0;
- /* assign fid to anonymous object */
- osi->osi_oi.oi_id = osp_precreate_get_id(d);
- osi->osi_oi.oi_seq = FID_SEQ_OST_MDT0;
- fid_ostid_unpack(&osi->osi_fid, &osi->osi_oi, d->opd_index);
- lu_object_assign_fid(env, &o->opo_obj.do_lu, &osi->osi_fid);
+ osp_precreate_get_fid(env, d, &osi->osi_fid);
- return osi->osi_oi.oi_id;
+ lu_object_assign_fid(env, &o->opo_obj.do_lu, &osi->osi_fid);
}
static int osp_declare_attr_set(const struct lu_env *env, struct dt_object *dt,
if (attr == NULL)
RETURN(0);
- if (attr->la_valid & LA_SIZE && attr->la_size > 0) {
+ if (attr->la_valid & LA_SIZE && attr->la_size > 0 &&
+ fid_is_zero(lu_object_fid(&o->opo_obj.do_lu))) {
LASSERT(!dt_object_exists(dt));
- osp_object_assign_id(env, d, o);
+ osp_object_assign_fid(env, d, o);
rc = osp_object_truncate(env, dt, attr->la_size);
if (rc)
RETURN(rc);
ENTRY;
- LASSERT(d->opd_last_used_file);
+ /* should happen to non-0 OSP only so that at least one object
+ * has been already declared in the scenario and LOD should
+ * cleanup that */
+ if (OBD_FAIL_CHECK(OBD_FAIL_MDS_OSC_CREATE_FAIL) && d->opd_index == 1)
+ RETURN(-ENOSPC);
+
+ LASSERT(d->opd_last_used_oid_file);
fid = lu_object_fid(&dt->do_lu);
/*
if (unlikely(!fid_is_zero(fid))) {
/* replay case: caller knows fid */
osi->osi_off = sizeof(osi->osi_id) * d->opd_index;
- rc = dt_declare_record_write(env, d->opd_last_used_file,
+ rc = dt_declare_record_write(env, d->opd_last_used_oid_file,
sizeof(osi->osi_id), osi->osi_off,
th);
RETURN(rc);
/* common for all OSPs file hystorically */
osi->osi_off = sizeof(osi->osi_id) * d->opd_index;
- rc = dt_declare_record_write(env, d->opd_last_used_file,
+ rc = dt_declare_record_write(env, d->opd_last_used_oid_file,
sizeof(osi->osi_id), osi->osi_off,
th);
} else {
/* not needed in the cache anymore */
- cfs_set_bit(LU_OBJECT_HEARD_BANSHEE,
+ set_bit(LU_OBJECT_HEARD_BANSHEE,
&dt->do_lu.lo_header->loh_flags);
}
RETURN(rc);
struct osp_thread_info *osi = osp_env_info(env);
struct osp_device *d = lu2osp_dev(dt->do_lu.lo_dev);
struct osp_object *o = dt2osp_obj(dt);
- int rc = 0;
-
+ int rc = 0;
+ struct lu_fid *fid = &osi->osi_fid;
ENTRY;
if (o->opo_reserved) {
- /* regular case, id is assigned holding transaction open */
- osi->osi_id = osp_object_assign_id(env, d, o);
- } else {
+ /* regular case, fid is assigned holding trunsaction open */
+ osp_object_assign_fid(env, d, o);
+ }
+
+ memcpy(fid, lu_object_fid(&dt->do_lu), sizeof(*fid));
+
+ LASSERTF(fid_is_sane(fid), "fid for osp_obj %p is insane"DFID"!\n",
+ osp_obj, PFID(fid));
+
+ if (!o->opo_reserved) {
/* special case, id was assigned outside of transaction
* see comments in osp_declare_attr_set */
- rc = fid_ostid_pack(lu_object_fid(&dt->do_lu), &osi->osi_oi);
- LASSERT(rc == 0);
- osi->osi_id = ostid_id(&osi->osi_oi);
- cfs_spin_lock(&d->opd_pre_lock);
- osp_update_last_id(d, osi->osi_id);
- cfs_spin_unlock(&d->opd_pre_lock);
+ spin_lock(&d->opd_pre_lock);
+ osp_update_last_fid(d, fid);
+ spin_unlock(&d->opd_pre_lock);
}
- LASSERT(osi->osi_id);
+ CDEBUG(D_INODE, "fid for osp_obj %p is "DFID"!\n", osp_obj, PFID(fid));
+
+ /* If the precreate ends, it means it will be ready to rollover to
+ * the new sequence soon, all the creation should be synchronized,
+ * otherwise during replay, the replay fid will be inconsistent with
+ * last_used/create fid */
+ if (osp_precreate_end_seq(env, d) && osp_is_fid_client(d))
+ th->th_sync = 1;
/*
* it's OK if the import is inactive by this moment - id was created
/* we might have lost precreated objects */
if (unlikely(d->opd_gap_count) > 0) {
- cfs_spin_lock(&d->opd_pre_lock);
+ spin_lock(&d->opd_pre_lock);
if (d->opd_gap_count > 0) {
int count = d->opd_gap_count;
-
- osi->osi_oi.oi_id = d->opd_gap_start;
+ osi->osi_oi.oi_id = fid_oid(&d->opd_gap_start_fid);
d->opd_gap_count = 0;
- cfs_spin_unlock(&d->opd_pre_lock);
+ spin_unlock(&d->opd_pre_lock);
- CDEBUG(D_HA, "Found gap "LPU64"+%d in objids\n",
- d->opd_gap_start, count);
+ CDEBUG(D_HA, "Writting gap "DFID"+%d in llog\n",
+ PFID(&d->opd_gap_start_fid), count);
/* real gap handling is disabled intil ORI-692 will be
* fixed, now we only report gaps */
} else {
- cfs_spin_unlock(&d->opd_pre_lock);
+ spin_unlock(&d->opd_pre_lock);
}
}
* initializing attributes needs no logging */
o->opo_new = 1;
- osp_objid_buf_prep(osi, d, d->opd_index);
- rc = dt_record_write(env, d->opd_last_used_file, &osi->osi_lb,
+ /* Only need update last_used oid file, seq file will only be update
+ * during seq rollover */
+ osp_objid_buf_prep(&osi->osi_lb, &osi->osi_off,
+ &d->opd_last_used_fid.f_oid, d->opd_index);
+
+ rc = dt_record_write(env, d->opd_last_used_oid_file, &osi->osi_lb,
&osi->osi_off, th);
+ CDEBUG(D_HA, "%s: Wrote last used FID: "DFID", index %d: %d\n",
+ d->opd_obd->obd_name, PFID(fid), d->opd_index, rc);
+
RETURN(rc);
}
rc = osp_sync_add(env, o, MDS_UNLINK64_REC, th, NULL);
/* not needed in cache any more */
- cfs_set_bit(LU_OBJECT_HEARD_BANSHEE, &dt->do_lu.lo_header->loh_flags);
+ set_bit(LU_OBJECT_HEARD_BANSHEE, &dt->do_lu.lo_header->loh_flags);
RETURN(rc);
}
.do_destroy = osp_object_destroy,
};
-static int osp_object_init(const struct lu_env *env, struct lu_object *o,
- const struct lu_object_conf *unused)
+static int is_ost_obj(struct lu_object *lo)
{
- struct osp_object *po = lu2osp_obj(o);
+ struct osp_device *osp = lu2osp_dev(lo->lo_dev);
- po->opo_obj.do_ops = &osp_obj_ops;
+ return !osp->opd_connect_mdt;
+}
+
+static int osp_object_init(const struct lu_env *env, struct lu_object *o,
+ const struct lu_object_conf *conf)
+{
+ struct osp_object *po = lu2osp_obj(o);
+ int rc = 0;
+ ENTRY;
- return 0;
+ if (is_ost_obj(o)) {
+ po->opo_obj.do_ops = &osp_obj_ops;
+ } else {
+ struct lu_attr *la = &osp_env_info(env)->osi_attr;
+
+ po->opo_obj.do_ops = &osp_md_obj_ops;
+ o->lo_header->loh_attr |= LOHA_REMOTE;
+ po->opo_obj.do_lock_ops = &osp_md_lock_ops;
+ rc = po->opo_obj.do_ops->do_attr_get(env, lu2dt_obj(o),
+ la, NULL);
+ if (rc == 0)
+ o->lo_header->loh_attr |=
+ LOHA_EXISTS | (la->la_mode & S_IFMT);
+ if (rc == -ENOENT)
+ rc = 0;
+ }
+ RETURN(rc);
}
static void osp_object_free(const struct lu_env *env, struct lu_object *o)
*/
if (unlikely(po->opo_reserved)) {
LASSERT(d->opd_pre_reserved > 0);
- cfs_spin_lock(&d->opd_pre_lock);
+ spin_lock(&d->opd_pre_lock);
d->opd_pre_reserved--;
- cfs_spin_unlock(&d->opd_pre_lock);
+ spin_unlock(&d->opd_pre_lock);
/* not needed in cache any more */
- cfs_set_bit(LU_OBJECT_HEARD_BANSHEE, &o->lo_header->loh_flags);
+ set_bit(LU_OBJECT_HEARD_BANSHEE, &o->lo_header->loh_flags);
}
EXIT;
}