Whamcloud - gitweb
LU-2154 osp: osd-zfs: remove 2.3.x debugging code
[fs/lustre-release.git] / lustre / osd-zfs / osd_index.c
index f14faf7..864b925 100644 (file)
@@ -476,6 +476,27 @@ static inline void osd_object_put(const struct lu_env *env,
        lu_object_put(env, &obj->oo_dt.do_lu);
 }
 
+static int osd_remote_fid(const struct lu_env *env, struct osd_device *osd,
+                         struct lu_fid *fid)
+{
+       struct lu_seq_range     *range = &osd_oti_get(env)->oti_seq_range;
+       struct seq_server_site  *ss = osd_seq_site(osd);
+       int                     rc;
+       ENTRY;
+
+       if (!fid_is_norm(fid) && !fid_is_root(fid))
+               RETURN(0);
+
+       rc = osd_fld_lookup(env, osd, fid, range);
+       if (rc != 0) {
+               CERROR("%s: Can not lookup fld for "DFID"\n",
+                      osd_name(osd), PFID(fid));
+               RETURN(rc);
+       }
+
+       RETURN(ss->ss_node_id != range->lsr_index);
+}
+
 /**
  *      Inserts (key, value) pair in \a directory object.
  *
@@ -499,7 +520,7 @@ static int osd_dir_insert(const struct lu_env *env, struct dt_object *dt,
        struct osd_device   *osd = osd_obj2dev(parent);
        struct lu_fid       *fid = (struct lu_fid *)rec;
        struct osd_thandle  *oh;
-       struct osd_object   *child;
+       struct osd_object   *child = NULL;
        __u32                attr;
        char                *name = (char *)key;
        int                  rc;
@@ -514,55 +535,60 @@ static int osd_dir_insert(const struct lu_env *env, struct dt_object *dt,
        LASSERT(th != NULL);
        oh = container_of0(th, struct osd_thandle, ot_super);
 
-       child = osd_object_find(env, dt, fid);
-       if (IS_ERR(child))
-               RETURN(PTR_ERR(child));
-
-/*
- * to simulate old Orion setups with ./..  stored in the directories
- */
-#if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 3, 91, 0)
-#define OSD_ZFS_INSERT_DOTS_FOR_TESTING__
-#endif
+       rc = osd_remote_fid(env, osd, fid);
+       if (rc < 0) {
+               CERROR("%s: Can not find object "DFID": rc = %d\n",
+                      osd->od_svname, PFID(fid), rc);
+               RETURN(rc);
+       }
 
-       LASSERT(child->oo_db);
-       if (name[0] == '.') {
-               if (name[1] == 0) {
-                       /* do not store ".", instead generate it
-                        * during iteration */
-#ifndef OSD_ZFS_INSERT_DOTS_FOR_TESTING
-                       GOTO(out, rc = 0);
-#endif
-               } else if (name[1] == '.' && name[2] == 0) {
-                       /* update parent dnode in the child.
-                        * later it will be used to generate ".." */
-                       udmu_objset_t *uos = &osd->od_objset;
-                       rc = osd_object_sa_update(parent, SA_ZPL_PARENT(uos),
-                                                 &child->oo_db->db_object,
-                                                 8, oh);
-
-#ifndef OSD_ZFS_INSERT_DOTS_FOR_TESTING
-                       GOTO(out, rc);
-#endif
+       if (unlikely(rc == 1)) {
+               /* Insert remote entry */
+               memset(&oti->oti_zde.lzd_reg, 0, sizeof(oti->oti_zde.lzd_reg));
+               oti->oti_zde.lzd_reg.zde_type = IFTODT(S_IFDIR & S_IFMT);
+       } else {
+               /*
+                * To simulate old Orion setups with ./..  stored in the
+                * directories
+                */
+               /* Insert local entry */
+               child = osd_object_find(env, dt, fid);
+               if (IS_ERR(child))
+                       RETURN(PTR_ERR(child));
+
+               LASSERT(child->oo_db);
+               if (name[0] == '.') {
+                       if (name[1] == 0) {
+                               /* do not store ".", instead generate it
+                                * during iteration */
+                               GOTO(out, rc = 0);
+                       } else if (name[1] == '.' && name[2] == 0) {
+                               /* update parent dnode in the child.
+                                * later it will be used to generate ".." */
+                               udmu_objset_t *uos = &osd->od_objset;
+                               rc = osd_object_sa_update(parent,
+                                                SA_ZPL_PARENT(uos),
+                                                &child->oo_db->db_object,
+                                                8, oh);
+                               GOTO(out, rc);
+                       }
                }
+               CLASSERT(sizeof(oti->oti_zde.lzd_reg) == 8);
+               CLASSERT(sizeof(oti->oti_zde) % 8 == 0);
+               attr = child->oo_dt.do_lu.lo_header ->loh_attr;
+               oti->oti_zde.lzd_reg.zde_type = IFTODT(attr & S_IFMT);
+               oti->oti_zde.lzd_reg.zde_dnode = child->oo_db->db_object;
        }
 
-       CLASSERT(sizeof(oti->oti_zde.lzd_reg) == 8);
-       CLASSERT(sizeof(oti->oti_zde) % 8 == 0);
-       attr = child->oo_dt.do_lu.lo_header ->loh_attr;
-       oti->oti_zde.lzd_reg.zde_type = IFTODT(attr & S_IFMT);
-       oti->oti_zde.lzd_reg.zde_dnode = child->oo_db->db_object;
        oti->oti_zde.lzd_fid = *fid;
-
        /* Insert (key,oid) into ZAP */
        rc = -zap_add(osd->od_objset.os, parent->oo_db->db_object,
                      (char *)key, 8, sizeof(oti->oti_zde) / 8,
                      (void *)&oti->oti_zde, oh->ot_tx);
 
-#ifndef OSD_ZFS_INSERT_DOTS_FOR_TESTING
 out:
-#endif
-       osd_object_put(env, child);
+       if (child != NULL)
+               osd_object_put(env, child);
 
        RETURN(rc);
 }
@@ -608,10 +634,9 @@ static int osd_dir_delete(const struct lu_env *env, struct dt_object *dt,
        LASSERT(th != NULL);
        oh = container_of0(th, struct osd_thandle, ot_super);
 
-#ifndef OSD_ZFS_INSERT_DOTS_FOR_TESTING
        /*
-        * in Orion . and .. were stored in the directory (not generated up on
-        * request as now. we preserve them for backward compatibility
+        * In Orion . and .. were stored in the directory (not generated upon
+        * request as now). we preserve them for backward compatibility
         */
        if (name[0] == '.') {
                if (name[1] == 0) {
@@ -620,7 +645,6 @@ static int osd_dir_delete(const struct lu_env *env, struct dt_object *dt,
                        RETURN(0);
                }
        }
-#endif
 
        /* Remove key from the ZAP */
        rc = -zap_remove(osd->od_objset.os, zap_db->db_object,
@@ -807,7 +831,7 @@ static struct dt_key *osd_dir_it_key(const struct lu_env *env,
 
        strcpy(it->ozi_name, za->za_name);
 
-#if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 3, 91, 0)
+#if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 3, 90, 0)
        if (za->za_name[0] == '.') {
                if (za->za_name[1] == 0 || (za->za_name[1] == '.' &&
                    za->za_name[2] == 0)) {
@@ -840,7 +864,7 @@ static int osd_dir_it_key_size(const struct lu_env *env, const struct dt_it *di)
        if ((rc = -zap_cursor_retrieve(it->ozi_zc, za)) == 0)
                rc = strlen(za->za_name);
 
-#if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 3, 99, 0)
+#if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 3, 90, 0)
        if (rc == 0 && za->za_name[0] == '.') {
                if (za->za_name[1] == 0 || (za->za_name[1] == '.' &&
                    za->za_name[2] == 0)) {
@@ -964,14 +988,10 @@ static int osd_dir_it_load(const struct lu_env *env,
        int                rc;
        ENTRY;
 
-       if (it->ozi_pos != 0) {
-               /* the cursor wasn't at the beginning
-                * so we should reset ZAP cursor as well */
-               udmu_zap_cursor_fini(it->ozi_zc);
-               if (udmu_zap_cursor_init(&it->ozi_zc, &osd->od_objset,
-                                        obj->oo_db->db_object, hash))
-                       RETURN(-ENOMEM);
-       }
+       udmu_zap_cursor_fini(it->ozi_zc);
+       if (udmu_zap_cursor_init(&it->ozi_zc, &osd->od_objset,
+                                obj->oo_db->db_object, hash))
+               RETURN(-ENOMEM);
 
        if (hash <= 2) {
                it->ozi_pos = hash;