/* md_dir operations */
static int cml_lookup(const struct lu_env *env, struct md_object *mo_p,
- const char *name, struct lu_fid *lf,
+ const struct lu_name *lname, struct lu_fid *lf,
struct md_op_spec *spec)
{
+ char *name = lname->ln_name;
struct cmm_device *cmm = cmm_obj2dev(md2cmm_obj(mo_p));
struct timeval start;
int rc;
}
}
#endif
- rc = mdo_lookup(env, md_object_next(mo_p), name, lf, spec);
+ rc = mdo_lookup(env, md_object_next(mo_p), lname, lf, spec);
cmm_lprocfs_time_end(cmm, &start, LPROC_CMM_LOOKUP);
RETURN(rc);
}
static int cml_create(const struct lu_env *env, struct md_object *mo_p,
- const char *name, struct md_object *mo_c,
+ const struct lu_name *lname, struct md_object *mo_c,
struct md_op_spec *spec, struct md_attr *ma)
{
+ char *name = lname->ln_name;
struct cmm_device *cmm = cmm_obj2dev(md2cmm_obj(mo_p));
struct timeval start;
int rc;
}
#endif
- rc = mdo_create(env, md_object_next(mo_p), name, md_object_next(mo_c),
+ rc = mdo_create(env, md_object_next(mo_p), lname, md_object_next(mo_c),
spec, ma);
EXIT;
}
static int cml_link(const struct lu_env *env, struct md_object *mo_p,
- struct md_object *mo_s, const char *name,
+ struct md_object *mo_s, const struct lu_name *lname,
struct md_attr *ma)
{
int rc;
ENTRY;
rc = mdo_link(env, md_object_next(mo_p), md_object_next(mo_s),
- name, ma);
+ lname, ma);
RETURN(rc);
}
/* remote part of md_dir operations */
static int cmr_lookup(const struct lu_env *env, struct md_object *mo_p,
- const char *name, struct lu_fid *lf,
+ const struct lu_name *lname, struct lu_fid *lf,
struct md_op_spec *spec)
{
/*
* For more details see rollback HLD/DLD.
*/
static int cmr_create(const struct lu_env *env, struct md_object *mo_p,
- const char *child_name, struct md_object *mo_c,
+ const struct lu_name *lchild_name, struct md_object *mo_c,
struct md_op_spec *spec,
struct md_attr *ma)
{
+ char *child_name = lchild_name->ln_name;
struct cmm_thread_info *cmi;
struct md_attr *tmp_ma;
int rc;
ENTRY;
/* Make sure that name isn't exist before doing remote call. */
- rc = mdo_lookup(env, md_object_next(mo_p), child_name,
+ rc = mdo_lookup(env, md_object_next(mo_p), lchild_name,
&cmm_env_info(env)->cmi_fid, NULL);
if (rc == 0)
RETURN(-EEXIST);
}
static int cmr_link(const struct lu_env *env, struct md_object *mo_p,
- struct md_object *mo_s, const char *name,
+ struct md_object *mo_s, const struct lu_name *lname,
struct md_attr *ma)
{
+ char *name = lname->ln_name;
int rc;
ENTRY;
/* Make sure that name isn't exist before doing remote call. */
- rc = mdo_lookup(env, md_object_next(mo_p), name,
+ rc = mdo_lookup(env, md_object_next(mo_p), lname,
&cmm_env_info(env)->cmi_fid, NULL);
if (rc == 0) {
rc = -EEXIST;
void lu_env_fini(struct lu_env *env);
/*
+ * Common name structure to be passed around for various name related methods.
+ */
+struct lu_name {
+ char *ln_name;
+ int ln_namelen;
+};
+
+/*
* Common buffer structure to be passed around for various xattr_{s,g}et()
* methods.
*/
const struct lu_fid *fid, struct lu_fid *sfid);
int (*mdo_lookup)(const struct lu_env *env, struct md_object *obj,
- const char *name, struct lu_fid *fid,
+ const struct lu_name *lname, struct lu_fid *fid,
struct md_op_spec *spec);
mdl_mode_t (*mdo_lock_mode)(const struct lu_env *env, struct md_object *obj,
mdl_mode_t mode);
int (*mdo_create)(const struct lu_env *env, struct md_object *pobj,
- const char *name, struct md_object *child,
+ const struct lu_name *lname, struct md_object *child,
struct md_op_spec *spec,
struct md_attr *ma);
const char *tname, struct md_attr *ma);
int (*mdo_link)(const struct lu_env *env, struct md_object *tgt_obj,
- struct md_object *src_obj, const char *name,
+ struct md_object *src_obj, const struct lu_name *lname,
struct md_attr *ma);
int (*mdo_unlink)(const struct lu_env *env, struct md_object *pobj,
static inline int mdo_lookup(const struct lu_env *env,
struct md_object *p,
- const char *name,
+ const struct lu_name *lname,
struct lu_fid *f,
struct md_op_spec *spec)
{
LASSERT(p->mo_dir_ops->mdo_lookup);
- return p->mo_dir_ops->mdo_lookup(env, p, name, f, spec);
+ return p->mo_dir_ops->mdo_lookup(env, p, lname, f, spec);
}
static inline mdl_mode_t mdo_lock_mode(const struct lu_env *env,
static inline int mdo_create(const struct lu_env *env,
struct md_object *p,
- const char *child_name,
+ const struct lu_name *lchild_name,
struct md_object *c,
struct md_op_spec *spc,
struct md_attr *at)
{
LASSERT(c->mo_dir_ops->mdo_create);
- return c->mo_dir_ops->mdo_create(env, p, child_name, c, spc, at);
+ return c->mo_dir_ops->mdo_create(env, p, lchild_name, c, spc, at);
}
static inline int mdo_create_data(const struct lu_env *env,
static inline int mdo_link(const struct lu_env *env,
struct md_object *p,
struct md_object *s,
- const char *name,
+ const struct lu_name *lname,
struct md_attr *ma)
{
LASSERT(s->mo_dir_ops->mdo_link);
- return s->mo_dir_ops->mdo_link(env, p, s, name, ma);
+ return s->mo_dir_ops->mdo_link(env, p, s, lname, ma);
}
static inline int mdo_unlink(const struct lu_env *env,
static const char dot[] = ".";
static const char dotdot[] = "..";
+static struct lu_name lname_dotdot = {
+ (char *) dotdot,
+ sizeof(dotdot) - 1
+};
+
static int __mdd_lookup(const struct lu_env *env, struct md_object *pobj,
- const char *name, struct lu_fid* fid, int mask);
+ const struct lu_name *lname, struct lu_fid* fid,
+ int mask);
static int
__mdd_lookup_locked(const struct lu_env *env, struct md_object *pobj,
- const char *name, struct lu_fid* fid, int mask)
+ const struct lu_name *lname, struct lu_fid* fid, int mask)
{
+ char *name = lname->ln_name;
struct mdd_object *mdd_obj = md2mdd_obj(pobj);
struct dynlock_handle *dlh;
int rc;
dlh = mdd_pdo_read_lock(env, mdd_obj, name);
if (dlh == NULL)
return -ENOMEM;
- rc = __mdd_lookup(env, pobj, name, fid, mask);
+ rc = __mdd_lookup(env, pobj, lname, fid, mask);
mdd_pdo_read_unlock(env, mdd_obj, dlh);
return rc;
}
static int mdd_lookup(const struct lu_env *env,
- struct md_object *pobj, const char *name,
+ struct md_object *pobj, const struct lu_name *lname,
struct lu_fid* fid, struct md_op_spec *spec)
{
int rc;
ENTRY;
- rc = __mdd_lookup_locked(env, pobj, name, fid, MAY_EXEC);
+ rc = __mdd_lookup_locked(env, pobj, lname, fid, MAY_EXEC);
RETURN(rc);
}
static int mdd_parent_fid(const struct lu_env *env, struct mdd_object *obj,
struct lu_fid *fid)
{
- return __mdd_lookup_locked(env, &obj->mod_obj, dotdot, fid, 0);
+ return __mdd_lookup_locked(env, &obj->mod_obj, &lname_dotdot, fid, 0);
}
/*
RETURN(rc);
}
-int mdd_link_sanity_check(const struct lu_env *env, struct mdd_object *tgt_obj,
+int mdd_link_sanity_check(const struct lu_env *env,
+ struct mdd_object *tgt_obj,
+ const struct lu_name *lname,
struct mdd_object *src_obj)
{
struct lu_attr *la = &mdd_env_info(env)->mti_la;
int rc = 0;
ENTRY;
+ /* Local ops, no lookup before link, check filename length here. */
+ if (lname && (lname->ln_namelen > m->mdd_dt_conf.ddp_max_name_len))
+ RETURN(-ENAMETOOLONG);
+
if (mdd_is_immutable(src_obj) || mdd_is_append(src_obj))
RETURN(-EPERM);
}
static int mdd_link(const struct lu_env *env, struct md_object *tgt_obj,
- struct md_object *src_obj, const char *name,
+ struct md_object *src_obj, const struct lu_name *lname,
struct md_attr *ma)
{
+ char *name = lname->ln_name;
struct lu_attr *la = &mdd_env_info(env)->mti_la_for_fix;
struct mdd_object *mdd_tobj = md2mdd_obj(tgt_obj);
struct mdd_object *mdd_sobj = md2mdd_obj(src_obj);
GOTO(out_trans, rc = -ENOMEM);
mdd_write_lock(env, mdd_sobj);
- rc = mdd_link_sanity_check(env, mdd_tobj, mdd_sobj);
+ rc = mdd_link_sanity_check(env, mdd_tobj, lname, mdd_sobj);
if (rc)
GOTO(out_unlock, rc);
static int
__mdd_lookup(const struct lu_env *env, struct md_object *pobj,
- const char *name, struct lu_fid* fid, int mask)
+ const struct lu_name *lname, struct lu_fid* fid, int mask)
{
+ char *name = lname->ln_name;
const struct dt_key *key = (const struct dt_key *)name;
struct mdd_object *mdd_obj = md2mdd_obj(pobj);
+ struct mdd_device *m = mdo2mdd(pobj);
struct dt_object *dir = mdd_object_child(mdd_obj);
struct dt_rec *rec = (struct dt_rec *)fid;
struct timeval start;
LBUG();
}
+ /* The common filename length check. */
+ if (lname->ln_namelen > m->mdd_dt_conf.ddp_max_name_len)
+ RETURN(-ENAMETOOLONG);
+
rc = mdd_permission_internal_locked(env, mdd_obj, NULL, mask);
if (rc)
RETURN(rc);
static int mdd_create_sanity_check(const struct lu_env *env,
struct md_object *pobj,
- const char *name,
+ const struct lu_name *lname,
struct md_attr *ma,
struct md_op_spec *spec)
{
* In some cases this lookup is not needed - we know before if name
* exists or not because MDT performs lookup for it.
*/
+ /* XXX we perform filename length check in lookup. */
+#if 1
+ /* XXX check filename length here temporary when lookup disabled. */
+ if (lname->ln_namelen > m->mdd_dt_conf.ddp_max_name_len)
+ RETURN(-ENAMETOOLONG);
+#endif
/* XXX disable that lookup temporary */
if (0 && lookup) {
/*
* _index_insert also, for avoiding rolling back if exists
* _index_insert.
*/
- rc = __mdd_lookup_locked(env, pobj, name, fid,
+ rc = __mdd_lookup_locked(env, pobj, lname, fid,
MAY_WRITE | MAY_EXEC);
if (rc != -ENOENT)
RETURN(rc ? : -EEXIST);
} else {
/*
- * Check if has WRITE permission for the parent.
+ * Check WRITE permission for the parent.
*/
rc = mdd_permission_internal_locked(env, obj, NULL, MAY_WRITE);
if (rc)
* Create object and insert it into namespace.
*/
static int mdd_create(const struct lu_env *env,
- struct md_object *pobj, const char *name,
+ struct md_object *pobj,
+ const struct lu_name *lname,
struct md_object *child,
struct md_op_spec *spec,
struct md_attr* ma)
{
+ char *name = lname->ln_name;
struct lu_attr *la = &mdd_env_info(env)->mti_la_for_fix;
struct mdd_object *mdd_pobj = md2mdd_obj(pobj);
struct mdd_object *son = md2mdd_obj(child);
*/
/* Sanity checks before big job. */
- rc = mdd_create_sanity_check(env, pobj, name, ma, spec);
+ rc = mdd_create_sanity_check(env, pobj, lname, ma, spec);
if (rc)
RETURN(rc);
struct mdd_object *child, struct md_attr *ma,
struct thandle *handle);
int mdd_link_sanity_check(const struct lu_env *env, struct mdd_object *tgt_obj,
- struct mdd_object *src_obj);
+ const struct lu_name *lname, struct mdd_object *src_obj);
void mdd_ref_add_internal(const struct lu_env *env, struct mdd_object *obj,
struct thandle *handle);
void mdd_ref_del_internal(const struct lu_env *env, struct mdd_object *obj,
RETURN(-ENOMEM);
mdd_write_lock(env, mdd_obj);
- rc = mdd_link_sanity_check(env, NULL, mdd_obj);
+ rc = mdd_link_sanity_check(env, NULL, NULL, mdd_obj);
if (rc == 0)
mdd_ref_add_internal(env, mdd_obj, handle);
mdd_write_unlock(env, mdd_obj);
static int mdt_raw_lookup(struct mdt_thread_info *info,
struct mdt_object *parent,
- const char* name,
+ const struct lu_name *lname,
struct ldlm_reply *ldlm_rep)
{
struct md_object *next = mdt_object_child(info->mti_object);
LASSERT(!info->mti_cross_ref);
/* Only got the fid of this obj by name */
- rc = mdo_lookup(info->mti_env, next, name, child_fid,
+ rc = mdo_lookup(info->mti_env, next, lname, child_fid,
&info->mti_spec);
#if 0
/* XXX is raw_lookup possible as intent operation? */
struct lu_fid *child_fid = &info->mti_tmp_fid1;
int is_resent, rc, namelen = 0;
const char *name;
+ struct lu_name *lname;
struct mdt_lock_handle *lhp;
struct ldlm_lock *lock;
struct ldlm_res_id *res_id;
namelen = req_capsule_get_size(&info->mti_pill, &RMF_NAME,
RCL_CLIENT);
+ lname = mdt_name(info->mti_env, (char *)name, namelen);
+
CDEBUG(D_INODE, "getattr with lock for "DFID"/%s, ldlm_rep = %p\n",
PFID(mdt_object_fid(parent)), name, ldlm_rep);
LBUG();
}
- rc = mdt_raw_lookup(info, parent, name, ldlm_rep);
+ rc = mdt_raw_lookup(info, parent, lname, ldlm_rep);
if (rc != 0) {
if (rc > 0)
rc = 0;
RETURN(rc);
/* step 2: lookup child's fid by name */
- rc = mdo_lookup(info->mti_env, next, name, child_fid,
+ rc = mdo_lookup(info->mti_env, next, lname, child_fid,
&info->mti_spec);
if (rc != 0) {
if (rc == -ENOENT)
/* Time for stats */
struct timeval mti_time;
+
+ /* Ops object filename */
+ struct lu_name mti_name;
};
/*
* Info allocated per-transaction.
return mdt_dlm_lock_modes[mode];
}
+static inline struct lu_name *mdt_name(const struct lu_env *env,
+ char *name, int namelen)
+{
+ struct lu_name *lname;
+ struct mdt_thread_info *mti;
+
+ mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
+ lname = &mti->mti_name;
+ lname->ln_name = name;
+ lname->ln_namelen = namelen;
+ return lname;
+}
+
/* lprocfs stuff */
int mdt_procfs_init(struct mdt_device *mdt, const char *name);
int mdt_procfs_fini(struct mdt_device *mdt);
struct lu_attr *la = &ma->ma_attr;
__u32 create_flags = info->mti_spec.sp_cr_flags;
struct mdt_reint_record *rr = &info->mti_rr;
+ struct lu_name *lname;
int result;
int created = 0;
ENTRY;
GOTO(out, result = PTR_ERR(parent));
fid_zero(child_fid);
+
+ lname = mdt_name(info->mti_env, (char *)rr->rr_name, rr->rr_namelen);
+
result = mdo_lookup(info->mti_env, mdt_object_child(parent),
- rr->rr_name, child_fid, &info->mti_spec);
+ lname, child_fid, &info->mti_spec);
LASSERTF(ergo(result == 0, fid_is_sane(child_fid)),
"looking for "DFID"/%s, result fid="DFID"\n",
PFID(mdt_object_fid(parent)), rr->rr_name, PFID(child_fid));
result = mdo_create(info->mti_env,
mdt_object_child(parent),
- rr->rr_name,
+ lname,
mdt_object_child(child),
&info->mti_spec,
&info->mti_attr);
struct mdt_body *repbody;
struct md_attr *ma = &info->mti_attr;
struct mdt_reint_record *rr = &info->mti_rr;
+ struct lu_name *lname;
int rc;
ENTRY;
*/
info->mti_spec.sp_cr_lookup = 1;
- rc = mdo_create(info->mti_env, next, rr->rr_name,
+ lname = mdt_name(info->mti_env, (char *)rr->rr_name,
+ rr->rr_namelen);
+ rc = mdo_create(info->mti_env, next, lname,
mdt_object_child(child),
&info->mti_spec, ma);
if (rc == 0) {
struct mdt_object *mc;
struct mdt_lock_handle *parent_lh;
struct mdt_lock_handle *child_lh;
+ struct lu_name *lname;
int rc;
ENTRY;
}
/* step 2: find & lock the child */
+ lname = mdt_name(info->mti_env, (char *)rr->rr_name, rr->rr_namelen);
rc = mdo_lookup(info->mti_env, mdt_object_child(mp),
- rr->rr_name, child_fid, &info->mti_spec);
+ lname, child_fid, &info->mti_spec);
if (rc != 0)
GOTO(out_unlock_parent, rc);
struct mdt_object *mp;
struct mdt_lock_handle *lhs;
struct mdt_lock_handle *lhp;
+ struct lu_name *lname;
int rc;
ENTRY;
mdt_fail_write(info->mti_env, info->mti_mdt->mdt_bottom,
OBD_FAIL_MDS_REINT_LINK_WRITE);
+ lname = mdt_name(info->mti_env, (char *)rr->rr_name, rr->rr_namelen);
rc = mdo_link(info->mti_env, mdt_object_child(mp),
- mdt_object_child(ms), rr->rr_name, ma);
+ mdt_object_child(ms), lname, ma);
EXIT;
mdt_object_unlock_put(info, ms, lhs, rc);
struct mdt_lock_handle *lh_tgtdir;
struct mdt_lock_handle *lh_tgt;
struct lu_fid *tgt_fid = &info->mti_tmp_fid1;
+ struct lu_name *lname;
int rc;
ENTRY;
/* step 2: find & lock the target object if exists. */
mdt_set_capainfo(info, 0, rr->rr_fid1, BYPASS_CAPA);
+ lname = mdt_name(info->mti_env, (char *)rr->rr_tgt, rr->rr_tgtlen);
rc = mdo_lookup(info->mti_env, mdt_object_child(mtgtdir),
- rr->rr_tgt, tgt_fid, &info->mti_spec);
+ lname, tgt_fid, &info->mti_spec);
if (rc != 0 && rc != -ENOENT) {
GOTO(out_unlock_tgtdir, rc);
} else if (rc == 0) {
struct lu_fid *old_fid = &info->mti_tmp_fid1;
struct lu_fid *new_fid = &info->mti_tmp_fid2;
struct lustre_handle rename_lh = { 0 };
+ struct lu_name *lname;
int rc;
ENTRY;
}
/* step 3: find & lock the old object. */
+ lname = mdt_name(info->mti_env, (char *)rr->rr_name, rr->rr_namelen);
rc = mdo_lookup(info->mti_env, mdt_object_child(msrcdir),
- rr->rr_name, old_fid, &info->mti_spec);
+ lname, old_fid, &info->mti_spec);
if (rc != 0)
GOTO(out_unlock_target, rc);
/* step 4: find & lock the new object. */
/* new target object may not exist now */
+ lname = mdt_name(info->mti_env, (char *)rr->rr_tgt, rr->rr_tgtlen);
rc = mdo_lookup(info->mti_env, mdt_object_child(mtgtdir),
- rr->rr_tgt, new_fid, &info->mti_spec);
+ lname, new_fid, &info->mti_spec);
if (rc == 0) {
/* the new_fid should have been filled at this moment */
if (lu_fid_eq(old_fid, new_fid))