Whamcloud - gitweb
LU-1606 idl: remove LASSERT/CLASSERT from lustre_idl.h 82/5682/3
authorAndreas Dilger <adilger@whamcloud.com>
Thu, 22 Nov 2012 21:40:29 +0000 (14:40 -0700)
committerOleg Drokin <oleg.drokin@intel.com>
Thu, 1 Aug 2013 05:54:37 +0000 (05:54 +0000)
Remove the usage of LASSERT() and CLASSERT() from lustre_idl.h, so
that it is usable from userspace programs if needed.  These have
crept in over the years, but are not intended to be there.

The CLASSERT() checks for fid swabbing were largely redundant, and
have been moved to lustre/fid/fid_handler.c.

The fid_is_sane() macro has been modified to remove the check that
f_ver == 0, since this will eventually not be true, and the client
or server should not crash if it sees such a FID during usage.

There are still a few LASSERTs that need to be removed when FID-on-OST
is landed, but I don't want to remove them before that code lands.

There are also uses of CERROR() that could be removed at that time.

Signed-off-by: Andreas Dilger <adilger@whamcloud.com>
Signed-off-by: John L. Hammond <john.hammond@intel.com>
Change-Id: I04901d7713dc31b489685d4639e7bf857decab07
Reviewed-on: http://review.whamcloud.com/5682
Tested-by: Hudson
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Tested-by: Maloo <whamcloud.maloo@gmail.com>
Reviewed-by: Christopher J. Morrone <chris.morrone.llnl@gmail.com>
lustre/fid/fid_handler.c
lustre/include/lustre/lustre_idl.h

index 9dff6eb..becd6da 100644 (file)
@@ -418,14 +418,25 @@ int seq_server_init(struct lu_server_seq *seq,
                    struct seq_server_site *ss,
                    const struct lu_env *env)
 {
-        int rc, is_srv = (type == LUSTRE_SEQ_SERVER);
-        ENTRY;
+       int rc, is_srv = (type == LUSTRE_SEQ_SERVER);
+       ENTRY;
 
-        LASSERT(dev != NULL);
-        LASSERT(prefix != NULL);
+       LASSERT(dev != NULL);
+       LASSERT(prefix != NULL);
        LASSERT(ss != NULL);
        LASSERT(ss->ss_lu != NULL);
 
+       /* A compile-time check for FIDs that used to be in lustre_idl.h
+        * but is moved here to remove CLASSERT/LASSERT in that header.
+        * Check all lu_fid fields are converted in fid_cpu_to_le() and friends
+        * and that there is no padding added by compiler to the struct. */
+       {
+               struct lu_fid tst;
+
+               CLASSERT(sizeof(tst) == sizeof(tst.f_seq) +
+                        sizeof(tst.f_oid) + sizeof(tst.f_ver));
+       }
+
        seq->lss_cli = NULL;
        seq->lss_type = type;
        seq->lss_site = ss;
index 1114c00..d8537f4 100644 (file)
@@ -91,8 +91,8 @@
 #ifndef _LUSTRE_IDL_H_
 #define _LUSTRE_IDL_H_
 
-#if !defined(LASSERT) && !defined(LPU64)
-#include <libcfs/libcfs.h> /* for LASSERT, LPUX64, etc */
+#if !defined(LPU64)
+#include <libcfs/libcfs.h> /* for LPUX64, etc */
 #endif
 
 /* Defn's shared with user-space. */
@@ -231,7 +231,6 @@ static inline unsigned fld_range_is_any(const struct lu_seq_range *range)
 static inline void fld_range_set_type(struct lu_seq_range *range,
                                      unsigned flags)
 {
-       LASSERT(!(flags & ~LU_SEQ_RANGE_MASK));
        range->lsr_flags |= flags;
 }
 
@@ -615,7 +614,6 @@ static inline obd_id fid_idif_id(obd_seq seq, __u32 oid, __u32 ver)
 /* extract ost index from IDIF FID */
 static inline __u32 fid_idif_ost_idx(const struct lu_fid *fid)
 {
-       LASSERT(fid_is_idif(fid));
        return (fid_seq(fid) >> 16) & 0xffff;
 }
 
@@ -833,10 +831,6 @@ static inline void lu_igif_build(struct lu_fid *fid, __u32 ino, __u32 gen)
  */
 static inline void fid_cpu_to_le(struct lu_fid *dst, const struct lu_fid *src)
 {
-       /* check that all fields are converted */
-       CLASSERT(sizeof *src ==
-                sizeof fid_seq(src) +
-                sizeof fid_oid(src) + sizeof fid_ver(src));
        dst->f_seq = cpu_to_le64(fid_seq(src));
        dst->f_oid = cpu_to_le32(fid_oid(src));
        dst->f_ver = cpu_to_le32(fid_ver(src));
@@ -844,10 +838,6 @@ static inline void fid_cpu_to_le(struct lu_fid *dst, const struct lu_fid *src)
 
 static inline void fid_le_to_cpu(struct lu_fid *dst, const struct lu_fid *src)
 {
-       /* check that all fields are converted */
-       CLASSERT(sizeof *src ==
-                sizeof fid_seq(src) +
-                sizeof fid_oid(src) + sizeof fid_ver(src));
        dst->f_seq = le64_to_cpu(fid_seq(src));
        dst->f_oid = le32_to_cpu(fid_oid(src));
        dst->f_ver = le32_to_cpu(fid_ver(src));
@@ -855,10 +845,6 @@ static inline void fid_le_to_cpu(struct lu_fid *dst, const struct lu_fid *src)
 
 static inline void fid_cpu_to_be(struct lu_fid *dst, const struct lu_fid *src)
 {
-       /* check that all fields are converted */
-       CLASSERT(sizeof *src ==
-                sizeof fid_seq(src) +
-                sizeof fid_oid(src) + sizeof fid_ver(src));
        dst->f_seq = cpu_to_be64(fid_seq(src));
        dst->f_oid = cpu_to_be32(fid_oid(src));
        dst->f_ver = cpu_to_be32(fid_ver(src));
@@ -866,10 +852,6 @@ static inline void fid_cpu_to_be(struct lu_fid *dst, const struct lu_fid *src)
 
 static inline void fid_be_to_cpu(struct lu_fid *dst, const struct lu_fid *src)
 {
-       /* check that all fields are converted */
-       CLASSERT(sizeof *src ==
-                sizeof fid_seq(src) +
-                sizeof fid_oid(src) + sizeof fid_ver(src));
        dst->f_seq = be64_to_cpu(fid_seq(src));
        dst->f_oid = be32_to_cpu(fid_oid(src));
        dst->f_ver = be32_to_cpu(fid_ver(src));
@@ -893,9 +875,6 @@ extern void lustre_swab_lu_seq_range(struct lu_seq_range *range);
 
 static inline int lu_fid_eq(const struct lu_fid *f0, const struct lu_fid *f1)
 {
-       /* Check that there is no alignment padding. */
-       CLASSERT(sizeof *f0 ==
-                sizeof f0->f_seq + sizeof f0->f_oid + sizeof f0->f_ver);
        return memcmp(f0, f1, sizeof *f0) == 0;
 }
 
@@ -3314,9 +3293,10 @@ struct obdo {
 #define o_grant_used o_data_version
 
 static inline void lustre_set_wire_obdo(struct obd_connect_data *ocd,
-                                       struct obdo *wobdo, struct obdo *lobdo)
+                                       struct obdo *wobdo,
+                                       const struct obdo *lobdo)
 {
-        memcpy(wobdo, lobdo, sizeof(*lobdo));
+       *wobdo = *lobdo;
        wobdo->o_flags &= ~OBD_FL_LOCAL_MASK;
        if (ocd == NULL)
                return;
@@ -3331,16 +3311,15 @@ static inline void lustre_set_wire_obdo(struct obd_connect_data *ocd,
 }
 
 static inline void lustre_get_wire_obdo(struct obd_connect_data *ocd,
-                                       struct obdo *lobdo, struct obdo *wobdo)
+                                       struct obdo *lobdo,
+                                       const struct obdo *wobdo)
 {
         obd_flag local_flags = 0;
 
         if (lobdo->o_valid & OBD_MD_FLFLAGS)
                  local_flags = lobdo->o_flags & OBD_FL_LOCAL_MASK;
 
-        LASSERT(!(wobdo->o_flags & OBD_FL_LOCAL_MASK));
-
-       memcpy(lobdo, wobdo, sizeof(*lobdo));
+       *lobdo = *wobdo;
        if (local_flags != 0) {
                lobdo->o_valid |= OBD_MD_FLFLAGS;
                lobdo->o_flags &= ~OBD_FL_LOCAL_MASK;