Whamcloud - gitweb
LU-6401 uapi: fix up lustre_ostid.h and lustre_fid.h 69/24569/7
authorJames Simmons <uja.ornl@yahoo.com>
Sat, 8 Apr 2017 21:38:42 +0000 (17:38 -0400)
committerOleg Drokin <oleg.drokin@intel.com>
Mon, 1 May 2017 17:48:53 +0000 (17:48 +0000)
Several inline functions in the header lustre_ostid.h
are using debug macros instead of returning proper errors.
Remove the debug macros and properly handle the returned
error codes. Place both UAPI headers lustre_fid.h and
lustre_ostid.h into the uapi directory.

Change-Id: Ic32afd05850b5bf02fb8de655cb1971eeb52a321
Signed-off-by: James Simmons <uja.ornl@yahoo.com>
Reviewed-on: https://review.whamcloud.com/24569
Reviewed-by: Fan Yong <fan.yong@intel.com>
Reviewed-by: Mike Pershin <mike.pershin@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
Tested-by: Oleg Drokin <oleg.drokin@intel.com>
24 files changed:
lustre/include/lustre/Makefile.am
lustre/include/lustre_fid.h
lustre/include/lustre_log_user.h
lustre/include/uapi/linux/Makefile.am
lustre/include/uapi/linux/lustre_fid.h [moved from lustre/include/lustre/lustre_fid.h with 83% similarity]
lustre/include/uapi/linux/lustre_ostid.h [moved from lustre/include/lustre/lustre_ostid.h with 79% similarity]
lustre/lfsck/lfsck_layout.c
lustre/obdclass/llog_internal.h
lustre/obdclass/llog_ioctl.c
lustre/obdecho/echo.c
lustre/obdecho/echo_client.c
lustre/ofd/ofd_dev.c
lustre/ofd/ofd_fs.c
lustre/ofd/ofd_obd.c
lustre/osc/osc_object.c
lustre/osd-ldiskfs/osd_handler.c
lustre/osp/osp_object.c
lustre/osp/osp_precreate.c
lustre/osp/osp_sync.c
lustre/utils/lhsmtool_posix.c
lustre/utils/liblustreapi.c
lustre/utils/ll_decode_linkea.c
lustre/utils/llog_reader.c
lustre/utils/obd.c

index 138960a..79d55a1 100644 (file)
@@ -41,10 +41,8 @@ EXTRA_DIST = libiam.h \
        liblustreapi.h \
        ll_fiemap.h \
        lustre_errno.h \
-       lustre_fid.h \
        lustre_idl.h \
        lustre_lfsck_user.h \
-       lustre_ostid.h \
        lustre_user.h \
        lustreapi.h \
        lustre_barrier_user.h
index 824eb82..26acbde 100644 (file)
  */
 
 #include <libcfs/libcfs.h>
-#include <lustre/lustre_fid.h>
+#include <uapi/linux/lustre_fid.h>
 #include <lustre/lustre_idl.h>
-#include <lustre/lustre_ostid.h>
+#include <uapi/linux/lustre_ostid.h>
 
 struct lu_env;
 struct lu_site;
@@ -325,6 +325,53 @@ static inline int fid_seq_in_fldb(__u64 seq)
               fid_seq_is_root(seq) || fid_seq_is_dot(seq);
 }
 
+static inline void ost_layout_cpu_to_le(struct ost_layout *dst,
+                                       const struct ost_layout *src)
+{
+       dst->ol_stripe_size = __cpu_to_le32(src->ol_stripe_size);
+       dst->ol_stripe_count = __cpu_to_le32(src->ol_stripe_count);
+       dst->ol_comp_start = __cpu_to_le64(src->ol_comp_start);
+       dst->ol_comp_end = __cpu_to_le64(src->ol_comp_end);
+       dst->ol_comp_id = __cpu_to_le32(src->ol_comp_id);
+}
+
+static inline void ost_layout_le_to_cpu(struct ost_layout *dst,
+                                       const struct ost_layout *src)
+{
+       dst->ol_stripe_size = __le32_to_cpu(src->ol_stripe_size);
+       dst->ol_stripe_count = __le32_to_cpu(src->ol_stripe_count);
+       dst->ol_comp_start = __le64_to_cpu(src->ol_comp_start);
+       dst->ol_comp_end = __le64_to_cpu(src->ol_comp_end);
+       dst->ol_comp_id = __le32_to_cpu(src->ol_comp_id);
+}
+
+/* Both filter_fid_*cpu* functions not currently used */
+static inline void filter_fid_cpu_to_le(struct filter_fid *dst,
+                                       const struct filter_fid *src, int size)
+{
+       fid_cpu_to_le(&dst->ff_parent, &src->ff_parent);
+
+       if (size < sizeof(struct filter_fid))
+               memset(&dst->ff_layout, 0, sizeof(dst->ff_layout));
+       else
+               ost_layout_cpu_to_le(&dst->ff_layout, &src->ff_layout);
+
+       /* XXX: Add more if filter_fid is enlarged in the future. */
+}
+
+static inline void filter_fid_le_to_cpu(struct filter_fid *dst,
+                                       const struct filter_fid *src, int size)
+{
+       fid_le_to_cpu(&dst->ff_parent, &src->ff_parent);
+
+       if (size < sizeof(struct filter_fid))
+               memset(&dst->ff_layout, 0, sizeof(dst->ff_layout));
+       else
+               ost_layout_le_to_cpu(&dst->ff_layout, &src->ff_layout);
+
+       /* XXX: Add more if filter_fid is enlarged in the future. */
+}
+
 static inline void lu_last_id_fid(struct lu_fid *fid, __u64 seq, __u32 ost_idx)
 {
        if (fid_seq_is_mdt0(seq)) {
@@ -658,6 +705,50 @@ static inline bool ostid_res_name_eq(const struct ost_id *oi,
        }
 }
 
+/**
+ * Note: we need check oi_seq to decide where to set oi_id,
+ * so oi_seq should always be set ahead of oi_id.
+ */
+static inline int ostid_set_id(struct ost_id *oi, __u64 oid)
+{
+       if (fid_seq_is_mdt0(oi->oi.oi_seq)) {
+               if (oid >= IDIF_MAX_OID)
+                       return -E2BIG;
+               oi->oi.oi_id = oid;
+       } else if (fid_is_idif(&oi->oi_fid)) {
+               if (oid >= IDIF_MAX_OID)
+                       return -E2BIG;
+               oi->oi_fid.f_seq = fid_idif_seq(oid,
+                                               fid_idif_ost_idx(&oi->oi_fid));
+               oi->oi_fid.f_oid = oid;
+               oi->oi_fid.f_ver = oid >> 48;
+       } else {
+               if (oid >= OBIF_MAX_OID)
+                       return -E2BIG;
+               oi->oi_fid.f_oid = oid;
+       }
+       return 0;
+}
+
+/* pack any OST FID into an ostid (id/seq) for the wire/disk */
+static inline int fid_to_ostid(const struct lu_fid *fid, struct ost_id *ostid)
+{
+       int rc = 0;
+
+       if (fid_seq_is_igif(fid->f_seq))
+               return -EBADF;
+
+       if (fid_is_idif(fid)) {
+               ostid_set_seq_mdt0(ostid);
+               rc = ostid_set_id(ostid, fid_idif_id(fid_seq(fid),
+                                 fid_oid(fid), fid_ver(fid)));
+       } else {
+               ostid->oi_fid = *fid;
+       }
+
+       return rc;
+}
+
 /* The same as osc_build_res_name() */
 static inline void ost_fid_build_resid(const struct lu_fid *fid,
                                       struct ldlm_res_id *resname)
@@ -680,8 +771,12 @@ static inline void ost_fid_from_resid(struct lu_fid *fid,
        if (fid_seq_is_mdt0(name->name[LUSTRE_RES_ID_VER_OID_OFF])) {
                /* old resid */
                struct ost_id oi;
+
                ostid_set_seq(&oi, name->name[LUSTRE_RES_ID_VER_OID_OFF]);
-               ostid_set_id(&oi, name->name[LUSTRE_RES_ID_SEQ_OFF]);
+               if (ostid_set_id(&oi, name->name[LUSTRE_RES_ID_SEQ_OFF])) {
+                       CERROR("Bad %llu to set " DOSTID "\n",
+                              name->name[LUSTRE_RES_ID_SEQ_OFF], POSTID(&oi));
+               }
                ostid_to_fid(fid, &oi, ost_idx);
        } else {
                /* new resid */
index b28fd26..ee5f0f7 100644 (file)
@@ -38,7 +38,7 @@
 #ifndef _LUSTRE_LOG_USER_H
 #define _LUSTRE_LOG_USER_H
 
-#include <lustre/lustre_fid.h>
+#include <uapi/linux/lustre_fid.h>
 
 /*  Lustre logs use FIDs constructed from oi_id and oi_seq directly,
  *  without attempting to use the IGIF and IDIF ranges as is done
index 09d3349..b07e08a 100644 (file)
@@ -31,4 +31,6 @@
 
 EXTRA_DIST = \
        lustre_disk.h \
-       lustre_ioctl.h
+       lustre_fid.h \
+       lustre_ioctl.h \
+       lustre_ostid.h
similarity index 83%
rename from lustre/include/lustre/lustre_fid.h
rename to lustre/include/uapi/linux/lustre_fid.h
index 2a2ff97..608f733 100644 (file)
@@ -34,8 +34,8 @@
  * of three parts: sequence, Object ID, and version.
  *
  */
-#ifndef _LUSTRE_LUSTRE_FID_H_
-#define _LUSTRE_LUSTRE_FID_H_
+#ifndef _UAPI_LUSTRE_FID_H_
+#define _UAPI_LUSTRE_FID_H_
 
 #include <lustre/lustre_idl.h>
 
@@ -324,52 +324,6 @@ static inline void fid_be_to_cpu(struct lu_fid *dst, const struct lu_fid *src)
        dst->f_ver = __be32_to_cpu(fid_ver(src));
 }
 
-static inline void ost_layout_cpu_to_le(struct ost_layout *dst,
-                                       const struct ost_layout *src)
-{
-       dst->ol_stripe_size = __cpu_to_le32(src->ol_stripe_size);
-       dst->ol_stripe_count = __cpu_to_le32(src->ol_stripe_count);
-       dst->ol_comp_start = __cpu_to_le64(src->ol_comp_start);
-       dst->ol_comp_end = __cpu_to_le64(src->ol_comp_end);
-       dst->ol_comp_id = __cpu_to_le32(src->ol_comp_id);
-}
-
-static inline void ost_layout_le_to_cpu(struct ost_layout *dst,
-                                       const struct ost_layout *src)
-{
-       dst->ol_stripe_size = __le32_to_cpu(src->ol_stripe_size);
-       dst->ol_stripe_count = __le32_to_cpu(src->ol_stripe_count);
-       dst->ol_comp_start = __le64_to_cpu(src->ol_comp_start);
-       dst->ol_comp_end = __le64_to_cpu(src->ol_comp_end);
-       dst->ol_comp_id = __le32_to_cpu(src->ol_comp_id);
-}
-
-static inline void filter_fid_cpu_to_le(struct filter_fid *dst,
-                                       const struct filter_fid *src, int size)
-{
-       fid_cpu_to_le(&dst->ff_parent, &src->ff_parent);
-
-       if (size < sizeof(struct filter_fid))
-               memset(&dst->ff_layout, 0, sizeof(dst->ff_layout));
-       else
-               ost_layout_cpu_to_le(&dst->ff_layout, &src->ff_layout);
-
-       /* XXX: Add more if filter_fid is enlarged in the future. */
-}
-
-static inline void filter_fid_le_to_cpu(struct filter_fid *dst,
-                                       const struct filter_fid *src, int size)
-{
-       fid_le_to_cpu(&dst->ff_parent, &src->ff_parent);
-
-       if (size < sizeof(struct filter_fid))
-               memset(&dst->ff_layout, 0, sizeof(dst->ff_layout));
-       else
-               ost_layout_le_to_cpu(&dst->ff_layout, &src->ff_layout);
-
-       /* XXX: Add more if filter_fid is enlarged in the future. */
-}
-
 static inline bool fid_is_sane(const struct lu_fid *fid)
 {
        return fid && ((fid_seq(fid) >= FID_SEQ_START && !fid_ver(fid)) ||
similarity index 79%
rename from lustre/include/lustre/lustre_ostid.h
rename to lustre/include/uapi/linux/lustre_ostid.h
index 9652987..c0e662a 100644 (file)
  * Define ost_id  associated functions
  */
 
-#ifndef _LUSTRE_OSTID_H_
-#define _LUSTRE_OSTID_H_
+#ifndef _UAPI_LUSTRE_OSTID_H_
+#define _UAPI_LUSTRE_OSTID_H_
 
-#include <libcfs/libcfs.h>
-#include <lustre/lustre_fid.h>
+/*
+ * This is due to us being out of kernel and the way the OpenSFS branch
+ * handles CFLAGS. Upstream will just have linux/lustre_fid.h
+ */
+#ifdef __KERNEL__
+#include <uapi/linux/lustre_fid.h>
+#else
+#include <linux/lustre_fid.h>
+#endif
 
 static inline __u64 lmm_oi_id(const struct ost_id *oi)
 {
@@ -133,39 +140,6 @@ static inline void ostid_set_seq_llog(struct ost_id *oi)
        ostid_set_seq(oi, FID_SEQ_LLOG);
 }
 
-/**
- * Note: we need check oi_seq to decide where to set oi_id,
- * so oi_seq should always be set ahead of oi_id.
- */
-static inline void ostid_set_id(struct ost_id *oi, __u64 oid)
-{
-       if (fid_seq_is_mdt0(oi->oi.oi_seq)) {
-               if (oid >= IDIF_MAX_OID) {
-                       CERROR("Bad %llu to set "DOSTID"\n",
-                               (unsigned long long)oid, POSTID(oi));
-                       return;
-               }
-               oi->oi.oi_id = oid;
-       } else if (fid_is_idif(&oi->oi_fid)) {
-               if (oid >= IDIF_MAX_OID) {
-                       CERROR("Bad %llu to set "DOSTID"\n",
-                               (unsigned long long)oid, POSTID(oi));
-                       return;
-               }
-               oi->oi_fid.f_seq = fid_idif_seq(oid,
-                                               fid_idif_ost_idx(&oi->oi_fid));
-               oi->oi_fid.f_oid = oid;
-               oi->oi_fid.f_ver = oid >> 48;
-       } else {
-               if (oid > OBIF_MAX_OID) {
-                       CERROR("Bad %llu to set "DOSTID"\n",
-                               (unsigned long long)oid, POSTID(oi));
-                       return;
-               }
-               oi->oi_fid.f_oid = oid;
-       }
-}
-
 static inline void ostid_cpu_to_le(const struct ost_id *src_oi,
                                   struct ost_id *dst_oi)
 {
@@ -188,25 +162,6 @@ static inline void ostid_le_to_cpu(const struct ost_id *src_oi,
        }
 }
 
-/* pack any OST FID into an ostid (id/seq) for the wire/disk */
-static inline int fid_to_ostid(const struct lu_fid *fid, struct ost_id *ostid)
-{
-       if (fid_seq_is_igif(fid->f_seq)) {
-               CERROR("bad IGIF, "DFID"\n", PFID(fid));
-               return -EBADF;
-       }
-
-       if (fid_is_idif(fid)) {
-               ostid_set_seq_mdt0(ostid);
-               ostid_set_id(ostid, fid_idif_id(fid_seq(fid), fid_oid(fid),
-                                               fid_ver(fid)));
-       } else {
-               ostid->oi_fid = *fid;
-       }
-
-       return 0;
-}
-
 /**
  * Sigh, because pre-2.4 uses
  * struct lov_mds_md_v1 {
@@ -251,11 +206,8 @@ static inline int ostid_to_fid(struct lu_fid *fid, const struct ost_id *ostid,
 {
        __u64 seq = ostid_seq(ostid);
 
-       if (ost_idx > 0xffff) {
-               CERROR("bad ost_idx, "DOSTID" ost_idx:%u\n", POSTID(ostid),
-                      ost_idx);
+       if (ost_idx > 0xffff)
                return -EBADF;
-       }
 
        if (fid_seq_is_mdt0(seq)) {
                __u64 oid = ostid_id(ostid);
@@ -266,11 +218,9 @@ static inline int ostid_to_fid(struct lu_fid *fid, const struct ost_id *ostid,
                 * been in production for years.  This can handle create rates
                 * of 1M objects/s/OST for 9 years, or combinations thereof.
                 */
-               if (oid >= IDIF_MAX_OID) {
-                       CERROR("bad MDT0 id(1), "DOSTID" ost_idx:%u\n",
-                              POSTID(ostid), ost_idx);
+               if (oid >= IDIF_MAX_OID)
                        return -EBADF;
-               }
+
                fid->f_seq = fid_idif_seq(oid, ost_idx);
                /* truncate to 32 bits by assignment */
                fid->f_oid = oid;
@@ -282,14 +232,12 @@ static inline int ostid_to_fid(struct lu_fid *fid, const struct ost_id *ostid,
                 * maps legacy OST objects into the FID namespace.  In both
                 * cases, we just pass the FID through, no conversion needed.
                 */
-               if (ostid->oi_fid.f_ver) {
-                       CERROR("bad MDT0 id(2), "DOSTID" ost_idx:%u\n",
-                              POSTID(ostid), ost_idx);
+               if (ostid->oi_fid.f_ver)
                        return -EBADF;
-               }
+
                *fid = ostid->oi_fid;
        }
 
        return 0;
 }
-#endif
+#endif /* _UAPI_LUSTRE_OSTID_H_ */
index dee7c1f..bdda625 100644 (file)
@@ -3116,7 +3116,10 @@ static int lfsck_layout_scan_orphan(const struct lu_env *env,
        }
 
        ostid_set_seq(oi, FID_SEQ_IDIF);
-       ostid_set_id(oi, 0);
+       rc = ostid_set_id(oi, 0);
+       if (rc)
+               GOTO(log, rc);
+
        rc = ostid_to_fid(fid, oi, ltd->ltd_index);
        if (rc != 0)
                GOTO(log, rc);
index 65752a0..eb9526a 100644 (file)
@@ -71,14 +71,6 @@ static inline struct llog_thread_info *llog_info(const struct lu_env *env)
        return lgi;
 }
 
-static inline void
-lustre_build_llog_lvfs_oid(struct llog_logid *logid, __u64 ino, __u32 gen)
-{
-       ostid_set_seq_llog(&logid->lgl_oi);
-       ostid_set_id(&logid->lgl_oi, ino);
-       logid->lgl_ogen = gen;
-}
-
 int llog_info_init(void);
 void llog_info_fini(void);
 
index 09934e7..906e6e6 100644 (file)
@@ -88,7 +88,8 @@ static int str2logid(struct llog_logid *logid, char *str, int len)
                 RETURN(-EINVAL);
 
        ostid_set_seq(&logid->lgl_oi, seq);
-       ostid_set_id(&logid->lgl_oi, id);
+       if (ostid_set_id(&logid->lgl_oi, id))
+               RETURN(-EINVAL);
 
        start = ++end;
         if (start - str >= len - 1)
index 5d60b18..de7fd77 100644 (file)
@@ -137,7 +137,11 @@ static int echo_create(const struct lu_env *env, struct obd_export *exp,
         }
 
        ostid_set_seq_echo(&oa->o_oi);
-       ostid_set_id(&oa->o_oi, echo_next_id(obd));
+       if (ostid_set_id(&oa->o_oi, echo_next_id(obd))) {
+               CERROR("Bad %llu to set " DOSTID "\n",
+                      echo_next_id(obd), POSTID(&oa->o_oi));
+               return -EINVAL;
+       }
        oa->o_valid = OBD_MD_FLID;
 
        return 0;
@@ -189,7 +193,11 @@ static int echo_getattr(const struct lu_env *env, struct obd_export *exp,
 
        obdo_cpy_md(oa, &obd->u.echo.eo_oa, oa->o_valid);
        ostid_set_seq_echo(&oa->o_oi);
-       ostid_set_id(&oa->o_oi, id);
+       if (ostid_set_id(&oa->o_oi, id)) {
+               CERROR("Bad %llu to set " DOSTID "\n",
+                      id, POSTID(&oa->o_oi));
+               RETURN(-EINVAL);
+       }
 
        RETURN(0);
 }
index 9f383f8..9abea3c 100644 (file)
@@ -2176,8 +2176,11 @@ static int echo_create_object(const struct lu_env *env, struct echo_device *ed,
                RETURN(-EINVAL);
        }
 
-       if (ostid_id(&oa->o_oi) == 0)
-               ostid_set_id(&oa->o_oi, ++last_object_id);
+       if (ostid_id(&oa->o_oi) == 0) {
+               rc = ostid_set_id(&oa->o_oi, ++last_object_id);
+               if (rc)
+                       GOTO(failed, rc);
+       }
 
        rc = obd_create(env, ec->ec_exp, oa);
        if (rc != 0) {
index c654a30..96d5de9 100644 (file)
@@ -1526,8 +1526,7 @@ done:
                rc = ofd_seq_last_oid_write(env, ofd, oseq);
        } else {
                /* don't reuse orphan object, return last used objid */
-               ostid_set_id(oi, last);
-               rc = 0;
+               rc = ostid_set_id(oi, last);
        }
 
        GOTO(out_put, rc);
@@ -1624,16 +1623,17 @@ static int ofd_create_hdl(struct tgt_session_info *tsi)
                if (!oseq->os_destroys_in_progress) {
                        CERROR("%s:[%llu] destroys_in_progress already"
                               " cleared\n", ofd_name(ofd), seq);
-                       ostid_set_id(&rep_oa->o_oi, ofd_seq_last_oid(oseq));
-                       GOTO(out, rc = 0);
+                       rc = ostid_set_id(&rep_oa->o_oi,
+                                         ofd_seq_last_oid(oseq));
+                       GOTO(out, rc);
                }
                diff = oid - ofd_seq_last_oid(oseq);
                CDEBUG(D_HA, "ofd_last_id() = %llu -> diff = %d\n",
                        ofd_seq_last_oid(oseq), diff);
                if (-diff > OST_MAX_PRECREATE) {
                        /* Let MDS know that we are so far ahead. */
-                       ostid_set_id(&rep_oa->o_oi, ofd_seq_last_oid(oseq) + 1);
-                       rc = 0;
+                       rc = ostid_set_id(&rep_oa->o_oi,
+                                         ofd_seq_last_oid(oseq) + 1);
                } else if (diff < 0) {
                        rc = ofd_orphans_destroy(tsi->tsi_env, exp,
                                                 ofd, rep_oa);
@@ -1781,7 +1781,7 @@ static int ofd_create_hdl(struct tgt_session_info *tsi)
                        granted = 0;
                }
 
-               ostid_set_id(&rep_oa->o_oi, ofd_seq_last_oid(oseq));
+               rc = ostid_set_id(&rep_oa->o_oi, ofd_seq_last_oid(oseq));
        }
        EXIT;
        ofd_counter_incr(exp, LPROC_OFD_STATS_CREATE,
index 25e59c2..0523077 100644 (file)
@@ -181,8 +181,12 @@ u64 ofd_seq_last_oid(struct ofd_seq *oseq)
 void ofd_seq_last_oid_set(struct ofd_seq *oseq, u64 id)
 {
        spin_lock(&oseq->os_last_oid_lock);
-       if (likely(ostid_id(&oseq->os_oi) < id))
-               ostid_set_id(&oseq->os_oi, id);
+       if (likely(ostid_id(&oseq->os_oi) < id)) {
+               if (ostid_set_id(&oseq->os_oi, id)) {
+                       CERROR("Bad %llu to set " DOSTID "\n",
+                              (unsigned long long)id, POSTID(&oseq->os_oi));
+               }
+       }
        spin_unlock(&oseq->os_last_oid_lock);
 }
 
index 5e35d8a..33d6b4f 100644 (file)
@@ -1062,9 +1062,14 @@ static int ofd_echo_create(const struct lu_env *env, struct obd_export *exp,
                CERROR("%s: unable to precreate: rc = %d\n",
                       ofd_name(ofd), rc);
        } else {
-               ostid_set_id(&oa->o_oi, ofd_seq_last_oid(oseq));
+               rc = ostid_set_id(&oa->o_oi, ofd_seq_last_oid(oseq));
+               if (rc) {
+                       CERROR("%s: Bad %llu to set " DOSTID " : rc %d\n",
+                              ofd_name(ofd),
+                              (unsigned long long)ofd_seq_last_oid(oseq),
+                              POSTID(&oa->o_oi), rc);
+               }
                oa->o_valid |= OBD_MD_FLID | OBD_MD_FLGROUP;
-               rc = 0;
        }
 
        tgt_grant_commit(ofd_obd(ofd)->obd_self_export, granted, rc);
@@ -1167,7 +1172,9 @@ static int ofd_ioc_get_obj_version(const struct lu_env *env,
                struct ost_id ostid;
 
                ostid_set_seq(&ostid, *(__u64 *)data->ioc_inlbuf4);
-               ostid_set_id(&ostid, *(__u64 *)data->ioc_inlbuf3);
+               rc = ostid_set_id(&ostid, *(__u64 *)data->ioc_inlbuf3);
+               if (rc)
+                       GOTO(out, rc);
                rc = ostid_to_fid(&fid, &ostid,
                                  ofd->ofd_lut.lut_lsd.lsd_osd_index);
                if (rc != 0)
index 502cfef..7c486dd 100644 (file)
@@ -375,7 +375,14 @@ static void osc_req_attr_set(const struct lu_env *env, struct cl_object *obj,
                oa->o_valid |= OBD_MD_FLGROUP;
        }
        if (flags & OBD_MD_FLID) {
-               ostid_set_id(&oa->o_oi, ostid_id(&oinfo->loi_oi));
+               int rc;
+
+               rc = ostid_set_id(&oa->o_oi, ostid_id(&oinfo->loi_oi));
+               if (rc) {
+                       CERROR("Bad %llu to set " DOSTID " : rc %d\n",
+                              (unsigned long long)ostid_id(&oinfo->loi_oi),
+                              POSTID(&oa->o_oi), rc);
+               }
                oa->o_valid |= OBD_MD_FLID;
        }
        if (flags & OBD_MD_FLHANDLE) {
index 50acaa4..dd682f5 100644 (file)
@@ -674,10 +674,13 @@ int osd_get_idif(struct osd_thread_info *info, struct inode *inode,
        if (rc == sizeof(*ff)) {
                rc = 0;
                ostid_set_seq(ostid, le64_to_cpu(ff->ff_seq));
-               ostid_set_id(ostid, le64_to_cpu(ff->ff_objid));
-               /* XXX: use 0 as the index for compatibility, the caller will
-                *      handle index related issues when necessarry. */
-               ostid_to_fid(fid, ostid, 0);
+               rc = ostid_set_id(ostid, le64_to_cpu(ff->ff_objid));
+               /*
+                * XXX: use 0 as the index for compatibility, the caller will
+                *      handle index related issues when necessary.
+                */
+               if (!rc)
+                       ostid_to_fid(fid, ostid, 0);
        } else if (rc == sizeof(struct filter_fid)) {
                rc = 1;
        } else if (rc >= 0) {
index 3e3b005..5b3d5a9 100644 (file)
@@ -1479,8 +1479,12 @@ static int osp_object_create(const struct lu_env *env, struct dt_object *dt,
                if (d->opd_gap_count > 0) {
                        int count = d->opd_gap_count;
 
-                       ostid_set_id(&osi->osi_oi,
-                                    fid_oid(&d->opd_gap_start_fid));
+                       rc = ostid_set_id(&osi->osi_oi,
+                                         fid_oid(&d->opd_gap_start_fid));
+                       if (rc) {
+                               spin_unlock(&d->opd_pre_lock);
+                               RETURN(rc);
+                       }
                        d->opd_gap_count = 0;
                        spin_unlock(&d->opd_pre_lock);
 
index c85b837..a89c9f5 100644 (file)
@@ -494,16 +494,17 @@ static int osp_precreate_fids(const struct lu_env *env, struct osp_device *osp,
        if (fid_is_idif(fid)) {
                struct lu_fid   *last_fid;
                struct ost_id   *oi = &osi->osi_oi;
+               int rc;
 
                spin_lock(&osp->opd_pre_lock);
                last_fid = &osp->opd_pre_last_created_fid;
                fid_to_ostid(last_fid, oi);
                end = min(ostid_id(oi) + *grow, IDIF_MAX_OID);
                *grow = end - ostid_id(oi);
-               ostid_set_id(oi, ostid_id(oi) + *grow);
+               rc = ostid_set_id(oi, ostid_id(oi) + *grow);
                spin_unlock(&osp->opd_pre_lock);
 
-               if (*grow == 0)
+               if (*grow == 0 || rc)
                        return 1;
 
                ostid_to_fid(fid, oi, osp->opd_index);
index 9887c30..ef3cc25 100644 (file)
@@ -146,9 +146,17 @@ static inline int osp_sync_inflight_conflict(struct osp_device *d,
 
        memset(&ostid, 0, sizeof(ostid));
        switch (h->lrh_type) {
-       case MDS_UNLINK_REC:
-               ostid_set_seq(&ostid, ((struct llog_unlink_rec *)h)->lur_oseq);
-               ostid_set_id(&ostid, ((struct llog_unlink_rec *)h)->lur_oid);
+       case MDS_UNLINK_REC: {
+               struct llog_unlink_rec *unlink = (struct llog_unlink_rec *)h;
+
+               ostid_set_seq(&ostid, unlink->lur_oseq);
+               if (ostid_set_id(&ostid, unlink->lur_oid)) {
+                       CERROR("Bad %llu to set " DOSTID "\n",
+                              (unsigned long long)(unlink->lur_oid),
+                              POSTID(&ostid));
+                       return 1;
+               }
+               }
                break;
        case MDS_UNLINK64_REC:
                fid_to_ostid(&((struct llog_unlink64_rec *)h)->lur_fid, &ostid);
@@ -775,6 +783,7 @@ static int osp_sync_new_unlink_job(struct osp_device *d,
        struct llog_unlink_rec  *rec = (struct llog_unlink_rec *)h;
        struct ptlrpc_request   *req;
        struct ost_body         *body;
+       int rc;
 
        ENTRY;
        LASSERT(h->lrh_type == MDS_UNLINK_REC);
@@ -786,7 +795,9 @@ static int osp_sync_new_unlink_job(struct osp_device *d,
        body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
        LASSERT(body);
        ostid_set_seq(&body->oa.o_oi, rec->lur_oseq);
-       ostid_set_id(&body->oa.o_oi, rec->lur_oid);
+       rc = ostid_set_id(&body->oa.o_oi, rec->lur_oid);
+       if (rc)
+               return rc;
        body->oa.o_misc = rec->lur_count;
        body->oa.o_valid = OBD_MD_FLGROUP | OBD_MD_FLID;
        if (rec->lur_count)
index fa9f009..0cb1c4e 100644 (file)
@@ -57,7 +57,7 @@
 #include <sys/types.h>
 
 #include <libcfs/util/string.h>
-#include <lustre/lustre_fid.h>
+#include <linux/lustre_fid.h>
 #include <lustre/lustreapi.h>
 
 /* Progress reporting period */
index 6764367..22a312b 100644 (file)
@@ -73,7 +73,7 @@
 #include <libcfs/util/string.h>
 #include <lnet/lnetctl.h>
 #include <lustre/lustreapi.h>
-#include <lustre/lustre_ostid.h>
+#include <linux/lustre_ostid.h>
 #include <linux/lustre_ioctl.h>
 #include "lustreapi_internal.h"
 
index 01ae43e..0e3f863 100644 (file)
@@ -38,7 +38,7 @@
 #include <limits.h>
 #include <sys/types.h>
 #include <sys/xattr.h>
-#include <lustre/lustre_fid.h>
+#include <linux/lustre_fid.h>
 
 #define BUFFER_SIZE 65536
 
index 7bd821e..949fed0 100644 (file)
@@ -53,8 +53,8 @@
 #include <errno.h>
 #include <time.h>
 #include <lnet/nidstr.h>
-#include <lustre/lustre_fid.h>
-#include <lustre/lustre_ostid.h>
+#include <linux/lustre_fid.h>
+#include <linux/lustre_ostid.h>
 #include <lustre/lustreapi.h>
 #include <lustre_log_user.h>
 #include <lustre_cfg.h>
index b3b6a14..08047e5 100644 (file)
@@ -68,7 +68,7 @@
 #include <libcfs/util/string.h>
 
 #include <lnet/nidstr.h>
-#include <lustre/lustre_ostid.h>
+#include <linux/lustre_ostid.h>
 #include <lustre_cfg.h>
 #include <linux/lustre_ioctl.h>
 #include <lustre_ver.h>
@@ -1366,7 +1366,7 @@ int jt_obd_md_common(int argc, char **argv, int cmd)
                                 fprintf(stderr, "Allocate fids error %d.\n",rc);
                                 return rc;
                         }
-                       fid_to_ostid(&fid, &data.ioc_obdo1.o_oi);
+                       data.ioc_obdo1.o_oi.oi_fid = fid;
                 }
 
                 child_base_id += data.ioc_count;
@@ -1494,8 +1494,12 @@ int jt_obd_create(int argc, char **argv)
 
        ostid_set_seq_echo(&data.ioc_obdo1.o_oi);
         for (i = 1, next_count = verbose; i <= count && shmem_running(); i++) {
+               /*
+                * base_id is 1 so we don't need to worry about it being
+                * greater than OBIF_MAX_OID
+                */
+               data.ioc_obdo1.o_oi.oi_fid.f_oid = base_id;
                data.ioc_obdo1.o_mode = mode;
-               ostid_set_id(&data.ioc_obdo1.o_oi, base_id);
                data.ioc_obdo1.o_uid = 0;
                data.ioc_obdo1.o_gid = 0;
                data.ioc_obdo1.o_projid = 0;
@@ -1537,30 +1541,42 @@ int jt_obd_create(int argc, char **argv)
 
 int jt_obd_setattr(int argc, char **argv)
 {
-        struct obd_ioctl_data data;
-        char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
-        char *end;
-        int rc;
+       struct obd_ioctl_data data;
+       char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
+       __u64 objid;
+       char *end;
+       int mode;
+       int rc;
 
         memset(&data, 0, sizeof(data));
         data.ioc_dev = cur_device;
         if (argc != 2)
                 return CMD_HELP;
 
-       ostid_set_seq_echo(&data.ioc_obdo1.o_oi);
-       ostid_set_id(&data.ioc_obdo1.o_oi, strtoull(argv[1], &end, 0));
-        if (*end) {
+       objid = strtoull(argv[1], &end, 0);
+       if (*end) {
+               fprintf(stderr, "error: %s: objid '%s' is not a number\n",
+                       jt_cmdname(argv[0]), argv[1]);
+               return CMD_HELP;
+       }
+
+       if (objid >= OBIF_MAX_OID) {
                 fprintf(stderr, "error: %s: invalid objid '%s'\n",
                         jt_cmdname(argv[0]), argv[1]);
                 return CMD_HELP;
         }
-        data.ioc_obdo1.o_mode = S_IFREG | strtoul(argv[2], &end, 0);
+
+       mode = strtoul(argv[2], &end, 0);
         if (*end) {
                 fprintf(stderr, "error: %s: invalid mode '%s'\n",
                         jt_cmdname(argv[0]), argv[2]);
                 return CMD_HELP;
         }
-        data.ioc_obdo1.o_valid = OBD_MD_FLID | OBD_MD_FLTYPE | OBD_MD_FLMODE;
+
+       ostid_set_seq_echo(&data.ioc_obdo1.o_oi);
+       data.ioc_obdo1.o_mode = S_IFREG | mode;
+       data.ioc_obdo1.o_oi.oi_fid.f_oid = objid;
+       data.ioc_obdo1.o_valid = OBD_MD_FLID | OBD_MD_FLTYPE | OBD_MD_FLMODE;
 
         memset(buf, 0, sizeof(rawbuf));
         rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf));
@@ -1630,7 +1646,13 @@ int jt_obd_test_setattr(int argc, char **argv)
 
        ostid_set_seq_echo(&data.ioc_obdo1.o_oi);
         for (i = 1, next_count = verbose; i <= count && shmem_running(); i++) {
-               ostid_set_id(&data.ioc_obdo1.o_oi, objid);
+               if (objid >= OBIF_MAX_OID) {
+                       fprintf(stderr, "errr: %s: invalid objid '%llu'\n",
+                               jt_cmdname(argv[0]), objid);
+                       return -E2BIG;
+               }
+
+               data.ioc_obdo1.o_oi.oi_fid.f_oid = objid;
                 data.ioc_obdo1.o_mode = S_IFREG;
                 data.ioc_obdo1.o_valid = OBD_MD_FLID | OBD_MD_FLTYPE | OBD_MD_FLMODE;
                 memset(buf, 0, sizeof(rawbuf));
@@ -1716,7 +1738,13 @@ int jt_obd_destroy(int argc, char **argv)
 
        ostid_set_seq_echo(&data.ioc_obdo1.o_oi);
         for (i = 1, next_count = verbose; i <= count && shmem_running(); i++, id++) {
-               ostid_set_id(&data.ioc_obdo1.o_oi, id);
+               if (id >= OBIF_MAX_OID) {
+                       fprintf(stderr, "errr: %s: invalid objid '%llu'\n",
+                               jt_cmdname(argv[0]), id);
+                       return -E2BIG;
+               }
+
+               data.ioc_obdo1.o_oi.oi_fid.f_oid = id;
                data.ioc_obdo1.o_mode = S_IFREG | 0644;
                data.ioc_obdo1.o_valid = OBD_MD_FLID | OBD_MD_FLMODE;
 
@@ -1749,21 +1777,30 @@ int jt_obd_getattr(int argc, char **argv)
 {
         struct obd_ioctl_data data;
         char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
+       __u64 objid;
         char *end;
         int rc;
 
         if (argc != 2)
                 return CMD_HELP;
 
-       memset(&data, 0, sizeof(data));
-       data.ioc_dev = cur_device;
-       ostid_set_seq_echo(&data.ioc_obdo1.o_oi);
-       ostid_set_id(&data.ioc_obdo1.o_oi, strtoull(argv[1], &end, 0));
+       objid = strtoull(argv[1], &end, 0);
        if (*end) {
+               fprintf(stderr, "error: %s: objid '%s' is not a number\n",
+                       jt_cmdname(argv[0]), argv[1]);
+               return CMD_HELP;
+       }
+
+       if (objid >= OBIF_MAX_OID) {
                fprintf(stderr, "error: %s: invalid objid '%s'\n",
                        jt_cmdname(argv[0]), argv[1]);
                return CMD_HELP;
        }
+
+       memset(&data, 0, sizeof(data));
+       data.ioc_dev = cur_device;
+       ostid_set_seq_echo(&data.ioc_obdo1.o_oi);
+       data.ioc_obdo1.o_oi.oi_fid.f_oid = objid;
        /* to help obd filter */
        data.ioc_obdo1.o_mode = 0100644;
        data.ioc_obdo1.o_valid = 0xffffffff;
@@ -1843,7 +1880,13 @@ int jt_obd_test_getattr(int argc, char **argv)
 
        ostid_set_seq_echo(&data.ioc_obdo1.o_oi);
         for (i = 1, next_count = verbose; i <= count && shmem_running(); i++) {
-               ostid_set_id(&data.ioc_obdo1.o_oi, objid);
+               if (objid >= OBIF_MAX_OID) {
+                       fprintf(stderr, "errr: %s: invalid objid '%llu'\n",
+                               jt_cmdname(argv[0]), objid);
+                       return -E2BIG;
+               }
+
+               data.ioc_obdo1.o_oi.oi_fid.f_oid = objid;
                data.ioc_obdo1.o_mode = S_IFREG;
                data.ioc_obdo1.o_valid = 0xffffffff;
                memset(buf, 0, sizeof(rawbuf));
@@ -2050,7 +2093,13 @@ int jt_obd_test_brw(int argc, char **argv)
 #endif
 
        ostid_set_seq_echo(&data.ioc_obdo1.o_oi);
-       ostid_set_id(&data.ioc_obdo1.o_oi, objid);
+       if (objid >= OBIF_MAX_OID) {
+               fprintf(stderr, "errr: %s: invalid objid '%llu'\n",
+                       jt_cmdname(argv[0]), objid);
+               return -E2BIG;
+       }
+
+       data.ioc_obdo1.o_oi.oi_fid.f_oid = objid;
        data.ioc_obdo1.o_mode = S_IFREG;
        data.ioc_obdo1.o_valid = OBD_MD_FLID | OBD_MD_FLTYPE | OBD_MD_FLMODE |
                                 OBD_MD_FLFLAGS | OBD_MD_FLGROUP;