4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2014, Intel Corporation.
28 * Copyright 2015 Cray Inc, all rights reserved.
31 * Define lu_seq_range associated functions
37 #include <lustre/lustre_idl.h>
40 * computes the sequence range type \a range
43 static inline unsigned fld_range_type(const struct lu_seq_range *range)
45 return range->lsr_flags & LU_SEQ_RANGE_MASK;
49 * Is this sequence range an OST? \a range
52 static inline bool fld_range_is_ost(const struct lu_seq_range *range)
54 return fld_range_type(range) == LU_SEQ_RANGE_OST;
58 * Is this sequence range an MDT? \a range
61 static inline bool fld_range_is_mdt(const struct lu_seq_range *range)
63 return fld_range_type(range) == LU_SEQ_RANGE_MDT;
67 * ANY range is only used when the fld client sends a fld query request,
68 * but it does not know whether the seq is an MDT or OST, so it will send the
69 * request with ANY type, which means any seq type from the lookup can be
72 static inline unsigned fld_range_is_any(const struct lu_seq_range *range)
74 return fld_range_type(range) == LU_SEQ_RANGE_ANY;
78 * Apply flags to range \a range \a flags
81 static inline void fld_range_set_type(struct lu_seq_range *range,
84 range->lsr_flags |= flags;
88 * Add MDT to range type \a range
91 static inline void fld_range_set_mdt(struct lu_seq_range *range)
93 fld_range_set_type(range, LU_SEQ_RANGE_MDT);
97 * Add OST to range type \a range
100 static inline void fld_range_set_ost(struct lu_seq_range *range)
102 fld_range_set_type(range, LU_SEQ_RANGE_OST);
106 * Add ANY to range type \a range
109 static inline void fld_range_set_any(struct lu_seq_range *range)
111 fld_range_set_type(range, LU_SEQ_RANGE_ANY);
115 * computes width of given sequence range \a range
118 static inline __u64 lu_seq_range_space(const struct lu_seq_range *range)
120 return range->lsr_end - range->lsr_start;
124 * initialize range to zero \a range
127 static inline void lu_seq_range_init(struct lu_seq_range *range)
129 memset(range, 0, sizeof(*range));
133 * check if given seq id \a s is within given range \a range
136 static inline bool lu_seq_range_within(const struct lu_seq_range *range,
139 return seq >= range->lsr_start && seq < range->lsr_end;
143 * Is the range sane? Is the end after the beginning? \a range
146 static inline bool lu_seq_range_is_sane(const struct lu_seq_range *range)
148 return range->lsr_end >= range->lsr_start;
152 * Is the range 0? \a range
155 static inline bool lu_seq_range_is_zero(const struct lu_seq_range *range)
157 return range->lsr_start == 0 && range->lsr_end == 0;
161 * Is the range out of space? \a range
164 static inline bool lu_seq_range_is_exhausted(const struct lu_seq_range *range)
166 return lu_seq_range_space(range) == 0;
170 * return 0 if two ranges have the same location, nonzero if they are
171 * different \a r1 \a r2
174 static inline int lu_seq_range_compare_loc(const struct lu_seq_range *r1,
175 const struct lu_seq_range *r2)
177 return r1->lsr_index != r2->lsr_index ||
178 r1->lsr_flags != r2->lsr_flags;
182 * printf string and argument list for sequence range
184 #define DRANGE "[%#16.16llx-%#16.16llx]:%x:%s"
186 #define PRANGE(range) \
187 (unsigned long long)(range)->lsr_start, \
188 (unsigned long long)(range)->lsr_end, \
189 (range)->lsr_index, \
190 fld_range_is_mdt(range) ? "mdt" : "ost"