* Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
* Use is subject to license terms.
*
- * Copyright (c) 2010, 2013, Intel Corporation.
+ * Copyright (c) 2010, 2014, Intel Corporation.
*/
/*
* This file is part of Lustre, http://www.lustre.org/
EXIT;
}
-int mdt_attr_get_eabuf_size(struct mdt_thread_info *info, struct mdt_object *o)
+static int mdt_attr_get_eabuf_size(struct mdt_thread_info *info,
+ struct mdt_object *o)
{
const struct lu_env *env = info->mti_env;
int rc, rc2;
}
static int mdt_raw_lookup(struct mdt_thread_info *info,
- struct mdt_object *parent,
- const struct lu_name *lname,
- struct ldlm_reply *ldlm_rep)
+ struct mdt_object *parent,
+ const struct lu_name *lname,
+ struct ldlm_reply *ldlm_rep)
{
- struct md_object *next = mdt_object_child(info->mti_object);
- const struct mdt_body *reqbody = info->mti_body;
- struct lu_fid *child_fid = &info->mti_tmp_fid1;
- struct mdt_body *repbody;
- int rc;
- ENTRY;
-
- if (reqbody->mbo_valid != OBD_MD_FLID)
- RETURN(0);
+ struct lu_fid *child_fid = &info->mti_tmp_fid1;
+ int rc;
+ ENTRY;
- LASSERT(!info->mti_cross_ref);
+ LASSERT(!info->mti_cross_ref);
- /* Only got the fid of this obj by name */
- fid_zero(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? */
- if (rc != 0) {
- if (rc == -ENOENT)
- mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_NEG);
- RETURN(rc);
- } else
- mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
+ /* Only got the fid of this obj by name */
+ fid_zero(child_fid);
+ rc = mdo_lookup(info->mti_env, mdt_object_child(info->mti_object),
+ lname, child_fid, &info->mti_spec);
+ if (rc == 0) {
+ struct mdt_body *repbody;
- repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
-#endif
- if (rc == 0) {
- repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
+ repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
repbody->mbo_fid1 = *child_fid;
repbody->mbo_valid = OBD_MD_FLID;
- }
- RETURN(1);
+ mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
+ } else if (rc == -ENOENT) {
+ mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_NEG);
+ }
+
+ RETURN(rc);
}
/*
}
if (lu_name_is_valid(lname)) {
- rc = mdt_raw_lookup(info, parent, lname, ldlm_rep);
- if (rc != 0) {
- if (rc > 0)
- rc = 0;
+ /* Always allow to lookup ".." */
+ if (unlikely(lname->ln_namelen == 2 &&
+ lname->ln_name[0] == '.' &&
+ lname->ln_name[1] == '.'))
+ info->mti_spec.sp_permitted = 1;
+
+ if (info->mti_body->mbo_valid == OBD_MD_FLID) {
+ rc = mdt_raw_lookup(info, parent, lname, ldlm_rep);
+
RETURN(rc);
}
struct mdt_lock_handle *lhc)
{
/* the lock might already be gotten in ldlm_handle_enqueue() */
- if (lustre_handle_is_used(&lhc->mlh_reg_lh)) {
+ if (unlikely(lustre_handle_is_used(&lhc->mlh_reg_lh))) {
struct ptlrpc_request *req = mdt_info_req(info);
struct ldlm_lock *lock;
info->mti_spec.no_create = 0;
info->mti_spec.sp_rm_entry = 0;
+ info->mti_spec.sp_permitted = 0;
info->mti_spec.u.sp_ea.eadata = NULL;
info->mti_spec.u.sp_ea.eadatalen = 0;
/* the open lock or the lock for cross-ref object should be
* returned to the client */
- if (rc == -MDT_EREMOTE_OPEN || mdt_get_disposition(rep, DISP_OPEN_LOCK)) {
- LASSERT(lustre_handle_is_used(&lhc->mlh_reg_lh));
+ if (lustre_handle_is_used(&lhc->mlh_reg_lh) &&
+ (rc == 0 || rc == -MDT_EREMOTE_OPEN)) {
rep->lock_policy_res2 = 0;
rc = mdt_intent_lock_replace(info, lockp, lhc, flags);
RETURN(rc);
mdt_get_disposition(rep, DISP_LOOKUP_NEG))
rep->lock_policy_res2 = 0;
+ lhc->mlh_reg_lh.cookie = 0ull;
if (rc == -ENOTCONN || rc == -ENODEV ||
rc == -EOVERFLOW) { /**< if VBR failure then return error */
/*
* will detect this, then disconnect, reconnect the import
* immediately, instead of impacting the following the rpc.
*/
- lhc->mlh_reg_lh.cookie = 0ull;
RETURN(rc);
- } else {
- /*
- * For other cases, the error will be returned by intent.
- * and client will retrieve the result from intent.
- */
- /*
- * FIXME: when open lock is finished, that should be
- * checked here.
- */
- if (lustre_handle_is_used(&lhc->mlh_reg_lh)) {
- LASSERTF(rc == 0, "Error occurred but lock handle "
- "is still in use, rc = %d\n", rc);
- rep->lock_policy_res2 = 0;
- rc = mdt_intent_lock_replace(info, lockp, lhc, flags);
- RETURN(rc);
- } else {
- lhc->mlh_reg_lh.cookie = 0ull;
- RETURN(ELDLM_LOCK_ABORTED);
- }
}
+ /*
+ * For other cases, the error will be returned by intent, and client
+ * will retrieve the result from intent.
+ */
+ RETURN(ELDLM_LOCK_ABORTED);
}
static int mdt_intent_code(long itcode)
lustre_cfg_bufs_reset(bufs, mdt_obd_name(m));
lustre_cfg_bufs_set_string(bufs, 1, NULL);
lcfg = lustre_cfg_new(LCFG_PRE_CLEANUP, bufs);
- if (!lcfg) {
- CERROR("%s: cannot alloc lcfg\n", mdt_obd_name(m));
- return;
- }
+ if (lcfg == NULL)
+ RETURN_EXIT;
+
top->ld_ops->ldo_process_config(env, top, lcfg);
lustre_cfg_free(lcfg);
EXIT;
strcat(flags, "A");
lustre_cfg_bufs_set_string(bufs, 1, flags);
lcfg = lustre_cfg_new(LCFG_CLEANUP, bufs);
- if (!lcfg) {
- CERROR("Cannot alloc lcfg!\n");
- return;
- }
+ if (lcfg == NULL)
+ RETURN_EXIT;
+
LASSERT(top);
top->ld_ops->ldo_process_config(env, top, lcfg);
lustre_cfg_free(lcfg);
lustre_cfg_bufs_set_string(bufs, 3, lprof->lp_dt);
lcfg = lustre_cfg_new(LCFG_ATTACH, bufs);
- if (!lcfg)
+ if (lcfg == NULL)
GOTO(free_bufs, rc = -ENOMEM);
rc = class_attach(lcfg);
lustre_cfg_bufs_set_string(bufs, 3, lprof->lp_dt);
lcfg = lustre_cfg_new(LCFG_SETUP, bufs);
+ if (lcfg == NULL)
+ GOTO(class_detach, rc = -ENOMEM);
rc = class_setup(obd, lcfg);
if (rc)
lustre_cfg_bufs_set_string(bufs, 3, lprof->lp_dt);
lcfg = lustre_cfg_new(LCFG_ATTACH, bufs);
- if (!lcfg)
+ if (lcfg == NULL)
GOTO(cleanup_mem, rc = -ENOMEM);
rc = class_attach(lcfg);
mdt->mdt_bottom->dd_lu_dev.ld_obd->obd_name);
lcfg = lustre_cfg_new(LCFG_SETUP, bufs);
+ if (lcfg == NULL)
+ GOTO(class_detach, rc = -ENOMEM);
rc = class_setup(obd, lcfg);
if (rc)
/* mdt_getxattr() is used from mdt_intent_getxattr(), use this wrapper
* for now. This will be removed along with converting rest of MDT code
* to use tgt_session_info */
-int mdt_tgt_getxattr(struct tgt_session_info *tsi)
+static int mdt_tgt_getxattr(struct tgt_session_info *tsi)
{
struct mdt_thread_info *info = tsi2mdt_info(tsi);
int rc;
RETURN(0);
}
-/** The maximum depth that fid2path() will search.
- * This is limited only because we want to store the fids for
- * historical path lookup purposes.
- */
-#define MAX_PATH_DEPTH 100
-
-/** mdt_path() lookup structure. */
-struct path_lookup_info {
- __u64 pli_recno; /**< history point */
- __u64 pli_currec; /**< current record */
- struct lu_fid pli_fid;
- struct lu_fid pli_fids[MAX_PATH_DEPTH]; /**< path, in fids */
- struct mdt_object *pli_mdt_obj;
- char *pli_path; /**< full path */
- int pli_pathlen;
- int pli_linkno; /**< which hardlink to follow */
- int pli_fidcount; /**< number of \a pli_fids */
-};
-
int mdt_links_read(struct mdt_thread_info *info, struct mdt_object *mdt_obj,
struct linkea_data *ldata)
{
return linkea_init(ldata);
}
+/**
+ * Given an MDT object, try to look up the full path to the object.
+ * Part of the MDT layer implementation of lfs fid2path.
+ *
+ * \param[in] info Per-thread common data shared by MDT level handlers.
+ * \param[in] obj Object to do path lookup of
+ * \param[in,out] fp User-provided struct to store path information
+ *
+ * \retval 0 Lookup successful, path information stored in fp
+ * \retval -EAGAIN Lookup failed, usually because object is being moved
+ * \retval negative errno if there was a problem
+ */
static int mdt_path_current(struct mdt_thread_info *info,
- struct path_lookup_info *pli)
+ struct mdt_object *obj,
+ struct getinfo_fid2path *fp)
{
struct mdt_device *mdt = info->mti_mdt;
struct mdt_object *mdt_obj;
int reclen;
struct linkea_data ldata = { 0 };
int rc = 0;
+ bool first = true;
ENTRY;
/* temp buffer for path element, the buffer will be finally freed
RETURN(-ENOMEM);
ldata.ld_buf = buf;
- ptr = pli->pli_path + pli->pli_pathlen - 1;
+ ptr = fp->gf_path + fp->gf_pathlen - 1;
*ptr = 0;
--ptr;
- pli->pli_fidcount = 0;
- pli->pli_fids[0] = *(struct lu_fid *)mdt_object_fid(pli->pli_mdt_obj);
- *tmpfid = pli->pli_fids[0];
+ *tmpfid = fp->gf_fid = *mdt_object_fid(obj);
+
/* root FID only exists on MDT0, and fid2path should also ends at MDT0,
* so checking root_fid can only happen on MDT0. */
- while (!lu_fid_eq(&mdt->mdt_md_root_fid,
- &pli->pli_fids[pli->pli_fidcount])) {
+ while (!lu_fid_eq(&mdt->mdt_md_root_fid, &fp->gf_fid)) {
struct lu_buf lmv_buf;
mdt_obj = mdt_object_find(info->mti_env, mdt, tmpfid);
linkea_entry_unpack(lee, &reclen, tmpname, tmpfid);
/* If set, use link #linkno for path lookup, otherwise use
link #0. Only do this for the final path element. */
- if (pli->pli_fidcount == 0 &&
- pli->pli_linkno < leh->leh_reccount) {
+ if (first && fp->gf_linkno < leh->leh_reccount) {
int count;
- for (count = 0; count < pli->pli_linkno; count++) {
+ for (count = 0; count < fp->gf_linkno; count++) {
lee = (struct link_ea_entry *)
((char *)lee + reclen);
linkea_entry_unpack(lee, &reclen, tmpname,
tmpfid);
}
- if (pli->pli_linkno < leh->leh_reccount - 1)
+ if (fp->gf_linkno < leh->leh_reccount - 1)
/* indicate to user there are more links */
- pli->pli_linkno++;
+ fp->gf_linkno++;
}
lmv_buf.lb_buf = info->mti_xattr_buf;
/* For slave stripes, get its master */
if (le32_to_cpu(lmm->lmv_magic) == LMV_MAGIC_STRIPE) {
- pli->pli_fids[pli->pli_fidcount] = *tmpfid;
+ fp->gf_fid = *tmpfid;
continue;
}
} else if (rc < 0 && rc != -ENODATA) {
/* Pack the name in the end of the buffer */
ptr -= tmpname->ln_namelen;
- if (ptr - 1 <= pli->pli_path)
+ if (ptr - 1 <= fp->gf_path)
GOTO(out, rc = -EOVERFLOW);
strncpy(ptr, tmpname->ln_name, tmpname->ln_namelen);
*(--ptr) = '/';
- /* Store the parent fid for historic lookup */
- if (++pli->pli_fidcount >= MAX_PATH_DEPTH)
- GOTO(out, rc = -EOVERFLOW);
- pli->pli_fids[pli->pli_fidcount] = *tmpfid;
+ /* keep the last resolved fid to the client, so the
+ * client will build the left path on another MDT for
+ * remote object */
+ fp->gf_fid = *tmpfid;
+
+ first = false;
}
remote_out:
ptr++; /* skip leading / */
- memmove(pli->pli_path, ptr, pli->pli_path + pli->pli_pathlen - ptr);
+ memmove(fp->gf_path, ptr, fp->gf_path + fp->gf_pathlen - ptr);
- EXIT;
out:
- return rc;
+ RETURN(rc);
}
-/* Returns the full path to this fid, as of changelog record recno. */
+/**
+ * Given an MDT object, use mdt_path_current to get the path.
+ * Essentially a wrapper to retry mdt_path_current a set number of times
+ * if -EAGAIN is returned (usually because an object is being moved).
+ *
+ * Part of the MDT layer implementation of lfs fid2path.
+ *
+ * \param[in] info Per-thread common data shared by mdt level handlers.
+ * \param[in] obj Object to do path lookup of
+ * \param[in,out] fp User-provided struct for arguments and to store path
+ * information
+ *
+ * \retval 0 Lookup successful, path information stored in fp
+ * \retval negative errno if there was a problem
+ */
static int mdt_path(struct mdt_thread_info *info, struct mdt_object *obj,
- char *path, int pathlen, __u64 *recno, int *linkno,
- struct lu_fid *fid)
+ struct getinfo_fid2path *fp)
{
struct mdt_device *mdt = info->mti_mdt;
- struct path_lookup_info *pli;
int tries = 3;
int rc = -EAGAIN;
ENTRY;
- if (pathlen < 3)
+ if (fp->gf_pathlen < 3)
RETURN(-EOVERFLOW);
if (lu_fid_eq(&mdt->mdt_md_root_fid, mdt_object_fid(obj))) {
- path[0] = '\0';
+ fp->gf_path[0] = '\0';
RETURN(0);
}
- OBD_ALLOC_PTR(pli);
- if (pli == NULL)
- RETURN(-ENOMEM);
-
- pli->pli_mdt_obj = obj;
- pli->pli_recno = *recno;
- pli->pli_path = path;
- pli->pli_pathlen = pathlen;
- pli->pli_linkno = *linkno;
-
/* Retry multiple times in case file is being moved */
while (tries-- && rc == -EAGAIN)
- rc = mdt_path_current(info, pli);
-
- /* return the last resolved fids to the client, so the client will
- * build the left path on another MDT for remote object */
- *fid = pli->pli_fids[pli->pli_fidcount];
-
- *recno = pli->pli_currec;
- /* Return next link index to caller */
- *linkno = pli->pli_linkno;
-
- OBD_FREE_PTR(pli);
+ rc = mdt_path_current(info, obj, fp);
RETURN(rc);
}
+/**
+ * Get the full path of the provided FID, as of changelog record recno.
+ *
+ * This checks sanity and looks up object for user provided FID
+ * before calling the actual path lookup code.
+ *
+ * Part of the MDT layer implementation of lfs fid2path.
+ *
+ * \param[in] info Per-thread common data shared by mdt level handlers.
+ * \param[in,out] fp User-provided struct for arguments and to store path
+ * information
+ *
+ * \retval 0 Lookup successful, path information and recno stored in fp
+ * \retval -ENOENT, object does not exist
+ * \retval negative errno if there was a problem
+ */
static int mdt_fid2path(struct mdt_thread_info *info,
struct getinfo_fid2path *fp)
{
RETURN(rc);
}
- rc = mdt_path(info, obj, fp->gf_path, fp->gf_pathlen, &fp->gf_recno,
- &fp->gf_linkno, &fp->gf_fid);
+ rc = mdt_path(info, obj, fp);
CDEBUG(D_INFO, "fid "DFID", path %s recno "LPX64" linkno %u\n",
PFID(&fp->gf_fid), fp->gf_path, fp->gf_recno, fp->gf_linkno);