* Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
* Use is subject to license terms.
*
- * Copyright (c) 2011, 2012, Whamcloud, Inc.
+ * Copyright (c) 2011, 2012, Intel Corporation.
*/
/*
* This file is part of Lustre, http://www.lustre.org/
#define DEBUG_SUBSYSTEM S_MDS
#include "mdt_internal.h"
-#include "lu_time.h"
static inline void mdt_reint_init_ma(struct mdt_thread_info *info,
struct md_attr *ma)
return rc;
}
+/**
+ * Check HSM flags and add HS_DIRTY flag if relevant.
+ *
+ * A file could be set dirty only if it has a copy in the backend (HS_EXISTS)
+ * and is not RELEASED.
+ */
+int mdt_add_dirty_flag(struct mdt_thread_info *info, struct mdt_object *mo,
+ struct md_attr *ma)
+{
+ int rc;
+ ENTRY;
+
+ /* If the file was modified, add the dirty flag */
+ ma->ma_need = MA_HSM;
+ rc = mdt_attr_get_complex(info, mo, ma);
+ if (rc) {
+ CERROR("file attribute read error for "DFID": %d.\n",
+ PFID(lu_object_fid(&mo->mot_obj.mo_lu)), rc);
+ RETURN(rc);
+ }
+
+ /* If an up2date copy exists in the backend, add dirty flag */
+ if ((ma->ma_valid & MA_HSM) && (ma->ma_hsm.mh_flags & HS_EXISTS)
+ && !(ma->ma_hsm.mh_flags & (HS_DIRTY|HS_RELEASED))) {
+
+ ma->ma_hsm.mh_flags |= HS_DIRTY;
+ rc = mdt_hsm_attr_set(info, mo, &ma->ma_hsm);
+ if (rc) {
+ CERROR("file attribute change error for "DFID": %d\n",
+ PFID(lu_object_fid(&mo->mot_obj.mo_lu)), rc);
+ RETURN(rc);
+ }
+ }
+
+ RETURN(rc);
+}
+
static int mdt_reint_setattr(struct mdt_thread_info *info,
struct mdt_lock_handle *lhc)
{
} else
LBUG();
+ /* If file data is modified, add the dirty flag */
+ if (ma->ma_attr_flags & MDS_DATA_MODIFIED)
+ rc = mdt_add_dirty_flag(info, mo, ma);
+
ma->ma_need = MA_INODE;
ma->ma_valid = 0;
rc = mdt_attr_get_complex(info, mo, ma);
static int mdt_rename_lock(struct mdt_thread_info *info,
struct lustre_handle *lh)
{
- struct ldlm_namespace *ns = info->mti_mdt->mdt_namespace;
- ldlm_policy_data_t *policy = &info->mti_policy;
- struct ldlm_res_id *res_id = &info->mti_res_id;
- __u64 flags = 0;
- struct md_site *ms;
- int rc;
- ENTRY;
-
- ms = mdt_md_site(info->mti_mdt);
- fid_build_reg_res_name(&LUSTRE_BFL_FID, res_id);
-
- memset(policy, 0, sizeof *policy);
- policy->l_inodebits.bits = MDS_INODELOCK_UPDATE;
-
- if (ms->ms_control_exp == NULL) {
- flags = LDLM_FL_LOCAL_ONLY | LDLM_FL_ATOMIC_CB;
-
- /*
- * Current node is controller, that is mdt0, where we should
- * take BFL lock.
- */
- rc = ldlm_cli_enqueue_local(ns, res_id, LDLM_IBITS, policy,
- LCK_EX, &flags, ldlm_blocking_ast,
- ldlm_completion_ast, NULL, NULL, 0,
- LVB_T_NONE,
- &info->mti_exp->exp_handle.h_cookie,
- lh);
- } else {
- struct ldlm_enqueue_info einfo = { LDLM_IBITS, LCK_EX,
- ldlm_blocking_ast, ldlm_completion_ast, NULL, NULL, NULL };
- /*
- * This is the case mdt0 is remote node, issue DLM lock like
- * other clients.
- */
- rc = ldlm_cli_enqueue(ms->ms_control_exp, NULL, &einfo, res_id,
- policy, &flags, NULL, 0, LVB_T_NONE, lh,
- 0);
- }
-
+ struct ldlm_namespace *ns = info->mti_mdt->mdt_namespace;
+ ldlm_policy_data_t *policy = &info->mti_policy;
+ struct ldlm_res_id *res_id = &info->mti_res_id;
+ __u64 flags = 0;
+ int rc;
+ ENTRY;
+
+ fid_build_reg_res_name(&LUSTRE_BFL_FID, res_id);
+
+ memset(policy, 0, sizeof *policy);
+ policy->l_inodebits.bits = MDS_INODELOCK_UPDATE;
+#if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 4, 53, 0)
+ /* In phase I, we will not do cross-rename, so local BFL lock would
+ * be enough
+ */
+ flags = LDLM_FL_LOCAL_ONLY | LDLM_FL_ATOMIC_CB;
+ /*
+ * Current node is controller, that is mdt0, where we should
+ * take BFL lock.
+ */
+ rc = ldlm_cli_enqueue_local(ns, res_id, LDLM_IBITS, policy,
+ LCK_EX, &flags, ldlm_blocking_ast,
+ ldlm_completion_ast, NULL, NULL, 0,
+ LVB_T_NONE,
+ &info->mti_exp->exp_handle.h_cookie,
+ lh);
+#else
+#warning "Local rename lock is invalid for DNE phase II."
+#endif
RETURN(rc);
}
PFID(rr->rr_fid1), rr->rr_name,
PFID(rr->rr_fid2), rr->rr_tgt);
- rc = mdt_rename_lock(info, &rename_lh);
- if (rc) {
- CERROR("Can't lock FS for rename, rc %d\n", rc);
- RETURN(rc);
- }
+ rc = mdt_rename_lock(info, &rename_lh);
+ if (rc) {
+ CERROR("Can't lock FS for rename, rc %d\n", rc);
+ RETURN(rc);
+ }
lh_newp = &info->mti_lh[MDT_LH_NEW];
out_unlock_source:
mdt_object_unlock_put(info, msrcdir, lh_srcdirp, rc);
out_rename_lock:
- mdt_rename_unlock(&rename_lh);
- return rc;
+ if (lustre_handle_is_used(&rename_lh))
+ mdt_rename_unlock(&rename_lh);
+ return rc;
}
typedef int (*mdt_reinter)(struct mdt_thread_info *info,