Whamcloud - gitweb
- change rename()/rename_tgt() format - source fid is used instead of object.
authortappro <tappro>
Sun, 11 Jun 2006 17:05:03 +0000 (17:05 +0000)
committertappro <tappro>
Sun, 11 Jun 2006 17:05:03 +0000 (17:05 +0000)
The object can be remote one and will be unaccessible in mdd, so lu_fid is used
instead.

- fix rename() logic in cmm. It was overdesigned and is simplier actually
- fix few defect found while CODE stage in cmm/mdc.

lustre/cmm/cmm_object.c
lustre/cmm/mdc_internal.h
lustre/cmm/mdc_object.c
lustre/include/md_object.h
lustre/mdd/mdd_handler.c

index f04e9dd..52ab3a0 100644 (file)
@@ -309,7 +309,7 @@ static int cml_unlink(const struct lu_context *ctx, struct md_object *mo_p,
 }
 
 static int cml_rename(const struct lu_context *ctx, struct md_object *mo_po,
-                       struct md_object *mo_pn, struct md_object *mo_s,
+                       struct md_object *mo_pn, const struct lu_fid *lf,
                        const char *s_name, struct md_object *mo_t,
                        const char *t_name)
 {
@@ -325,35 +325,21 @@ static int cml_rename(const struct lu_context *ctx, struct md_object *mo_po,
         }
 
         rc = mdo_rename(ctx, cmm2child_obj(md2cmm_obj(mo_po)),
-                        cmm2child_obj(md2cmm_obj(mo_pn)),
-                        cmm2child_obj(md2cmm_obj(mo_s)), s_name,
+                        cmm2child_obj(md2cmm_obj(mo_pn)), lf, s_name, 
                         cmm2child_obj(md2cmm_obj(mo_t)), t_name);
+
         RETURN(rc);
 }
 
 static int cml_rename_tgt(const struct lu_context *ctx,
-                          struct md_object *mo_p,
-                          struct md_object *mo_s, struct md_object *mo_t,
-                          const char *name)
+                          struct md_object *mo_p, struct md_object *mo_t,
+                          const struct lu_fid *lf, const char *name)
 {
         int rc;
         ENTRY;
 
         rc = mdo_rename_tgt(ctx, cmm2child_obj(md2cmm_obj(mo_po)),
-                            cmm2child_obj(md2cmm_obj(mo_s)),
-                            cmm2child_obj(md2cmm_obj(mo_t)), name);
-        RETURN(rc);
-}
-
-static int cml_name_insert(const struct lu_context * ctx,
-                           struct md_object *mo_p,
-                           const char *name, const struct lu_fid *lf)
-{
-        int rc;
-        ENTRY;
-        
-        rc = mdo_name_insert(ctx, cmm2child_obj(md2cmm_obj(mo_po)), name, lf);
-
+                            cmm2child_obj(md2cmm_obj(mo_t)), lf, name);
         RETURN(rc);
 }
 
@@ -364,7 +350,6 @@ static struct md_dir_operations cmm_dir_ops = {
         .mdo_unlink      = cml_unlink,
         .mdo_rename      = cml_rename,
         .mdo_rename_tgt  = cml_rename_tgt,
-        .mdo_name_insert = cml_name_insert
 };
 
 /* -------------------------------------------------------------------
@@ -524,7 +509,10 @@ static struct md_object_operations cml_mo_ops = {
 static int cmr_lookup(const struct lu_context *ctx, struct md_object *mo_p,
                       const char *name, struct lu_fid *lf)
 {
-        RETURN(-EFAULT);
+        /*this can happens while rename()
+         * If new parent is remote dir, lookup will happens here */
+        
+        RETURN(-EREMOTE);
 }
 
 static int cmr_create(const struct lu_context *ctx,
@@ -580,51 +568,29 @@ static int cmr_unlink(const struct lu_context *ctx, struct md_object *mo_p,
 }
 
 static int cmr_rename(const struct lu_context *ctx, struct md_object *mo_po,
-                       struct md_object *mo_pn, struct md_object *mo_s,
+                       struct md_object *mo_pn, const struct lu_fid *lf,
                        const char *s_name, struct md_object *mo_t,
                        const char *t_name)
 {
         int rc;
         ENTRY;
-        rc = mdo_rename(ctx, cmm2child_obj(md2cmm_obj(mo_po)),
-                        cmm2child_obj(md2cmm_obj(mo_pn)),
-                        cmm2child_obj(md2cmm_obj(mo_s)), s_name,
-                        cmm2child_obj(md2cmm_obj(mo_t)), t_name);
-        
-        if (mo_t == NULL) { 
-                rc = mdo_name_insert(ctx, c_pn, t_name,
-                                     lu_object_fid(&c_s->mo_lu));
-                rc = mdo_name_remove(ctx, c_po, s_name); 
-        } else {
-                c_t =  cmm2child_obj(md2cmm_obj(mo_t));
-                if (cmm_is_local_obj(md2cmm_obj(mo_t))) {
-                        /*
-                         * target object is local so only name should
-                         * deleted/inserted on remote server 
-                         */
-                        rc = mdo_rename_tgt(ctx, c_pn, c_s,
-                                            NULL, t_name);
-                        /* localy the old name will be removed and target object
-                         * will be destroeyd*/
-                        rc = mdo_rename(ctx, c_po, NULL, c_s, 
-                                        s_name, c_t, NULL); 
-               } else {
-                        /* target object is remote one so just ask remote server
-                         * to continue with rename */
-                        rc = mdo_rename_tgt(ctx, c_pn, c_s,
-                                            c_t, t_name);
-                        /* only old name is removed localy */
-                        rc = mdo_name_destroy(ctx, c_po, s_name); 
-               }
-       }
+
+        /* the mo_pn is remote directory, so we cannot even know if there is
+         * mo_t or not. Therefore mo_t is NULL here but remote server should do
+         * lookup and process this further */
+
+        LASSERT(mo_t == NULL);
+        rc = mdo_rename_tgt(ctx, c_pn, NULL/* mo_t */, lf, t_name);
+        /* only old name is removed localy */
+        if (rc == 0) 
+                rc = mdo_name_destroy(ctx, c_po, s_name); 
 
         RETURN(rc);
 }
 
 static int cmr_rename_tgt(const struct lu_context *ctx,
-                          struct md_object *mo_p,
-                          struct md_object *mo_s, struct md_object *mo_t,
-                          const char *name)
+                          struct md_object *mo_p, struct md_object *mo_t,
+                          const struct lu_fid *lf, const char *name)
 {
         int rc;
         ENTRY;
@@ -632,18 +598,10 @@ static int cmr_rename_tgt(const struct lu_context *ctx,
         rc = mo_ref_del(ctx, cmm2child_obj(md2cmm_obj(mo_t)));
         /* continue locally with name handling only */
         rc = mdo_rename_tgt(ctx, cmm2child_obj(md2cmm_obj(mo_po)),
-                            cmm2child_obj(md2cmm_obj(mo_s)),
-                            NULL, name);
+                            NULL, lf, name);
         RETURN(rc);
 }
 
-static int cmr_name_insert(const struct lu_context * ctx,
-                           struct md_object *mo_p,
-                           const char *name, const struct lu_fid *lf)
-{
-        RETURN(-EFAULT);
-}
-
 static struct md_dir_operations cmm_dir_ops = {
         .mdo_lookup      = cmr_lookup,
         .mdo_create      = cmr_create,
@@ -651,7 +609,6 @@ static struct md_dir_operations cmm_dir_ops = {
         .mdo_unlink      = cmr_unlink,
         .mdo_rename      = cmr_rename,
         .mdo_rename_tgt  = cmr_rename_tgt,
-        .mdo_name_insert = cmr_name_insert,
 };
 
 #else /* CMM_CODE */
index 1f66261..91c13bf 100644 (file)
@@ -31,7 +31,7 @@
 
 struct mdc_cli_desc {
         struct obd_connect_data  cl_conn_data;
-        struct obd_uuid          cl_srv_uuid;
+        struct obd_uuid          cl_cli_uuid;
         struct obd_export        *cl_exp;
 };
 
index ce955f7..3d46f49 100644 (file)
@@ -176,31 +176,9 @@ static struct md_object_operations mdc_mo_ops = {
 };
 
 /* md_dir_operations */
-static int mdc_name_insert(const struct lu_context *ctx, struct md_object *mo,
-                           const char *name, const struct lu_fid *lf)
-{
-        struct mdc_device *mc = md2mdc_dev(md_device_get(mo));
-        struct mdc_thread_info *mci;
-        int rc;
-        ENTRY;
-
-        mci = lu_context_get_key(ctx, &mdc_thread_key);
-        LASSERT(mci);
-
-        mci->mci_opdata.fid1 = *lu_object_fid(&mo->mo_lu);
-        mci->mci_opdata.fid2 = *lf;
-        mci->mci_opdata.mod_time = attr->la_mtime;
-        //TODO: distinguish the name_insert and rename_tgt()
-
-        rc = md_rename(mc->mc_desc.cl_exp, &mci->mci_opdata, NULL, 0,
-                       name, strlen(name), &mci->mci_req);
-
-        RETURN(rc);
-}
-
 static int mdc_rename_tgt(const struct lu_context *ctx,
-                          struct md_object *mo_p, struct md_object *mo_s,
-                          struct md_object *mo_t, const char *name)
+                          struct md_object *mo_p, struct md_object *mo_t,
+                          const struct lu_fid *lf, const char *name)
 {
         struct mdc_device *mc = md2mdc_dev(md_device_get(mo));
         struct mdc_thread_info *mci;
@@ -211,7 +189,7 @@ static int mdc_rename_tgt(const struct lu_context *ctx,
         LASSERT(mci);
 
         mci->mci_opdata.fid1 = *lu_object_fid(&mo_p->mo_lu);
-        mci->mci_opdata.fid2 = *lu_object_fid(&mo_s->mo_lu);
+        mci->mci_opdata.fid2 = *lf;
         mci->mci_opdata.mod_time = attr->la_mtime;
 
         rc = md_rename(mc->mc_desc.cl_exp, &mci->mci_opdata, NULL, 0,
@@ -221,7 +199,6 @@ static int mdc_rename_tgt(const struct lu_context *ctx,
 }
 
 static struct md_dir_operations mdc_dir_ops = {
-        .mdo_name_insert = mdc_name_insert,
         .mdo_rename_tgt  = mdc_rename_tgt,
 };
 
index 66accfc..4d1fd9f 100644 (file)
@@ -86,10 +86,9 @@ struct md_dir_operations {
                           struct lu_attr *);
 
         int (*mdo_rename)(const struct lu_context *ctxt,
-                          struct md_object *spobj,
-                          struct md_object *tpobj, struct md_object *sobj,
-                          const char *sname, struct md_object *tobj,
-                          const char *tname);
+                          struct md_object *spobj, struct md_object *tpobj,
+                          const struct lu_fid *lf, const char *sname,
+                          struct md_object *tobj, const char *tname);
 
         int (*mdo_link)(const struct lu_context *ctxt, struct md_object *tobj,
                         struct md_object *sobj, const char *name);
@@ -103,7 +102,7 @@ struct md_dir_operations {
         int (*mdo_name_remove)(const struct lu_context *, struct md_object *,
                                const char *);
         int (*mdo_rename_tgt)(const struct lu_context *, struct md_object *,
-                              struct md_object *, struct md_object *,
+                              struct md_object *, const struct lu_fid *,
                               const char *);
 };
 
@@ -231,11 +230,11 @@ static inline int mdo_create(const struct lu_context *cx,
 
 static inline int mdo_rename(const struct lu_context *cx,
                              struct md_object *sp, struct md_object *tp,
-                             struct md_object *s, const char *sname,
+                             const struct lu_fid *lf, const char *sname,
                              struct md_object *t, const char *tname)
 {
         LASSERT(tp->mo_dir_ops->mdo_rename);
-        return tp->mo_dir_ops->mdo_rename(cx, sp, tp, s, sname, t, tname);
+        return tp->mo_dir_ops->mdo_rename(cx, sp, tp, lf, sname, t, tname);
 }
 
 static inline int mdo_link(const struct lu_context *cx, struct md_object *p,
@@ -269,16 +268,15 @@ static inline int mdo_name_remove(const struct lu_context *cx,
 }
 
 static inline int mdo_rename_tgt(const struct lu_context *cx,
-                                 struct md_object *p,
-                                 struct md_object *s, struct md_object *t,
-                                 const char *name)
+                                 struct md_object *p, struct md_object *t,
+                                 const struct lu_fid *lf, const char *name)
 {
         if (t) {
                 LASSERT(t->mo_dir_ops->mdo_rename_tgt);
-                return t->mo_dir_ops->mdo_rename_tgt(cx, p, s, t, name);
+                return t->mo_dir_ops->mdo_rename_tgt(cx, p, t, lf, name);
         } else {
                 LASSERT(p->mo_dir_ops->mdo_rename_tgt);
-                return p->mo_dir_ops->mdo_rename_tgt(cx, p, s, t, name);
+                return p->mo_dir_ops->mdo_rename_tgt(cx, p, t, lf, name);
         }
 }
 #endif /* _LINUX_MD_OBJECT_H */
index fb01970..cf16c6c 100644 (file)
@@ -617,23 +617,20 @@ __mdd_index_insert(const struct lu_context *ctxt, struct mdd_object *pobj,
 
 static int
 __mdd_index_delete(const struct lu_context *ctxt, struct mdd_device *mdd,
-                   struct mdd_object *pobj,
-                   struct mdd_object *obj, const char *name,
+                   struct mdd_object *pobj, const char *name,
                    struct thandle *handle)
 {
         int rc;
         struct dt_object *next = mdd_object_child(pobj);
         ENTRY;
 
-        mdd_lock2(ctxt, pobj, obj);
-
         rc = next->do_index_ops->dio_delete(ctxt, next,
                                             (struct dt_key *)name, handle);
-        mdd_unlock2(ctxt, pobj, obj);
 
         RETURN(rc);
 }
 
+/* XXX not used anywhere
 static int
 mdd_index_delete(const struct lu_context *ctxt, struct md_object *pobj,
                  struct md_object *obj, const char *name)
@@ -650,13 +647,13 @@ mdd_index_delete(const struct lu_context *ctxt, struct md_object *pobj,
         if (IS_ERR(handle))
                 RETURN(PTR_ERR(handle));
 
-        rc = __mdd_index_delete(ctxt, mdd, mdd_pobj, mdd_obj, name, handle);
+        rc = __mdd_index_delete(ctxt, mdd, mdd_pobj, name, handle);
 
         mdd_trans_stop(ctxt, mdd, handle);
 
         RETURN(rc);
 }
-
+*/
 static int
 mdd_link(const struct lu_context *ctxt, struct md_object *tgt_obj,
          struct md_object *src_obj, const char *name)
@@ -695,14 +692,14 @@ exit:
 static void mdd_rename_lock(struct mdd_device *mdd,
                             struct mdd_object *src_pobj,
                             struct mdd_object *tgt_pobj,
-                            struct mdd_object *sobj,
+                            /*struct mdd_object *sobj,*/
                             struct mdd_object *tobj)
 {
         return;
 }
 
 static void mdd_rename_unlock(struct mdd_device *mdd, struct mdd_object *src_pobj,
-                              struct mdd_object *tgt_pobj, struct mdd_object *sobj,
+                              struct mdd_object *tgt_pobj/*, struct mdd_object *sobj*/,
                               struct mdd_object *tobj)
 {
         return;
@@ -710,13 +707,12 @@ static void mdd_rename_unlock(struct mdd_device *mdd, struct mdd_object *src_pob
 
 static int
 mdd_rename(const struct lu_context *ctxt, struct md_object *src_pobj,
-           struct md_object *tgt_pobj, struct md_object *sobj,
+           struct md_object *tgt_pobj, const struct lu_fid *lf,
            const char *sname, struct md_object *tobj, const char *tname)
 {
         struct mdd_device *mdd = mdo2mdd(src_pobj);
         struct mdd_object *mdd_spobj = mdo2mddo(src_pobj);
         struct mdd_object *mdd_tpobj = mdo2mddo(tgt_pobj);
-        struct mdd_object *mdd_sobj = mdo2mddo(sobj);
         struct mdd_object *mdd_tobj = mdo2mddo(tobj);
         int rc;
         struct thandle *handle;
@@ -726,18 +722,18 @@ mdd_rename(const struct lu_context *ctxt, struct md_object *src_pobj,
         if (IS_ERR(handle))
                 RETURN(PTR_ERR(handle));
 
-        mdd_rename_lock(mdd, mdd_spobj, mdd_tpobj, mdd_sobj, mdd_tobj);
+        mdd_rename_lock(mdd, mdd_spobj, mdd_tpobj, /*mdd_sobj, */ mdd_tobj);
 
-        rc = __mdd_index_delete(ctxt, mdd, mdd_spobj, mdd_sobj, sname, handle);
+        rc = __mdd_index_delete(ctxt, mdd, mdd_spobj, sname, handle);
         if (rc)
                 GOTO(cleanup, rc);
 
-        rc = __mdd_index_delete(ctxt, mdd, mdd_tpobj, mdd_tobj, tname, handle);
+        /*TODO: if (mdd_tobj != NULL)*/
+        rc = __mdd_index_delete(ctxt, mdd, mdd_tpobj, tname, handle);
         if (rc)
                 GOTO(cleanup, rc);
 
-        rc = __mdd_index_insert(ctxt, mdd_spobj, lu_object_fid(&tobj->mo_lu),
-                                tname, handle);
+        rc = __mdd_index_insert(ctxt, mdd_tpobj, lf, tname, handle);
         if (rc)
                 GOTO(cleanup, rc);
 
@@ -747,7 +743,7 @@ mdd_rename(const struct lu_context *ctxt, struct md_object *src_pobj,
                         GOTO(cleanup, rc);
         }
 cleanup:
-        mdd_rename_unlock(mdd, mdd_spobj, mdd_tpobj, mdd_sobj, mdd_tobj);
+        mdd_rename_unlock(mdd, mdd_spobj, mdd_tpobj, /*mdd_sobj,*/ mdd_tobj);
         mdd_trans_stop(ctxt, mdd, handle);
         RETURN(rc);
 }