RETURN(rc);
if (likely(S_ISDIR(mdd_object_type(mdd_obj)) &&
- dt_try_as_dir(env, dir))) {
-
- rc = dir->do_index_ops->dio_lookup(env, dir,
- (struct dt_rec *)fid, key,
- mdd_object_capa(env, mdd_obj));
- if (rc > 0)
- rc = 0;
- else if (rc == 0)
- rc = -ENOENT;
- } else
+ dt_try_as_dir(env, dir)))
+ rc = dt_lookup(env, dir, (struct dt_rec *)fid, key,
+ mdd_object_capa(env, mdd_obj));
+ else
rc = -ENOTDIR;
RETURN(rc);
if (rc != 0)
RETURN(rc);
- rc = __mdd_lookup(env, pobj, pattr, lname, fid, MAY_EXEC);
+ rc = __mdd_lookup(env, pobj, pattr, lname, fid,
+ (spec != NULL && spec->sp_permitted) ? 0 : MAY_EXEC);
RETURN(rc);
}
if (mdd_is_dead_obj(pobj))
RETURN(-ENOENT);
- if ((attr->la_valid & LA_FLAGS) &&
- (attr->la_flags & (LUSTRE_APPEND_FL | LUSTRE_IMMUTABLE_FL)))
+ if (attr->la_flags & (LUSTRE_APPEND_FL | LUSTRE_IMMUTABLE_FL))
RETURN(-EPERM);
rc = mdd_permission_internal_locked(env, pobj, pattr,
MAY_WRITE | MAY_EXEC,
MOR_TGT_PARENT);
- if (rc)
+ if (rc != 0)
RETURN(rc);
- if (mdd_is_append(pobj))
+ if (pattr->la_flags & LUSTRE_APPEND_FL)
RETURN(-EPERM);
RETURN(rc);
RETURN(rc);
}
- if (mdd_is_append(pobj))
+ if (pattr->la_flags & LUSTRE_APPEND_FL)
RETURN(-EPERM);
RETURN(0);
if (mdd_is_sticky(env, tpobj, tpattr, tobj, tattr))
RETURN(-EPERM);
- if (mdd_is_immutable(tobj) || mdd_is_append(tobj))
- RETURN(-EPERM);
-
- if ((tattr->la_valid & LA_FLAGS) &&
- (tattr->la_flags & (LUSTRE_APPEND_FL | LUSTRE_IMMUTABLE_FL)))
+ if (tattr->la_flags & (LUSTRE_APPEND_FL | LUSTRE_IMMUTABLE_FL))
RETURN(-EPERM);
/* additional check the rename case */
if (rc < 0)
RETURN(rc);
- if (mdd_is_immutable(src_obj) || mdd_is_append(src_obj))
- RETURN(-EPERM);
+ if (cattr->la_flags & (LUSTRE_IMMUTABLE_FL | LUSTRE_APPEND_FL))
+ RETURN(-EPERM);
- if (S_ISDIR(mdd_object_type(src_obj)))
- RETURN(-EPERM);
+ if (S_ISDIR(mdd_object_type(src_obj)))
+ RETURN(-EPERM);
LASSERT(src_obj != tgt_obj);
rc = mdd_may_create(env, tgt_obj, tattr, NULL, true);
}
static int __mdd_index_delete_only(const struct lu_env *env, struct mdd_object *pobj,
- const char *name, struct thandle *handle,
- struct lustre_capa *capa)
+ const char *name, struct thandle *handle,
+ struct lustre_capa *capa)
{
- struct dt_object *next = mdd_object_child(pobj);
- int rc;
- ENTRY;
+ struct dt_object *next = mdd_object_child(pobj);
+ int rc;
+ ENTRY;
- if (dt_try_as_dir(env, next)) {
- rc = next->do_index_ops->dio_delete(env, next,
- (struct dt_key *)name,
- handle, capa);
- } else
- rc = -ENOTDIR;
+ if (dt_try_as_dir(env, next))
+ rc = dt_delete(env, next, (struct dt_key *)name, handle, capa);
+ else
+ rc = -ENOTDIR;
- RETURN(rc);
+ RETURN(rc);
}
static int __mdd_index_insert_only(const struct lu_env *env,
rec->rec_fid = lf;
rec->rec_type = type;
ignore_quota = uc ? uc->uc_cap & CFS_CAP_SYS_RESOURCE_MASK : 1;
- rc = next->do_index_ops->dio_insert(env, next,
- (const struct dt_rec *)rec,
- (const struct dt_key *)name,
- handle, capa, ignore_quota);
+ rc = dt_insert(env, next, (const struct dt_rec *)rec,
+ (const struct dt_key *)name, handle, capa,
+ ignore_quota);
} else {
rc = -ENOTDIR;
}
RETURN(rc);
}
-int mdd_declare_changelog_store(const struct lu_env *env,
- struct mdd_device *mdd,
- const struct lu_name *fname,
- struct thandle *handle)
+static int mdd_llog_record_calc_size(const struct lu_env *env,
+ const struct lu_name *tname,
+ const struct lu_name *sname)
{
- struct obd_device *obd = mdd2obd_dev(mdd);
- struct llog_ctxt *ctxt;
- struct llog_changelog_rec *rec;
- struct lu_buf *buf;
- int reclen;
- int rc;
-
- /* Not recording */
- if (!(mdd->mdd_cl.mc_flags & CLM_ON))
- return 0;
+ const struct lu_ucred *uc = lu_ucred(env);
+ enum changelog_rec_flags crf = 0;
+ size_t hdr_size = sizeof(struct llog_changelog_rec) -
+ sizeof(struct changelog_rec);
- reclen = llog_data_len(sizeof(*rec) +
- (fname != NULL ? fname->ln_namelen : 0));
- buf = lu_buf_check_and_alloc(&mdd_env_info(env)->mti_big_buf, reclen);
- if (buf->lb_buf == NULL)
- return -ENOMEM;
+ if (sname != NULL)
+ crf |= CLF_RENAME;
- rec = buf->lb_buf;
- rec->cr_hdr.lrh_len = reclen;
- rec->cr_hdr.lrh_type = CHANGELOG_REC;
+ if (uc != NULL && uc->uc_jobid[0] != '\0')
+ crf |= CLF_JOBID;
- ctxt = llog_get_context(obd, LLOG_CHANGELOG_ORIG_CTXT);
- if (ctxt == NULL)
- return -ENXIO;
-
- rc = llog_declare_add(env, ctxt->loc_handle, &rec->cr_hdr, handle);
- llog_ctxt_put(ctxt);
-
- return rc;
+ return llog_data_len(hdr_size + changelog_rec_offset(crf) +
+ (tname != NULL ? tname->ln_namelen : 0) +
+ (sname != NULL ? 1 + sname->ln_namelen : 0));
}
-static int mdd_declare_changelog_ext_store(const struct lu_env *env,
- struct mdd_device *mdd,
- const struct lu_name *tname,
- const struct lu_name *sname,
- struct thandle *handle)
+int mdd_declare_changelog_store(const struct lu_env *env,
+ struct mdd_device *mdd,
+ const struct lu_name *tname,
+ const struct lu_name *sname,
+ struct thandle *handle)
{
struct obd_device *obd = mdd2obd_dev(mdd);
struct llog_ctxt *ctxt;
- struct llog_changelog_ext_rec *rec;
+ struct llog_changelog_rec *rec;
struct lu_buf *buf;
int reclen;
int rc;
if (!(mdd->mdd_cl.mc_flags & CLM_ON))
return 0;
- reclen = llog_data_len(sizeof(*rec) +
- (tname != NULL ? tname->ln_namelen : 0) +
- (sname != NULL ? 1 + sname->ln_namelen : 0));
+ reclen = mdd_llog_record_calc_size(env, tname, sname);
buf = lu_buf_check_and_alloc(&mdd_env_info(env)->mti_big_buf, reclen);
if (buf->lb_buf == NULL)
return -ENOMEM;
* \param mdd
* \param rec
* \param handle - currently ignored since llogs start their own transaction;
- * this will hopefully be fixed in llog rewrite
+ * this will hopefully be fixed in llog rewrite
* \retval 0 ok
*/
int mdd_changelog_store(const struct lu_env *env, struct mdd_device *mdd,
struct llog_ctxt *ctxt;
int rc;
- rec->cr_hdr.lrh_len = llog_data_len(sizeof(*rec) + rec->cr.cr_namelen);
- rec->cr_hdr.lrh_type = CHANGELOG_REC;
- rec->cr.cr_time = cl_time();
-
- spin_lock(&mdd->mdd_cl.mc_lock);
- /* NB: I suppose it's possible llog_add adds out of order wrt cr_index,
- * but as long as the MDD transactions are ordered correctly for e.g.
- * rename conflicts, I don't think this should matter. */
- rec->cr.cr_index = ++mdd->mdd_cl.mc_index;
- spin_unlock(&mdd->mdd_cl.mc_lock);
+ rec->cr_hdr.lrh_len = llog_data_len(sizeof(*rec) +
+ changelog_rec_varsize(&rec->cr));
- ctxt = llog_get_context(obd, LLOG_CHANGELOG_ORIG_CTXT);
- if (ctxt == NULL)
- return -ENXIO;
-
- rc = llog_add(env, ctxt->loc_handle, &rec->cr_hdr, NULL, th);
- llog_ctxt_put(ctxt);
- if (rc > 0)
- rc = 0;
- return rc;
-}
-
-/** Add a changelog_ext entry \a rec to the changelog llog
- * \param mdd
- * \param rec
- * \param handle - currently ignored since llogs start their own transaction;
- * this will hopefully be fixed in llog rewrite
- * \retval 0 ok
- */
-static int
-mdd_changelog_ext_store(const struct lu_env *env, struct mdd_device *mdd,
- struct llog_changelog_ext_rec *rec, struct thandle *th)
-{
- struct obd_device *obd = mdd2obd_dev(mdd);
- struct llog_ctxt *ctxt;
- int rc;
-
- rec->cr_hdr.lrh_len = llog_data_len(sizeof(*rec) + rec->cr.cr_namelen);
/* llog_lvfs_write_rec sets the llog tail len */
rec->cr_hdr.lrh_type = CHANGELOG_REC;
rec->cr.cr_time = cl_time();
return rc;
}
-/** Store a namespace change changelog record
- * If this fails, we must fail the whole transaction; we don't
- * want the change to commit without the log entry.
- * \param target - mdd_object of change
- * \param parent - parent dir/object
- * \param tname - target name string
- * \param handle - transacion handle
- */
-int mdd_changelog_ns_store(const struct lu_env *env, struct mdd_device *mdd,
- enum changelog_rec_type type, unsigned flags,
- struct mdd_object *target, struct mdd_object *parent,
- const struct lu_name *tname, struct thandle *handle)
+static void mdd_changelog_rec_ext_rename(struct changelog_rec *rec,
+ const struct lu_fid *sfid,
+ const struct lu_fid *spfid,
+ const struct lu_name *sname)
{
- struct llog_changelog_rec *rec;
- struct lu_buf *buf;
- int reclen;
- int rc;
- ENTRY;
+ struct changelog_ext_rename *rnm = changelog_rec_rename(rec);
+ size_t extsize = sname->ln_namelen + 1;
- /* Not recording */
- if (!(mdd->mdd_cl.mc_flags & CLM_ON))
- RETURN(0);
- if ((mdd->mdd_cl.mc_mask & (1 << type)) == 0)
- RETURN(0);
+ LASSERT(sfid != NULL);
+ LASSERT(spfid != NULL);
+ LASSERT(sname != NULL);
- LASSERT(target != NULL);
- LASSERT(parent != NULL);
- LASSERT(tname != NULL);
- LASSERT(handle != NULL);
+ rnm->cr_sfid = *sfid;
+ rnm->cr_spfid = *spfid;
- reclen = llog_data_len(sizeof(*rec) + tname->ln_namelen);
- buf = lu_buf_check_and_alloc(&mdd_env_info(env)->mti_big_buf, reclen);
- if (buf->lb_buf == NULL)
- RETURN(-ENOMEM);
- rec = buf->lb_buf;
-
- rec->cr.cr_flags = CLF_VERSION | (CLF_FLAGMASK & flags);
- rec->cr.cr_type = (__u32)type;
- rec->cr.cr_tfid = *mdo2fid(target);
- rec->cr.cr_pfid = *mdo2fid(parent);
- rec->cr.cr_namelen = tname->ln_namelen;
- memcpy(rec->cr.cr_name, tname->ln_name, tname->ln_namelen);
+ changelog_rec_name(rec)[rec->cr_namelen] = '\0';
+ strlcpy(changelog_rec_sname(rec), sname->ln_name, extsize);
+ rec->cr_namelen += extsize;
+}
- target->mod_cltime = cfs_time_current_64();
+void mdd_changelog_rec_ext_jobid(struct changelog_rec *rec, const char *jobid)
+{
+ struct changelog_ext_jobid *jid = changelog_rec_jobid(rec);
- rc = mdd_changelog_store(env, mdd, rec, handle);
- if (rc < 0) {
- CERROR("changelog failed: rc=%d, op%d %s c"DFID" p"DFID"\n",
- rc, type, tname->ln_name, PFID(&rec->cr.cr_tfid),
- PFID(&rec->cr.cr_pfid));
- RETURN(-EFAULT);
- }
+ if (jobid == NULL || jobid[0] == '\0')
+ return;
- RETURN(0);
+ strlcpy(jid->cr_jobid, jobid, sizeof(jid->cr_jobid));
}
-
/** Store a namespace change changelog record
* If this fails, we must fail the whole transaction; we don't
* want the change to commit without the log entry.
* \param sname - source name string
* \param handle - transacion handle
*/
-static int mdd_changelog_ext_ns_store(const struct lu_env *env,
- struct mdd_device *mdd,
- enum changelog_rec_type type,
- unsigned flags,
- struct mdd_object *target,
- const struct lu_fid *tpfid,
- const struct lu_fid *sfid,
- const struct lu_fid *spfid,
- const struct lu_name *tname,
- const struct lu_name *sname,
- struct thandle *handle)
+int mdd_changelog_ns_store(const struct lu_env *env,
+ struct mdd_device *mdd,
+ enum changelog_rec_type type,
+ enum changelog_rec_flags crf,
+ struct mdd_object *target,
+ const struct lu_fid *tpfid,
+ const struct lu_fid *sfid,
+ const struct lu_fid *spfid,
+ const struct lu_name *tname,
+ const struct lu_name *sname,
+ struct thandle *handle)
{
- struct llog_changelog_ext_rec *rec;
- struct lu_buf *buf;
- int reclen;
- int rc;
+ const struct lu_ucred *uc = lu_ucred(env);
+ struct llog_changelog_rec *rec;
+ struct lu_buf *buf;
+ int reclen;
+ int rc;
ENTRY;
/* Not recording */
if (!(mdd->mdd_cl.mc_flags & CLM_ON))
RETURN(0);
+
if ((mdd->mdd_cl.mc_mask & (1 << type)) == 0)
RETURN(0);
- LASSERT(sfid != NULL);
LASSERT(tpfid != NULL);
LASSERT(tname != NULL);
LASSERT(handle != NULL);
- reclen = llog_data_len(sizeof(*rec) +
- sname != NULL ? 1 + sname->ln_namelen : 0);
+ reclen = mdd_llog_record_calc_size(env, tname, sname);
buf = lu_buf_check_and_alloc(&mdd_env_info(env)->mti_big_buf, reclen);
if (buf->lb_buf == NULL)
RETURN(-ENOMEM);
rec = buf->lb_buf;
- rec->cr.cr_flags = CLF_EXT_VERSION | (CLF_FLAGMASK & flags);
+ crf = (crf & CLF_FLAGMASK);
+
+ if (uc->uc_jobid[0] != '\0')
+ crf |= CLF_JOBID;
+
+ if (sname != NULL)
+ crf |= CLF_RENAME;
+ else
+ crf |= CLF_VERSION;
+
+ rec->cr.cr_flags = crf;
rec->cr.cr_type = (__u32)type;
rec->cr.cr_pfid = *tpfid;
- rec->cr.cr_sfid = *sfid;
- rec->cr.cr_spfid = *spfid;
rec->cr.cr_namelen = tname->ln_namelen;
- memcpy(rec->cr.cr_name, tname->ln_name, tname->ln_namelen);
- if (sname) {
- rec->cr.cr_name[tname->ln_namelen] = '\0';
- memcpy(rec->cr.cr_name + tname->ln_namelen + 1, sname->ln_name,
- sname->ln_namelen);
- rec->cr.cr_namelen += 1 + sname->ln_namelen;
- }
+ memcpy(changelog_rec_name(&rec->cr), tname->ln_name, tname->ln_namelen);
+
+ if (crf & CLF_RENAME)
+ mdd_changelog_rec_ext_rename(&rec->cr, sfid, spfid, sname);
+
+ if (crf & CLF_JOBID)
+ mdd_changelog_rec_ext_jobid(&rec->cr, uc->uc_jobid);
if (likely(target != NULL)) {
rec->cr.cr_tfid = *mdo2fid(target);
fid_zero(&rec->cr.cr_tfid);
}
- rc = mdd_changelog_ext_store(env, mdd, rec, handle);
+ rc = mdd_changelog_store(env, mdd, rec, handle);
if (rc < 0) {
CERROR("changelog failed: rc=%d, op%d %s c"DFID" p"DFID"\n",
rc, type, tname->ln_name, PFID(sfid), PFID(tpfid));
{
const struct lu_buf *buf = mdd_buf_get_const(env, ldata->ld_buf->lb_buf,
ldata->ld_leh->leh_len);
- return mdo_xattr_set(env, mdd_obj, buf, XATTR_NAME_LINK, 0, handle,
- mdd_object_capa(env, mdd_obj));
+ int rc;
+
+ if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_NO_LINKEA))
+ return 0;
+
+ rc = mdo_xattr_set(env, mdd_obj, buf, XATTR_NAME_LINK, 0, handle,
+ mdd_object_capa(env, mdd_obj));
+ if (unlikely(rc == -ENOSPC) && S_ISREG(mdd_object_type(mdd_obj)) &&
+ mdd_object_remote(mdd_obj) == 0) {
+ struct lfsck_request *lr = &mdd_env_info(env)->mti_lr;
+
+ /* XXX: If the linkEA is overflow, then we need to notify the
+ * namespace LFSCK to skip "nlink" attribute verification
+ * on this object to avoid the "nlink" to be shrinked by
+ * wrong. It may be not good an interaction with LFSCK
+ * like this. We will consider to replace it with other
+ * mechanism in future. LU-5802. */
+ lfsck_pack_rfa(lr, mdo2fid(mdd_obj), LE_SKIP_NLINK,
+ LFSCK_TYPE_NAMESPACE);
+ lfsck_in_notify(env, mdo2mdd(&mdd_obj->mod_obj)->mdd_bottom,
+ lr, handle);
+ }
+
+ return rc;
}
int mdd_declare_links_add(const struct lu_env *env, struct mdd_object *mdd_obj,
- struct thandle *handle, struct linkea_data *ldata)
+ struct thandle *handle, struct linkea_data *ldata,
+ enum mdd_links_add_overflow overflow)
{
int rc;
int ea_len;
rc = mdo_declare_xattr_set(env, mdd_obj,
mdd_buf_get_const(env, linkea, ea_len),
XATTR_NAME_LINK, 0, handle);
+ if (rc != 0)
+ return rc;
+
+ if (mdd_object_remote(mdd_obj) == 0 && overflow == MLAO_CHECK) {
+ struct lfsck_request *lr = &mdd_env_info(env)->mti_lr;
+
+ /* XXX: If the linkEA is overflow, then we need to notify the
+ * namespace LFSCK to skip "nlink" attribute verification
+ * on this object to avoid the "nlink" to be shrinked by
+ * wrong. It may be not good an interaction with LFSCK
+ * like this. We will consider to replace it with other
+ * mechanism in future. LU-5802. */
+ lfsck_pack_rfa(lr, mdo2fid(mdd_obj), LE_SKIP_NLINK_DECLARE,
+ LFSCK_TYPE_NAMESPACE);
+ rc = lfsck_in_notify(env,
+ mdo2mdd(&mdd_obj->mod_obj)->mdd_bottom,
+ lr, handle);
+ }
+
return rc;
}
/* For directory, the linkEA will be removed together
* with the object. */
if (!S_ISDIR(mdd_object_type(c)))
- rc = mdd_declare_links_add(env, c, handle, NULL);
+ rc = mdd_declare_links_add(env, c, handle, NULL, MLAO_IGNORE);
return rc;
}
rc = mdo_declare_index_insert(env, p, mdo2fid(c), mdd_object_type(c),
name->ln_name, handle);
if (rc != 0)
- return rc;
+ return rc;
- rc = mdo_declare_ref_add(env, c, handle);
- if (rc)
- return rc;
+ rc = mdo_declare_ref_add(env, c, handle);
+ if (rc != 0)
+ return rc;
+
+ if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_MORE_NLINK)) {
+ rc = mdo_declare_ref_add(env, c, handle);
+ if (rc != 0)
+ return rc;
+ }
la->la_valid = LA_CTIME | LA_MTIME;
rc = mdo_declare_attr_set(env, p, la, handle);
la->la_valid = LA_CTIME;
rc = mdo_declare_attr_set(env, c, la, handle);
- if (rc)
- return rc;
+ if (rc != 0)
+ return rc;
- rc = mdd_declare_links_add(env, c, handle, data);
- if (rc)
- return rc;
+ rc = mdd_declare_links_add(env, c, handle, data,
+ S_ISREG(mdd_object_type(c)) ? MLAO_CHECK : MLAO_IGNORE);
+ if (rc != 0)
+ return rc;
- rc = mdd_declare_changelog_store(env, mdd, name, handle);
+ rc = mdd_declare_changelog_store(env, mdd, name, NULL, handle);
- return rc;
+ return rc;
}
static int mdd_link(const struct lu_env *env, struct md_object *tgt_obj,
if (rc)
GOTO(out_unlock, rc);
- rc = mdo_ref_add(env, mdd_sobj, handle);
- if (rc)
- GOTO(out_unlock, rc);
+ if (!OBD_FAIL_CHECK(OBD_FAIL_LFSCK_LESS_NLINK)) {
+ rc = mdo_ref_add(env, mdd_sobj, handle);
+ if (rc != 0)
+ GOTO(out_unlock, rc);
+ }
+ if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_MORE_NLINK)) {
+ rc = mdo_ref_add(env, mdd_sobj, handle);
+ if (rc != 0)
+ GOTO(out_unlock, rc);
+ }
+
+ if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_DANGLING3)) {
+ struct lu_fid tfid = *mdo2fid(mdd_sobj);
+
+ tfid.f_oid++;
+ rc = __mdd_index_insert_only(env, mdd_tobj, &tfid,
+ mdd_object_type(mdd_sobj),
+ name, handle,
+ mdd_object_capa(env, mdd_tobj));
+ } else {
+ rc = __mdd_index_insert_only(env, mdd_tobj, mdo2fid(mdd_sobj),
+ mdd_object_type(mdd_sobj),
+ name, handle,
+ mdd_object_capa(env, mdd_tobj));
+ }
- rc = __mdd_index_insert_only(env, mdd_tobj, mdo2fid(mdd_sobj),
- mdd_object_type(mdd_sobj), name, handle,
- mdd_object_capa(env, mdd_tobj));
if (rc != 0) {
mdo_ref_del(env, mdd_sobj, handle);
GOTO(out_unlock, rc);
mdd_write_unlock(env, mdd_sobj);
if (rc == 0)
rc = mdd_changelog_ns_store(env, mdd, CL_HARDLINK, 0, mdd_sobj,
- mdd_tobj, lname, handle);
+ mdo2fid(mdd_tobj), NULL, NULL,
+ lname, NULL, handle);
stop:
mdd_trans_stop(env, mdd, rc, handle);
static int mdd_declare_unlink(const struct lu_env *env, struct mdd_device *mdd,
struct mdd_object *p, struct mdd_object *c,
const struct lu_name *name, struct md_attr *ma,
- struct thandle *handle, int no_name)
+ struct thandle *handle, int no_name, int is_dir)
{
- struct lu_attr *la = &mdd_env_info(env)->mti_la_for_fix;
- int rc;
+ struct lu_attr *la = &mdd_env_info(env)->mti_la_for_fix;
+ int rc;
- if (likely(no_name == 0)) {
- rc = mdo_declare_index_delete(env, p, name->ln_name, handle);
- if (rc)
- return rc;
- }
+ if (!OBD_FAIL_CHECK(OBD_FAIL_LFSCK_DANGLING2)) {
+ if (likely(no_name == 0)) {
+ rc = mdo_declare_index_delete(env, p, name->ln_name,
+ handle);
+ if (rc != 0)
+ return rc;
+ }
- rc = mdo_declare_ref_del(env, p, handle);
- if (rc)
- return rc;
+ if (is_dir != 0) {
+ rc = mdo_declare_ref_del(env, p, handle);
+ if (rc != 0)
+ return rc;
+ }
+ }
LASSERT(ma->ma_attr.la_valid & LA_CTIME);
la->la_ctime = la->la_mtime = ma->ma_attr.la_ctime;
return rc;
/* FIXME: need changelog for remove entry */
- rc = mdd_declare_changelog_store(env, mdd, name, handle);
+ rc = mdd_declare_changelog_store(env, mdd, name, NULL, handle);
}
return rc;
RETURN(PTR_ERR(handle));
rc = mdd_declare_unlink(env, mdd, mdd_pobj, mdd_cobj,
- lname, ma, handle, no_name);
+ lname, ma, handle, no_name, is_dir);
if (rc)
GOTO(stop, rc);
if (likely(mdd_cobj != NULL))
mdd_write_lock(env, mdd_cobj, MOR_TGT_CHILD);
- if (likely(no_name == 0)) {
+ if (likely(no_name == 0) && !OBD_FAIL_CHECK(OBD_FAIL_LFSCK_DANGLING2)) {
rc = __mdd_index_delete(env, mdd_pobj, name, is_dir, handle,
mdd_object_capa(env, mdd_pobj));
if (rc)
GOTO(cleanup, rc);
}
+ if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_MUL_REF) ||
+ OBD_FAIL_CHECK(OBD_FAIL_LFSCK_NO_NAMEENTRY))
+ GOTO(cleanup, rc = 0);
+
if (likely(mdd_cobj != NULL)) {
rc = mdo_ref_del(env, mdd_cobj, handle);
if (rc != 0) {
}
EXIT;
cleanup:
- mdd_write_unlock(env, mdd_cobj);
+ if (likely(mdd_cobj != NULL))
+ mdd_write_unlock(env, mdd_cobj);
+
if (rc == 0) {
int cl_flags = 0;
rc = mdd_changelog_ns_store(env, mdd,
is_dir ? CL_RMDIR : CL_UNLINK, cl_flags,
- mdd_cobj, mdd_pobj, lname, handle);
+ mdd_cobj, mdo2fid(mdd_pobj), NULL, NULL, lname, NULL,
+ handle);
}
stop:
if (rc)
GOTO(stop, rc);
- rc = mdd_declare_changelog_store(env, mdd, NULL, handle);
+ rc = mdd_declare_changelog_store(env, mdd, NULL, NULL, handle);
if (rc)
GOTO(stop, rc);
struct lu_attr *attr, struct thandle *handle,
const struct md_op_spec *spec)
{
- int rc;
- ENTRY;
-
- /*
- * Update attributes for child.
- *
- * FIXME:
- * (1) the valid bits should be converted between Lustre and Linux;
- * (2) maybe, the child attributes should be set in OSD when creation.
- */
+ int rc = 0;
+ ENTRY;
- rc = mdd_attr_set_internal(env, child, attr, handle, 0);
- /* arguments are supposed to stay the same */
if (S_ISDIR(attr->la_mode)) {
/* Add "." and ".." for newly created dir */
mdo_ref_add(env, child, handle);
if (rc != 0)
return rc;
- rc = mdd_declare_links_add(env, c, handle, ldata);
+ rc = mdd_declare_links_add(env, c, handle, ldata, MLAO_IGNORE);
if (rc)
return rc;
if (rc)
return rc;
- rc = mdd_declare_changelog_store(env, mdd, name, handle);
+ rc = mdd_declare_changelog_store(env, mdd, name, NULL, handle);
if (rc)
return rc;
}
/* During creation, there are only a few cases we need do xattr_set to
* create stripes.
* 1. regular file: see comments above.
- * 2. create striped directory with provided stripeEA.
- * 3. create striped directory because inherit default layout from the
- * parent. */
+ * 2. dir: inherit default striping or pool settings from parent.
+ * 3. create striped directory with provided stripeEA.
+ * 4. create striped directory because inherit default layout from the
+ * parent.
+ */
if (spec->no_create ||
(S_ISREG(attr->la_mode) && spec->sp_cr_flags & MDS_OPEN_HAS_EA) ||
S_ISDIR(attr->la_mode)) {
mdd_object_make_hint(env, mdd_pobj, son, attr, spec, hint);
memset(ldata, 0, sizeof(*ldata));
- rc = mdd_linkea_prepare(env, son, NULL, NULL,
- mdd_object_fid(mdd_pobj),
- lname, 1, 0, ldata);
+ if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_BAD_PARENT)) {
+ struct lu_fid tfid = *mdd_object_fid(mdd_pobj);
+
+ tfid.f_oid--;
+ rc = mdd_linkea_prepare(env, son, NULL, NULL,
+ &tfid, lname, 1, 0, ldata);
+ } else {
+ rc = mdd_linkea_prepare(env, son, NULL, NULL,
+ mdd_object_fid(mdd_pobj),
+ lname, 1, 0, ldata);
+ }
rc = mdd_declare_create(env, mdd, mdd_pobj, son, lname, attr,
handle, spec, ldata, &def_acl_buf, &acl_buf,
S_ISDIR(attr->la_mode) ? CL_MKDIR :
S_ISREG(attr->la_mode) ? CL_CREATE :
S_ISLNK(attr->la_mode) ? CL_SOFTLINK : CL_MKNOD,
- 0, son, mdd_pobj, lname, handle);
+ 0, son, mdo2fid(mdd_pobj), NULL, NULL, lname,
+ NULL, handle);
out_stop:
rc2 = mdd_trans_stop(env, mdd, rc, handle);
if (rc == 0)
if (rc)
return rc;
- rc = mdd_declare_links_add(env, mdd_sobj, handle, ldata);
+ rc = mdd_declare_links_add(env, mdd_sobj, handle, ldata,
+ S_ISREG(mdd_object_type(mdd_sobj)) ? MLAO_CHECK : MLAO_IGNORE);
if (rc)
return rc;
return rc;
}
- rc = mdd_declare_changelog_ext_store(env, mdd, tname, sname, handle);
+ rc = mdd_declare_changelog_store(env, mdd, tname, sname, handle);
if (rc)
return rc;
cleanup_unlocked:
if (rc == 0)
- rc = mdd_changelog_ext_ns_store(env, mdd, CL_RENAME, cl_flags,
- mdd_tobj, tpobj_fid, lf,
- spobj_fid, ltname, lsname,
- handle);
+ rc = mdd_changelog_ns_store(env, mdd, CL_RENAME, cl_flags,
+ mdd_tobj, tpobj_fid, lf, spobj_fid,
+ ltname, lsname, handle);
stop:
mdd_trans_stop(env, mdd, rc, handle);
linkea_entry_pack(ldata.ld_lee, &lname,
mdd_object_fid(parent));
if (declare)
- rc = mdd_declare_links_add(env, child, handle, &ldata);
+ rc = mdd_declare_links_add(env, child, handle, &ldata,
+ MLAO_IGNORE);
else
rc = mdd_links_write(env, child, &ldata, handle);
break;
}
if (declare)
- rc = mdd_declare_links_add(env, mdd_tobj, handle, ldata);
+ rc = mdd_declare_links_add(env, mdd_tobj, handle, ldata,
+ MLAO_IGNORE);
else
rc = mdd_links_write(env, mdd_tobj, ldata, handle);
la_flag->la_valid = LA_FLAGS;
la_flag->la_flags = la->la_flags | LUSTRE_IMMUTABLE_FL;
- mdd_flags_xlate(mdd_sobj, la_flag->la_flags);
rc = mdo_declare_attr_set(env, mdd_sobj, la_flag, handle);
return rc;
* flag and approve the migration */
la_flag->la_valid = LA_FLAGS;
la_flag->la_flags = la->la_flags | LUSTRE_IMMUTABLE_FL;
- mdd_flags_xlate(mdd_sobj, la_flag->la_flags);
rc = mdo_attr_set(env, mdd_sobj, la_flag, handle,
mdd_object_capa(env, mdd_sobj));
stop_trans:
if (dt_try_as_dir(env, dt_tobj)) {
struct lu_fid *fid = &mdd_env_info(env)->mti_fid2;
- rc = dt_tobj->do_index_ops->dio_lookup(env, dt_tobj,
- (struct dt_rec *)fid,
- (struct dt_key *)name,
- mdd_object_capa(env, mdd_tobj));
+ rc = dt_lookup(env, dt_tobj, (struct dt_rec *)fid,
+ (struct dt_key *)name,
+ mdd_object_capa(env, mdd_tobj));
if (unlikely(rc == 0))
target_exist = true;
}
/* Revert IMMUTABLE flag */
la_flag->la_valid = LA_FLAGS;
la_flag->la_flags = la->la_flags & ~LUSTRE_IMMUTABLE_FL;
- mdd_flags_xlate(mdd_sobj, la_flag->la_flags);
rc = mdo_declare_attr_set(env, mdd_sobj, la_flag, handle);
if (rc != 0)
return rc;
/* Revert IMMUTABLE flag */
la_flag->la_valid = LA_FLAGS;
la_flag->la_flags = so_attr->la_flags & ~LUSTRE_IMMUTABLE_FL;
- mdd_flags_xlate(mdd_sobj, la_flag->la_flags);
rc = mdo_attr_set(env, mdd_sobj, la_flag, handle,
mdd_object_capa(env, mdd_pobj));
if (rc != 0)
rc = mdd_la_get(env, mdd_sobj, so_attr,
mdd_object_capa(env, mdd_sobj));
if (rc != 0)
- GOTO(stop_trans, rc);
+ GOTO(out_unlock, rc);
+
ma->ma_attr = *so_attr;
ma->ma_valid |= MA_INODE;
rc = mdd_finish_unlink(env, mdd_sobj, ma, mdd_pobj, lname, handle);
if (rc != 0)
- GOTO(stop_trans, rc);
+ GOTO(out_unlock, rc);
rc = mdd_attr_set_internal(env, mdd_pobj, p_la, handle, 0);
if (rc != 0)
- GOTO(stop_trans, rc);
+ GOTO(out_unlock, rc);
+out_unlock:
mdd_write_unlock(env, mdd_sobj);
stop_trans:
struct mdd_device *mdd = mdo2mdd(&sobj->mod_obj);
sattr->la_flags &= ~LUSTRE_IMMUTABLE_FL;
- sobj->mod_flags &= ~IMMUTE_OBJ;
CDEBUG(D_HA, "%s: "DFID" override IMMUTE FLAG\n",
mdd2obd_dev(mdd)->obd_name,
PFID(mdd_object_fid(sobj)));