* 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.
*/
/*
struct mdd_object *mdd_obj,
const struct lu_fid *pfid,
const struct lu_name *lname,
- struct thandle *handle);
+ struct thandle *handle, int first);
static int mdd_links_rename(const struct lu_env *env,
struct mdd_object *mdd_obj,
const struct lu_fid *oldpfid,
iops = &obj->do_index_ops->dio_it;
it = iops->init(env, obj, BYPASS_CAPA);
- if (it != NULL) {
+ if (!IS_ERR(it)) {
result = iops->get(env, it, (const void *)"");
if (result > 0) {
int i;
iops->put(env, it);
iops->fini(env, it);
} else
- result = -ENOMEM;
+ result = PTR_ERR(it);
RETURN(result);
}
static int mdd_changelog_ns_store(const struct lu_env *env,
struct mdd_device *mdd,
enum changelog_rec_type type,
+ int flags,
struct mdd_object *target,
struct mdd_object *parent,
const struct lu_fid *tf,
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(parent != NULL);
LASSERT(tname != NULL);
RETURN(-ENOMEM);
rec = (struct llog_changelog_rec *)buf->lb_buf;
- rec->cr.cr_flags = CLF_VERSION;
+ rec->cr.cr_flags = CLF_VERSION | (CLF_FLAGMASK & flags);
rec->cr.cr_type = (__u32)type;
tfid = tf ? tf : mdo2fid(target);
rec->cr.cr_tfid = *tfid;
la->la_valid = LA_CTIME;
rc = mdd_attr_check_set_internal(env, mdd_sobj, la, handle, 0);
- if (rc == 0)
- mdd_links_add(env, mdd_sobj, mdo2fid(mdd_tobj), lname, handle);
+ if (rc == 0) {
+ mdd_links_add(env, mdd_sobj,
+ mdo2fid(mdd_tobj), lname, handle, 0);
+ }
EXIT;
out_unlock:
mdd_pdo_write_unlock(env, mdd_tobj, dlh);
out_trans:
if (rc == 0)
- rc = mdd_changelog_ns_store(env, mdd, CL_HARDLINK, mdd_sobj,
+ rc = mdd_changelog_ns_store(env, mdd, CL_HARDLINK, 0, mdd_sobj,
mdd_tobj, NULL, lname, handle);
mdd_trans_stop(env, mdd, rc, handle);
out_pending:
LASSERT(mdd_write_locked(env, obj) != 0);
- rc = mdd_iattr_get(env, obj, ma);
+ /* read HSM flags, needed to set changelogs flags */
+ ma->ma_need = MA_HSM | MA_INODE;
+ rc = mdd_attr_get_internal(env, obj, ma);
if (rc == 0 && ma->ma_attr.la_nlink == 0) {
obj->mod_flags |= DEAD_OBJ;
/* add new orphan and the object
if (rc)
GOTO(cleanup, rc);
- la->la_valid = LA_CTIME;
- rc = mdd_attr_check_set_internal(env, mdd_cobj, la, handle, 0);
- if (rc)
- GOTO(cleanup, rc);
+ if (ma->ma_attr.la_nlink > 0 || mdd_cobj->mod_count > 0) {
+ /* update ctime of an unlinked file only if it is still
+ * opened or a link still exists */
+ la->la_valid = LA_CTIME;
+ rc = mdd_attr_check_set_internal(env, mdd_cobj, la, handle, 0);
+ if (rc)
+ GOTO(cleanup, rc);
+ }
rc = mdd_finish_unlink(env, mdd_cobj, ma, handle);
#ifdef HAVE_QUOTA_SUPPORT
mdd_write_unlock(env, mdd_cobj);
mdd_pdo_write_unlock(env, mdd_pobj, dlh);
out_trans:
- if (rc == 0)
+ if (rc == 0) {
+ int cl_flags;
+
+ cl_flags = (ma->ma_attr.la_nlink == 0) ? CLF_UNLINK_LAST : 0;
+ if ((ma->ma_valid & MA_HSM) &&
+ (ma->ma_hsm.mh_flags & HS_EXISTS))
+ cl_flags |= CLF_UNLINK_HSM_EXISTS;
+
rc = mdd_changelog_ns_store(env, mdd,
- is_dir ? CL_RMDIR : CL_UNLINK,
- mdd_cobj, mdd_pobj, NULL, lname,
- handle);
+ is_dir ? CL_RMDIR : CL_UNLINK, cl_flags,
+ mdd_cobj, mdd_pobj, NULL, lname, handle);
+ }
mdd_trans_stop(env, mdd, rc, handle);
#ifdef HAVE_QUOTA_SUPPORT
if (rc == 0)
/* Bare EXT record with no RENAME in front of it signifies
a partial slave op */
- rc = mdd_changelog_ns_store(env, mdd, CL_EXT, mdd_tobj,
+ rc = mdd_changelog_ns_store(env, mdd, CL_EXT, 0, mdd_tobj,
mdd_tpobj, NULL, lname, handle);
mdd_trans_stop(env, mdd, rc, handle);
__mdd_ref_del(env, child, handle, 1);
}
if (rc == 0)
- mdd_links_add(env, child, pfid, lname, handle);
+ mdd_links_add(env, child, pfid, lname, handle, 1);
RETURN(rc);
}
S_ISDIR(attr->la_mode) ? CL_MKDIR :
S_ISREG(attr->la_mode) ? CL_CREATE :
S_ISLNK(attr->la_mode) ? CL_SOFTLINK : CL_MKNOD,
- son, mdd_pobj, NULL, lname, handle);
+ 0, son, mdd_pobj, NULL, lname, handle);
mdd_trans_stop(env, mdd, rc, handle);
out_free:
- /* finis lov_create stuff, free all temporary data */
+ /* finish lov_create stuff, free all temporary data */
mdd_lov_create_finish(env, mdd, lmm, lmm_size, spec);
out_pending:
#ifdef HAVE_QUOTA_SUPPORT
if (rc == -ENOENT)
/* Old files might not have EA entry */
mdd_links_add(env, mdd_sobj, mdo2fid(mdd_spobj),
- lsname, handle);
+ lsname, handle, 0);
mdd_write_unlock(env, mdd_sobj);
/* We don't fail the transaction if the link ea can't be
updated -- fid2path will use alternate lookup method. */
mdd_pdo_write_unlock(env, mdd_spobj, sdlh);
cleanup_unlocked:
if (rc == 0)
- rc = mdd_changelog_ns_store(env, mdd, CL_RENAME, mdd_tobj,
+ rc = mdd_changelog_ns_store(env, mdd, CL_RENAME, 0, mdd_tobj,
mdd_spobj, lf, lsname, handle);
if (rc == 0)
- rc = mdd_changelog_ns_store(env, mdd, CL_EXT, mdd_tobj,
+ rc = mdd_changelog_ns_store(env, mdd, CL_EXT, 0, mdd_tobj,
mdd_tpobj, lf, ltname, handle);
mdd_trans_stop(env, mdd, rc, handle);
struct mdd_object *mdd_obj,
const struct lu_fid *pfid,
const struct lu_name *lname,
- struct thandle *handle)
+ struct thandle *handle, int first)
{
struct lu_buf *buf;
struct link_ea_header *leh;
if (!mdd_linkea_enable)
RETURN(0);
- buf = mdd_links_get(env, mdd_obj);
+ buf = first ? ERR_PTR(-ENODATA) : mdd_links_get(env, mdd_obj);
if (IS_ERR(buf)) {
rc = PTR_ERR(buf);
if (rc != -ENODATA) {
.mdo_name_insert = mdd_name_insert,
.mdo_name_remove = mdd_name_remove,
.mdo_rename_tgt = mdd_rename_tgt,
- .mdo_create_data = mdd_create_data
+ .mdo_create_data = mdd_create_data,
};