From bb2f0dac868cf1321277bc3d7d6fc71f016d921b Mon Sep 17 00:00:00 2001 From: Li Dongyang Date: Wed, 24 Nov 2021 10:45:48 +1100 Subject: [PATCH] LU-11912 fid: clean up OBIF_MAX_OID and IDIF_MAX_OID Define the OBIF|IDIF_MAX_OID macros to 1ULL << OBIF|IDIF_MAX_BITS - 1 Clean up the callers and remove OBIF|IDIF_OID_MASK which are not used. Test-Parameters: trivial Change-Id: I9a679b930c73da5904b2eb4c74f785fc1d27a8a0 Signed-off-by: Li Dongyang Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/45659 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Sergey Cheremencev Reviewed-by: Oleg Drokin --- lustre/include/lustre_fid.h | 8 ++++---- lustre/include/uapi/linux/lustre/lustre_idl.h | 6 ++---- lustre/include/uapi/linux/lustre/lustre_ostid.h | 4 ++-- lustre/ofd/ofd_dev.c | 2 +- lustre/ofd/ofd_io.c | 2 +- lustre/ofd/ofd_objects.c | 9 ++++++--- lustre/utils/obd.c | 12 ++++++------ 7 files changed, 22 insertions(+), 21 deletions(-) diff --git a/lustre/include/lustre_fid.h b/lustre/include/lustre_fid.h index e82b847..86e5986 100644 --- a/lustre/include/lustre_fid.h +++ b/lustre/include/lustre_fid.h @@ -713,18 +713,18 @@ static inline bool ostid_res_name_eq(const struct ost_id *oi, 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) + 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) + 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) + if (oid > OBIF_MAX_OID) return -E2BIG; oi->oi_fid.f_oid = oid; } @@ -868,7 +868,7 @@ static inline int fid_set_id(struct lu_fid *fid, u64 oid) } if (fid_is_idif(fid)) { - if (oid >= IDIF_MAX_OID) { + if (oid > IDIF_MAX_OID) { CERROR("Too large OID %#llx to set IDIF "DFID"\n", (unsigned long long)oid, PFID(fid)); return -EBADF; diff --git a/lustre/include/uapi/linux/lustre/lustre_idl.h b/lustre/include/uapi/linux/lustre/lustre_idl.h index d8c432e..4d8b326 100644 --- a/lustre/include/uapi/linux/lustre/lustre_idl.h +++ b/lustre/include/uapi/linux/lustre/lustre_idl.h @@ -316,11 +316,9 @@ enum fid_seq { }; #define OBIF_OID_MAX_BITS 32 -#define OBIF_MAX_OID (1ULL << OBIF_OID_MAX_BITS) -#define OBIF_OID_MASK ((1ULL << OBIF_OID_MAX_BITS) - 1) +#define OBIF_MAX_OID ((1ULL << OBIF_OID_MAX_BITS) - 1) #define IDIF_OID_MAX_BITS 48 -#define IDIF_MAX_OID (1ULL << IDIF_OID_MAX_BITS) -#define IDIF_OID_MASK ((1ULL << IDIF_OID_MAX_BITS) - 1) +#define IDIF_MAX_OID ((1ULL << IDIF_OID_MAX_BITS) - 1) /** OID for FID_SEQ_SPECIAL */ enum special_oid { diff --git a/lustre/include/uapi/linux/lustre/lustre_ostid.h b/lustre/include/uapi/linux/lustre/lustre_ostid.h index 90fa213..baf7c8f 100644 --- a/lustre/include/uapi/linux/lustre/lustre_ostid.h +++ b/lustre/include/uapi/linux/lustre/lustre_ostid.h @@ -91,7 +91,7 @@ static inline __u64 ostid_seq(const struct ost_id *ostid) static inline __u64 ostid_id(const struct ost_id *ostid) { if (fid_seq_is_mdt0(ostid->oi.oi_seq)) - return ostid->oi.oi_id & IDIF_OID_MASK; + return ostid->oi.oi_id & IDIF_MAX_OID; if (fid_seq_is_default(ostid->oi.oi_seq)) return ostid->oi.oi_id; @@ -212,7 +212,7 @@ 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) + if (oid > IDIF_MAX_OID) return -EBADF; fid->f_seq = fid_idif_seq(oid, ost_idx); diff --git a/lustre/ofd/ofd_dev.c b/lustre/ofd/ofd_dev.c index cb1ac93..087c715 100644 --- a/lustre/ofd/ofd_dev.c +++ b/lustre/ofd/ofd_dev.c @@ -1579,7 +1579,7 @@ static int ofd_create_hdl(struct tgt_session_info *tsi) diff = oid - ofd_seq_last_oid(oseq); /* Do sync create if the seq is about to used up */ if (fid_seq_is_idif(seq) || fid_seq_is_mdt0(seq)) { - if (unlikely(oid >= IDIF_MAX_OID - 1)) + if (unlikely(oid >= IDIF_MAX_OID)) sync_trans = 1; } else if (fid_seq_is_norm(seq)) { if (unlikely(oid >= diff --git a/lustre/ofd/ofd_io.c b/lustre/ofd/ofd_io.c index 9b6981f..8c1b798 100644 --- a/lustre/ofd/ofd_io.c +++ b/lustre/ofd/ofd_io.c @@ -737,7 +737,7 @@ static int ofd_preprw_write(const struct lu_env *env, struct obd_export *exp, /* Do sync create if the seq is about to used up */ if (fid_seq_is_idif(seq) || fid_seq_is_mdt0(seq)) { - if (unlikely(oid >= IDIF_MAX_OID - 1)) + if (unlikely(oid >= IDIF_MAX_OID)) sync = 1; } else if (fid_seq_is_norm(seq)) { if (unlikely(oid >= diff --git a/lustre/ofd/ofd_objects.c b/lustre/ofd/ofd_objects.c index 3abab0f..8423734 100644 --- a/lustre/ofd/ofd_objects.c +++ b/lustre/ofd/ofd_objects.c @@ -264,14 +264,17 @@ int ofd_precreate_objects(const struct lu_env *env, struct ofd_device *ofd, ENTRY; - /* Don't create objects beyond the valid range for this SEQ */ + /* Don't create objects beyond the valid range for this SEQ + * Last object to create is (id + nr - 1), but we move -1 on LHS + * to +1 on RHS to evaluate constant at compile time. LU-11186 + */ if (unlikely(fid_seq_is_mdt0(ostid_seq(&oseq->os_oi)) && - (id + nr) > IDIF_MAX_OID)) { + id + nr > IDIF_MAX_OID + 1)) { CERROR("%s:"DOSTID" hit the IDIF_MAX_OID (1<<48)!\n", ofd_name(ofd), id, ostid_seq(&oseq->os_oi)); RETURN(rc = -ENOSPC); } else if (unlikely(!fid_seq_is_mdt0(ostid_seq(&oseq->os_oi)) && - (id + nr) > OBIF_MAX_OID)) { + id + nr > OBIF_MAX_OID + 1)) { CERROR("%s:"DOSTID" hit the OBIF_MAX_OID (1<<32)!\n", ofd_name(ofd), id, ostid_seq(&oseq->os_oi)); RETURN(rc = -ENOSPC); diff --git a/lustre/utils/obd.c b/lustre/utils/obd.c index b0ac9e9..d07da81 100644 --- a/lustre/utils/obd.c +++ b/lustre/utils/obd.c @@ -1476,7 +1476,7 @@ int jt_obd_setattr(int argc, char **argv) return CMD_HELP; } - if (objid >= OBIF_MAX_OID) { + if (objid > OBIF_MAX_OID) { fprintf(stderr, "error: %s: invalid objid '%s'\n", jt_cmdname(argv[0]), argv[1]); return CMD_HELP; @@ -1563,7 +1563,7 @@ 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++) { - if (objid >= OBIF_MAX_OID) { + if (objid > OBIF_MAX_OID) { fprintf(stderr, "errr: %s: invalid objid '%llu'\n", jt_cmdname(argv[0]), (unsigned long long)objid); return -E2BIG; @@ -1656,7 +1656,7 @@ 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++) { - if (id >= OBIF_MAX_OID) { + if (id > OBIF_MAX_OID) { fprintf(stderr, "errr: %s: invalid objid '%llu'\n", jt_cmdname(argv[0]), (unsigned long long)id); return -E2BIG; @@ -1700,7 +1700,7 @@ static int jt_str_to_ost_id(const char *str, struct ost_id *oi) if (*end == '\0') { /* If str is a single number then assume old echo * client usage. */ - if (oid >= OBIF_MAX_OID) + if (oid > OBIF_MAX_OID) return -EINVAL; ostid_set_seq_echo(oi); @@ -1847,7 +1847,7 @@ 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++) { - if (objid >= OBIF_MAX_OID) { + if (objid > OBIF_MAX_OID) { fprintf(stderr, "errr: %s: invalid objid '%llu'\n", jt_cmdname(argv[0]), (unsigned long long)objid); return -E2BIG; @@ -2058,7 +2058,7 @@ int jt_obd_test_brw(int argc, char **argv) #endif ostid_set_seq_echo(&data.ioc_obdo1.o_oi); - if (objid >= OBIF_MAX_OID) { + if (objid > OBIF_MAX_OID) { fprintf(stderr, "errr: %s: invalid objid '%llu'\n", jt_cmdname(argv[0]), (unsigned long long)objid); return -E2BIG; -- 1.8.3.1