Whamcloud - gitweb
LU-5707 lfsck: store namespace LFSCK statistics info in new EA 21/12321/5
authorFan Yong <fan.yong@intel.com>
Tue, 9 Sep 2014 03:23:04 +0000 (11:23 +0800)
committerOleg Drokin <oleg.drokin@intel.com>
Sun, 23 Nov 2014 06:57:19 +0000 (06:57 +0000)
For Lustre-2.6 or older release, the namespace LFSCK statistics info
was stored as XATTR_NAME_LFSCK_NAMESPACE EA, but in Lustre-2.7, the
namespace LFSCK will introduce more statistics information that will
cause the XATTR_NAME_LFSCK_NAMESPACE EA to be extended. If it still
uses the old XATTR_NAME_LFSCK_NAMESPACE EA, then when downgrade, the
old LFSCK will get -ERANGE when load the new trace file from disk,
and then the LFSCK cannot be started after downgrade.

To avoid such trouble, Lustre-2.7 will use new EA to store the
namespace LFSCK statistics info: XATTR_NAME_LFSCK_NAMESPACE_V2,
and keep a dummy XATTR_NAME_LFSCK_NAMESPACE EA in the trace file
to be compatible with old LFSCK.

Signed-off-by: Fan Yong <fan.yong@intel.com>
Change-Id: I55b5adb962434013b00e3938a67b671010ecc206
Reviewed-on: http://review.whamcloud.com/12321
Tested-by: Jenkins
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Lai Siyao <lai.siyao@intel.com>
lustre/include/lustre/lustre_idl.h
lustre/lfsck/lfsck_namespace.c
lustre/mdt/mdt_xattr.c
lustre/tests/sanity.sh

index 1b9d47d..26da4c3 100644 (file)
@@ -1702,8 +1702,13 @@ static inline void lmm_oi_cpu_to_le(struct ost_id *dst_oi,
 #define XATTR_NAME_VERSION      "trusted.version"
 #define XATTR_NAME_SOM         "trusted.som"
 #define XATTR_NAME_HSM         "trusted.hsm"
-#define XATTR_NAME_LFSCK_NAMESPACE "trusted.lfsck_namespace"
 #define XATTR_NAME_LFSCK_BITMAP "trusted.lfsck_bitmap"
+
+#if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 8, 53, 0)
+# define XATTR_NAME_LFSCK_NAMESPACE_OLD "trusted.lfsck_namespace"
+#endif
+
+#define XATTR_NAME_LFSCK_NAMESPACE "trusted.lfsck_ns"
 #define XATTR_NAME_MAX_LEN     32 /* increase this, if there is longer name. */
 
 struct lov_mds_md_v3 {            /* LOV EA mds/wire data (little-endian) */
index 83d62df..9b67144 100644 (file)
@@ -319,9 +319,19 @@ static int lfsck_namespace_load_bitmap(const struct lu_env *env,
 }
 
 /**
- * \retval +ve: the lfsck_namespace is broken, the caller should reset it.
- * \retval 0: succeed.
- * \retval -ve: failed cases.
+ * Load namespace LFSCK statistics information from the trace file.
+ *
+ * For old release (Lustre-2.6 or older), the statistics information was
+ * stored as XATTR_NAME_LFSCK_NAMESPACE_OLD EA. But in Lustre-2.7, we need
+ * more statistics information. To avoid confusing old MDT when downgrade,
+ * Lustre-2.7 stores the namespace LFSCK statistics information as new
+ * XATTR_NAME_LFSCK_NAMESPACE EA.
+ *
+ * \param[in] env      pointer to the thread context
+ * \param[in] com      pointer to the lfsck component
+ *
+ * \retval             0 for success
+ * \retval             negative error number on failure
  */
 static int lfsck_namespace_load(const struct lu_env *env,
                                struct lfsck_component *com)
@@ -341,7 +351,7 @@ static int lfsck_namespace_load(const struct lu_env *env,
                        CDEBUG(D_LFSCK, "%s: invalid lfsck_namespace magic "
                               "%#x != %#x\n", lfsck_lfsck2name(com->lc_lfsck),
                               ns->ln_magic, LFSCK_NAMESPACE_MAGIC);
-                       rc = 1;
+                       rc = -ESTALE;
                } else {
                        rc = 0;
                }
@@ -350,13 +360,22 @@ static int lfsck_namespace_load(const struct lu_env *env,
                       "expected = %d: rc = %d\n",
                       lfsck_lfsck2name(com->lc_lfsck), len, rc);
                if (rc >= 0)
-                       rc = 1;
+                       rc = -ESTALE;
+       } else {
+               /* Check whether it is old trace file or not.
+                * If yes, it should be reset via returning -ESTALE. */
+               rc = dt_xattr_get(env, com->lc_obj,
+                                 lfsck_buf_get(env, com->lc_file_disk, len),
+                                 XATTR_NAME_LFSCK_NAMESPACE_OLD, BYPASS_CAPA);
+               if (rc >= 0)
+                       rc = -ESTALE;
        }
+
        return rc;
 }
 
 static int lfsck_namespace_store(const struct lu_env *env,
-                                struct lfsck_component *com)
+                                struct lfsck_component *com, bool init)
 {
        struct dt_object                *obj    = com->lc_obj;
        struct lfsck_instance           *lfsck  = com->lc_lfsck;
@@ -367,6 +386,9 @@ static int lfsck_namespace_store(const struct lu_env *env,
        __u32                            nbits  = 0;
        int                              len    = com->lc_file_size;
        int                              rc;
+#if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 8, 53, 0)
+       struct lu_buf            tbuf   = { &len, sizeof(len) };
+#endif
        ENTRY;
 
        if (lad != NULL) {
@@ -398,6 +420,20 @@ static int lfsck_namespace_store(const struct lu_env *env,
                        GOTO(out, rc);
        }
 
+#if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 8, 53, 0)
+       /* To be compatible with old Lustre-2.x MDT (x <= 6), generate dummy
+        * XATTR_NAME_LFSCK_NAMESPACE_OLD EA, then when downgrade to Lustre-2.x,
+        * the old LFSCK will find "invalid" XATTR_NAME_LFSCK_NAMESPACE_OLD EA,
+        * then reset the namespace LFSCK trace file. */
+       if (init) {
+               rc = dt_declare_xattr_set(env, obj, &tbuf,
+                                         XATTR_NAME_LFSCK_NAMESPACE_OLD,
+                                         LU_XATTR_CREATE, handle);
+               if (rc != 0)
+                       GOTO(out, rc);
+       }
+#endif
+
        rc = dt_trans_start_local(env, lfsck->li_bottom, handle);
        if (rc != 0)
                GOTO(out, rc);
@@ -411,6 +447,13 @@ static int lfsck_namespace_store(const struct lu_env *env,
                                  XATTR_NAME_LFSCK_BITMAP, 0, handle,
                                  BYPASS_CAPA);
 
+#if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 8, 53, 0)
+       if (rc == 0 && init)
+               rc = dt_xattr_set(env, obj, &tbuf,
+                                 XATTR_NAME_LFSCK_NAMESPACE_OLD,
+                                 LU_XATTR_CREATE, handle, BYPASS_CAPA);
+#endif
+
        GOTO(out, rc);
 
 out:
@@ -433,7 +476,7 @@ static int lfsck_namespace_init(const struct lu_env *env,
        ns->ln_magic = LFSCK_NAMESPACE_MAGIC;
        ns->ln_status = LS_INIT;
        down_write(&com->lc_sem);
-       rc = lfsck_namespace_store(env, com);
+       rc = lfsck_namespace_store(env, com, true);
        up_write(&com->lc_sem);
        return rc;
 }
@@ -3731,7 +3774,7 @@ static int lfsck_namespace_reset(const struct lu_env *env,
        lad->lad_incomplete = 0;
        CFS_RESET_BITMAP(lad->lad_bitmap);
 
-       rc = lfsck_namespace_store(env, com);
+       rc = lfsck_namespace_store(env, com, true);
 
        GOTO(out, rc);
 
@@ -3868,7 +3911,7 @@ static int lfsck_namespace_checkpoint(const struct lu_env *env,
                com->lc_new_checked = 0;
        }
 
-       rc = lfsck_namespace_store(env, com);
+       rc = lfsck_namespace_store(env, com, false);
        up_write(&com->lc_sem);
 
 log:
@@ -4188,7 +4231,7 @@ static int lfsck_namespace_post(const struct lu_env *env,
                com->lc_new_checked = 0;
        }
 
-       rc = lfsck_namespace_store(env, com);
+       rc = lfsck_namespace_store(env, com, false);
        up_write(&com->lc_sem);
 
        CDEBUG(D_LFSCK, "%s: namespace LFSCK post done: rc = %d\n",
@@ -5966,7 +6009,7 @@ checkpoint:
                        ns->ln_time_last_checkpoint = cfs_time_current_sec();
                        ns->ln_objs_checked_phase2 += com->lc_new_checked;
                        com->lc_new_checked = 0;
-                       rc = lfsck_namespace_store(env, com);
+                       rc = lfsck_namespace_store(env, com, false);
                        up_write(&com->lc_sem);
                        if (rc != 0)
                                GOTO(put, rc);
@@ -6048,7 +6091,7 @@ static int lfsck_namespace_double_scan_result(const struct lu_env *env,
                ns->ln_status = LS_FAILED;
        }
 
-       rc = lfsck_namespace_store(env, com);
+       rc = lfsck_namespace_store(env, com, false);
        up_write(&com->lc_sem);
 
        return rc;
@@ -6499,10 +6542,10 @@ int lfsck_namespace_setup(const struct lu_env *env,
                GOTO(out, rc);
 
        rc = lfsck_namespace_load(env, com);
-       if (rc > 0)
-               rc = lfsck_namespace_reset(env, com, true);
-       else if (rc == -ENODATA)
+       if (rc == -ENODATA)
                rc = lfsck_namespace_init(env, com);
+       else if (rc < 0)
+               rc = lfsck_namespace_reset(env, com, true);
        if (rc != 0)
                GOTO(out, rc);
 
index 480377a..8364fab 100644 (file)
@@ -423,6 +423,11 @@ int mdt_reint_setxattr(struct mdt_thread_info *info,
                    strcmp(xattr_name, XATTR_NAME_HSM) == 0 ||
                    strcmp(xattr_name, XATTR_NAME_LFSCK_NAMESPACE) == 0)
                        GOTO(out, rc = 0);
+
+#if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 8, 53, 0)
+               if (strcmp(xattr_name, XATTR_NAME_LFSCK_NAMESPACE_OLD) == 0)
+                       GOTO(out, rc = 0);
+#endif
        } else if ((valid & OBD_MD_FLXATTR) &&
                   (strcmp(xattr_name, XATTR_NAME_ACL_ACCESS) == 0 ||
                    strcmp(xattr_name, XATTR_NAME_ACL_DEFAULT) == 0)) {
index 238e756..64d952b 100644 (file)
@@ -6799,6 +6799,27 @@ test_102n() { # LU-4101 mdt: protect internal xattrs
                setfattr --remove=$trusted.$name $file1 2> /dev/null
        done
 
+       if [ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.6.50) ]
+       then
+               name="lfsck_ns"
+               # Try to copy xattr from $file0 to $file1.
+               value=$(getxattr $file0 trusted.$name 2> /dev/null)
+
+               setfattr --name=trusted.$name --value="$value" $file1 ||
+                       error "setxattr 'trusted.$name' failed"
+
+               # Try to set a garbage xattr.
+               value=0sVGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIGl0c2VsZi4=
+
+               setfattr --name=trusted.$name --value="$value" $file1 ||
+                       error "setxattr 'trusted.$name' failed"
+
+               # Try to remove the xattr from $file1. We don't care if this
+               # appears to succeed or fail, we just don't want there to be
+               # any changes or crashes.
+               setfattr --remove=$trusted.$name $file1 2> /dev/null
+       fi
+
        # Get 'after' xattrs of file1.
        getfattr --absolute-names --dump --match=- $file1 > $xattr1