RETURN(result);
}
+/**
+ * Determine if the target object can be hard linked, and right now it only
+ * checks if the link count reach the maximum limit. Note: for ldiskfs, the
+ * directory nlink count might exceed the maximum link count(see
+ * osd_object_ref_add), so it only check nlink for non-directories.
+ *
+ * \param[in] env thread environment
+ * \param[in] obj object being linked to
+ * \param[in] la attributes of \a obj
+ *
+ * \retval 0 if \a obj can be hard linked
+ * \retval negative error if \a obj is a directory or has too
+ * many links
+ */
static int __mdd_may_link(const struct lu_env *env, struct mdd_object *obj,
const struct lu_attr *la)
{
LASSERT(la != NULL);
- if (!S_ISDIR(la->la_mode))
- RETURN(0);
-
- /*
- * Subdir count limitation can be broken through.
- */
- if (la->la_nlink >= m->mdd_dt_conf.ddp_max_nlink)
+ /* Subdir count limitation can be broken through
+ * (see osd_object_ref_add), so only check non-directory here. */
+ if (!S_ISDIR(la->la_mode) &&
+ la->la_nlink >= m->mdd_dt_conf.ddp_max_nlink)
RETURN(-EMLINK);
- else
- RETURN(0);
+
+ RETURN(0);
}
-/*
+/**
* Check whether it may create the cobj under the pobj.
- * cobj maybe NULL
+ *
+ * \param[in] env execution environment
+ * \param[in] pobj the parent directory
+ * \param[in] pattr the attribute of the parent directory
+ * \param[in] cobj the child to be created
+ * \param[in] check_perm if check WRITE|EXEC permission for parent
+ *
+ * \retval = 0 create the child under this dir is allowed
+ * \retval negative errno create the child under this dir is
+ * not allowed
*/
-int mdd_may_create(const struct lu_env *env,
- struct mdd_object *pobj, const struct lu_attr *pattr,
- struct mdd_object *cobj, bool check_perm, bool check_nlink)
+int mdd_may_create(const struct lu_env *env, struct mdd_object *pobj,
+ const struct lu_attr *pattr, struct mdd_object *cobj,
+ bool check_perm)
{
struct mdd_thread_info *info = mdd_env_info(env);
struct lu_buf *xbuf;
rc = mdd_permission_internal_locked(env, pobj, pattr,
MAY_WRITE | MAY_EXEC,
MOR_TGT_PARENT);
- if (!rc && check_nlink)
- rc = __mdd_may_link(env, pobj, pattr);
-
RETURN(rc);
}
RETURN(rc);
}
-/*
- * tgt maybe NULL
- * has mdd_write_lock on src already, but not on tgt yet
+/**
+ * Check whether it can create the link file(linked to @src_obj) under
+ * the target directory(@tgt_obj), and src_obj has been locked by
+ * mdd_write_lock.
+ *
+ * \param[in] env execution environment
+ * \param[in] tgt_obj the target directory
+ * \param[in] tattr attributes of target directory
+ * \param[in] lname the link name
+ * \param[in] src_obj source object for link
+ * \param[in] cattr attributes for source object
+ *
+ * \retval = 0 it is allowed to create the link file under tgt_obj
+ * \retval negative error not allowed to create the link file
*/
static int mdd_link_sanity_check(const struct lu_env *env,
struct mdd_object *tgt_obj,
RETURN(-EPERM);
LASSERT(src_obj != tgt_obj);
- if (tgt_obj) {
- rc = mdd_may_create(env, tgt_obj, tattr, NULL, true, false);
- if (rc)
- RETURN(rc);
- }
+ rc = mdd_may_create(env, tgt_obj, tattr, NULL, true);
+ if (rc != 0)
+ RETURN(rc);
rc = __mdd_may_link(env, src_obj, cattr);
static int __mdd_index_insert_only(const struct lu_env *env,
struct mdd_object *pobj,
- const struct lu_fid *lf, const char *name,
+ const struct lu_fid *lf, __u32 type,
+ const char *name,
struct thandle *handle,
struct lustre_capa *capa)
{
ENTRY;
if (dt_try_as_dir(env, next)) {
- struct lu_ucred *uc = lu_ucred_check(env);
- int ignore_quota;
+ struct dt_insert_rec *rec = &mdd_env_info(env)->mti_dt_rec;
+ struct lu_ucred *uc = lu_ucred_check(env);
+ int ignore_quota;
+ 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,
- (struct dt_rec*)lf,
+ (const struct dt_rec *)rec,
(const struct dt_key *)name,
handle, capa, ignore_quota);
} else {
/* insert named index, add reference if isdir */
static int __mdd_index_insert(const struct lu_env *env, struct mdd_object *pobj,
- const struct lu_fid *lf, const char *name, int is_dir,
- struct thandle *handle, struct lustre_capa *capa)
+ const struct lu_fid *lf, __u32 type,
+ const char *name, struct thandle *handle,
+ struct lustre_capa *capa)
{
- int rc;
- ENTRY;
+ int rc;
+ ENTRY;
- rc = __mdd_index_insert_only(env, pobj, lf, name, handle, capa);
- if (rc == 0 && is_dir) {
- mdd_write_lock(env, pobj, MOR_TGT_PARENT);
- mdo_ref_add(env, pobj, handle);
- mdd_write_unlock(env, pobj);
- }
- RETURN(rc);
+ rc = __mdd_index_insert_only(env, pobj, lf, type, name, handle, capa);
+ if (rc == 0 && S_ISDIR(type)) {
+ mdd_write_lock(env, pobj, MOR_TGT_PARENT);
+ mdo_ref_add(env, pobj, handle);
+ mdd_write_unlock(env, pobj);
+ }
+
+ RETURN(rc);
}
/* delete named index, drop reference if isdir */
}
static int mdd_declare_link(const struct lu_env *env,
- struct mdd_device *mdd,
- struct mdd_object *p,
- struct mdd_object *c,
- const struct lu_name *name,
+ struct mdd_device *mdd,
+ struct mdd_object *p,
+ struct mdd_object *c,
+ const struct lu_name *name,
struct thandle *handle,
struct lu_attr *la,
struct linkea_data *data)
{
- int rc;
+ int rc;
- rc = mdo_declare_index_insert(env, p, mdo2fid(c), name->ln_name,handle);
- if (rc)
+ rc = mdo_declare_index_insert(env, p, mdo2fid(c), mdd_object_type(c),
+ name->ln_name, handle);
+ if (rc != 0)
return rc;
rc = mdo_declare_ref_add(env, c, handle);
rc = __mdd_index_insert_only(env, mdd_tobj, mdo2fid(mdd_sobj),
- name, handle,
+ mdd_object_type(mdd_sobj), name, handle,
mdd_object_capa(env, mdd_tobj));
if (rc != 0) {
mdo_ref_del(env, mdd_sobj, handle);
if (rc != 0) {
__mdd_index_insert_only(env, mdd_pobj,
mdo2fid(mdd_cobj),
+ mdd_object_type(mdd_cobj),
name, handle,
mdd_object_capa(env, mdd_pobj));
GOTO(cleanup, rc);
struct lu_attr *attr,
struct thandle *handle)
{
- int rc;
+ int rc;
ENTRY;
/*
attr->la_valid &= ~(LA_MODE | LA_TYPE);
rc = mdo_declare_attr_set(env, child, attr, handle);
attr->la_valid |= LA_MODE | LA_TYPE;
- if (rc == 0 && S_ISDIR(attr->la_mode)) {
- rc = mdo_declare_index_insert(env, child, mdo2fid(child),
- dot, handle);
- if (rc == 0)
- rc = mdo_declare_ref_add(env, child, handle);
-
- rc = mdo_declare_index_insert(env, child, mdo2fid(parent),
- dotdot, handle);
- }
+ if (rc != 0 || !S_ISDIR(attr->la_mode))
+ RETURN(rc);
+
+ rc = mdo_declare_index_insert(env, child, mdo2fid(child), S_IFDIR,
+ dot, handle);
+ if (rc != 0)
+ RETURN(rc);
+
+ rc = mdo_declare_ref_add(env, child, handle);
+ if (rc != 0)
+ RETURN(rc);
+
+ rc = mdo_declare_index_insert(env, child, mdo2fid(parent), S_IFDIR,
+ dotdot, handle);
RETURN(rc);
}
/* Add "." and ".." for newly created dir */
mdo_ref_add(env, child, handle);
rc = __mdd_index_insert_only(env, child, mdo2fid(child),
- dot, handle, BYPASS_CAPA);
- if (rc == 0)
- rc = __mdd_index_insert_only(env, child, pfid,
- dotdot, handle,
- BYPASS_CAPA);
- if (rc != 0)
- mdo_ref_del(env, child, handle);
- }
+ S_IFDIR, dot, handle, BYPASS_CAPA);
+ if (rc == 0)
+ rc = __mdd_index_insert_only(env, child, pfid, S_IFDIR,
+ dotdot, handle,
+ BYPASS_CAPA);
+ if (rc != 0)
+ mdo_ref_del(env, child, handle);
+ }
RETURN(rc);
}
-/* has not lock on pobj yet */
+/**
+ * This function checks whether it can create a file/dir under the
+ * directory(@pobj). The directory(@pobj) is not being locked by
+ * mdd lock.
+ *
+ * \param[in] env execution environment
+ * \param[in] pobj the directory to create files
+ * \param[in] pattr the attributes of the directory
+ * \param[in] lname the name of the created file/dir
+ * \param[in] cattr the attributes of the file/dir
+ * \param[in] spec create specification
+ *
+ * \retval = 0 it is allowed to create file/dir under
+ * the directory
+ * \retval negative error not allowed to create file/dir
+ * under the directory
+ */
static int mdd_create_sanity_check(const struct lu_env *env,
struct md_object *pobj,
const struct lu_attr *pattr,
struct lu_fid *fid = &info->mti_fid;
struct mdd_object *obj = md2mdd_obj(pobj);
struct mdd_device *m = mdo2mdd(pobj);
+ bool check_perm = true;
int rc;
ENTRY;
MAY_WRITE | MAY_EXEC);
if (rc != -ENOENT)
RETURN(rc ? : -EEXIST);
- } else {
- rc = mdd_may_create(env, obj, pattr, NULL, true, false);
- if (rc != 0)
- RETURN(rc);
+
+ /* Permission is already being checked in mdd_lookup */
+ check_perm = false;
}
+ rc = mdd_may_create(env, obj, pattr, NULL, check_perm);
+ if (rc != 0)
+ RETURN(rc);
+
/* sgid check */
if (pattr->la_mode & S_ISGID) {
cattr->la_gid = pattr->la_gid;
} else {
struct lu_attr *la = &mdd_env_info(env)->mti_la_for_fix;
- rc = mdo_declare_index_insert(env, p, mdo2fid(c), name->ln_name,
- handle);
- if (rc)
+ rc = mdo_declare_index_insert(env, p, mdo2fid(c), attr->la_mode,
+ name->ln_name, handle);
+ if (rc != 0)
return rc;
+
rc = mdd_declare_links_add(env, c, handle, ldata);
if (rc)
return rc;
GOTO(out_volatile, rc);
} else {
rc = __mdd_index_insert(env, mdd_pobj, mdo2fid(son),
- name, S_ISDIR(attr->la_mode), handle,
+ attr->la_mode, name, handle,
mdd_object_capa(env, mdd_pobj));
if (rc != 0)
GOTO(err_created, rc);
* processed in cld_rename before mdd_rename and enable
* MDS_PERM_BYPASS).
* So check may_create, but not check may_unlink. */
- if (!tobj)
+ if (tobj == NULL)
rc = mdd_may_create(env, tgt_pobj, tpattr, NULL,
- (src_pobj != tgt_pobj), false);
+ (src_pobj != tgt_pobj));
else
rc = mdd_may_delete(env, tgt_pobj, tpattr, tobj, tattr, cattr,
(src_pobj != tgt_pobj), 1);
if (mdd_spobj != mdd_tpobj) {
rc = mdo_declare_index_delete(env, mdd_sobj, dotdot,
handle);
- if (rc)
+ if (rc != 0)
return rc;
rc = mdo_declare_index_insert(env, mdd_sobj,
mdo2fid(mdd_tpobj),
- dotdot, handle);
- if (rc)
+ S_IFDIR, dotdot, handle);
+ if (rc != 0)
return rc;
}
- /* new target child can be directory,
- * counted by target dir's nlink */
- rc = mdo_declare_ref_add(env, mdd_tpobj, handle);
- if (rc)
- return rc;
- }
+
+ /* new target child can be directory,
+ * counted by target dir's nlink */
+ rc = mdo_declare_ref_add(env, mdd_tpobj, handle);
+ if (rc != 0)
+ return rc;
+ }
la->la_valid = LA_CTIME | LA_MTIME;
rc = mdo_declare_attr_set(env, mdd_spobj, la, handle);
if (rc)
return rc;
- /* new name */
- rc = mdo_declare_index_insert(env, mdd_tpobj, mdo2fid(mdd_sobj),
- tname->ln_name, handle);
- if (rc)
- return rc;
+ /* new name */
+ rc = mdo_declare_index_insert(env, mdd_tpobj, mdo2fid(mdd_sobj),
+ mdd_object_type(mdd_sobj),
+ tname->ln_name, handle);
+ if (rc != 0)
+ return rc;
/* name from target dir (old name), we declare it unconditionally
* as mdd_rename() calls delete unconditionally as well. so just
if (is_dir && mdd_sobj && !lu_fid_eq(spobj_fid, tpobj_fid)) {
rc = __mdd_index_delete_only(env, mdd_sobj, dotdot, handle,
mdd_object_capa(env, mdd_sobj));
- if (rc)
- GOTO(fixup_spobj2, rc);
+ if (rc != 0)
+ GOTO(fixup_spobj2, rc);
- rc = __mdd_index_insert_only(env, mdd_sobj, tpobj_fid, dotdot,
- handle, mdd_object_capa(env, mdd_sobj));
- if (rc)
+ rc = __mdd_index_insert_only(env, mdd_sobj, tpobj_fid, S_IFDIR,
+ dotdot, handle,
+ mdd_object_capa(env, mdd_sobj));
+ if (rc != 0)
GOTO(fixup_spobj, rc);
}
}
/* Insert new fid with target name into target dir */
- rc = __mdd_index_insert(env, mdd_tpobj, lf, tname, is_dir, handle,
- mdd_object_capa(env, mdd_tpobj));
- if (rc)
+ rc = __mdd_index_insert(env, mdd_tpobj, lf, cattr->la_mode,
+ tname, handle, mdd_object_capa(env, mdd_tpobj));
+ if (rc != 0)
GOTO(fixup_tpobj, rc);
LASSERT(ma->ma_attr.la_valid & LA_CTIME);
mdo_ref_add(env, mdd_tobj, handle);
}
- rc2 = __mdd_index_insert(env, mdd_tpobj,
- mdo2fid(mdd_tobj), tname,
- is_dir, handle,
- BYPASS_CAPA);
-
- if (rc2)
- CWARN("tp obj fix error %d\n",rc2);
- }
- }
+ rc2 = __mdd_index_insert(env, mdd_tpobj,
+ mdo2fid(mdd_tobj),
+ mdd_object_type(mdd_tobj),
+ tname, handle, BYPASS_CAPA);
+ if (rc2 != 0)
+ CWARN("tp obj fix error: rc = %d\n", rc2);
+ }
+ }
fixup_spobj:
if (rc && is_dir && mdd_sobj && mdd_spobj != mdd_tpobj) {
mdd2obd_dev(mdd)->obd_name, rc2);
- rc2 = __mdd_index_insert_only(env, mdd_sobj, spobj_fid,
+ rc2 = __mdd_index_insert_only(env, mdd_sobj, spobj_fid, S_IFDIR,
dotdot, handle, BYPASS_CAPA);
- if (rc2)
+ if (rc2 != 0)
CWARN("%s: sp obj dotdot insert error: rc = %d\n",
mdd2obd_dev(mdd)->obd_name, rc2);
}
fixup_spobj2:
- if (rc) {
- rc2 = __mdd_index_insert(env, mdd_spobj,
- lf, sname, is_dir, handle, BYPASS_CAPA);
- if (rc2)
- CWARN("sp obj fix error %d\n",rc2);
- }
+ if (rc != 0) {
+ rc2 = __mdd_index_insert(env, mdd_spobj, lf,
+ mdd_object_type(mdd_sobj), sname,
+ handle, BYPASS_CAPA);
+ if (rc2 != 0)
+ CWARN("sp obj fix error: rc = %d\n", rc2);
+ }
+
cleanup:
if (tobj_locked)
mdd_write_unlock(env, mdd_tobj);
+
cleanup_unlocked:
- if (rc == 0)
+ 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);
stop:
- mdd_trans_stop(env, mdd, rc, handle);
+ mdd_trans_stop(env, mdd, rc, handle);
+
out_pending:
mdd_object_put(env, mdd_sobj);
return rc;
/* Insert new fid with target name into target dir */
rc = mdo_declare_index_delete(env, pobj, lname.ln_name,
handle);
- if (rc)
+ if (rc != 0)
GOTO(next_put, rc);
rc = mdo_declare_index_insert(env, pobj,
- mdd_object_fid(mdd_tobj),
- lname.ln_name, handle);
- if (rc)
+ mdd_object_fid(mdd_tobj),
+ mdd_object_type(mdd_tobj),
+ lname.ln_name, handle);
+ if (rc != 0)
GOTO(next_put, rc);
rc = mdo_declare_ref_add(env, mdd_tobj, handle);
GOTO(next_put, rc);
rc = __mdd_index_insert(env, pobj,
- mdd_object_fid(mdd_tobj),
- lname.ln_name, 0, handle,
- mdd_object_capa(env, pobj));
- if (rc)
+ mdd_object_fid(mdd_tobj),
+ mdd_object_type(mdd_tobj),
+ lname.ln_name, handle,
+ mdd_object_capa(env, pobj));
+ if (rc != 0)
GOTO(next_put, rc);
mdd_write_lock(env, mdd_tobj, MOR_SRC_CHILD);
}
mgr_ea = (struct lmv_mds_md_v1 *)info->mti_xattr_buf;
+ memset(mgr_ea, 0, sizeof(*mgr_ea));
mgr_ea->lmv_magic = cpu_to_le32(LMV_MAGIC_V1);
mgr_ea->lmv_stripe_count = cpu_to_le32(2);
mgr_ea->lmv_master_mdt_index = mdd_seq_site(mdd)->ss_node_id;
mgr_ea->lmv_hash_type = cpu_to_le32(LMV_HASH_FLAG_MIGRATION);
- fid_cpu_to_le(&mgr_ea->lmv_master_fid, mdd_object_fid(mdd_sobj));
fid_cpu_to_le(&mgr_ea->lmv_stripe_fids[0], mdd_object_fid(mdd_sobj));
fid_cpu_to_le(&mgr_ea->lmv_stripe_fids[1], mdd_object_fid(mdd_tobj));
if (IS_ERR(child))
GOTO(out, rc = PTR_ERR(child));
- is_dir = S_ISDIR(lu_object_attr(&child->mod_obj.mo_lu));
+ is_dir = S_ISDIR(mdd_object_type(child));
snprintf(name, ent->lde_namelen + 1, "%s", ent->lde_name);
if (likely(!target_exist)) {
rc = mdo_declare_index_insert(env, mdd_tobj,
&ent->lde_fid,
+ mdd_object_type(child),
name, handle);
if (rc != 0)
GOTO(out_put, rc);
rc = mdo_declare_index_insert(env, child,
mdd_object_fid(mdd_tobj),
- dotdot, handle);
+ S_IFDIR, dotdot, handle);
if (rc != 0)
GOTO(out_put, rc);
}
if (likely(!target_exist)) {
rc = __mdd_index_insert(env, mdd_tobj, &ent->lde_fid,
- name, is_dir, handle,
+ mdd_object_type(child),
+ name, handle,
mdd_object_capa(env, mdd_tobj));
if (rc != 0)
GOTO(out_put, rc);
GOTO(out_put, rc);
rc = __mdd_index_insert_only(env, child,
- mdd_object_fid(mdd_tobj),
+ mdd_object_fid(mdd_tobj), S_IFDIR,
dotdot, handle,
mdd_object_capa(env, child));
if (rc != 0)
/* new name */
rc = mdo_declare_index_insert(env, mdd_pobj, mdo2fid(mdd_tobj),
+ mdd_object_type(mdd_tobj),
lname->ln_name, handle);
if (rc != 0)
return rc;
}
/* Insert new fid with target name into target dir */
- rc = __mdd_index_insert(env, mdd_pobj, mdd_object_fid(mdd_tobj), name,
- is_dir, handle, mdd_object_capa(env, mdd_pobj));
+ rc = __mdd_index_insert(env, mdd_pobj, mdd_object_fid(mdd_tobj),
+ mdd_object_type(mdd_tobj), name,
+ handle, mdd_object_capa(env, mdd_pobj));
if (rc != 0)
GOTO(stop_trans, rc);