Whamcloud - gitweb
70bbd21ee73a30f20353d6ba6ccacc2be1c19bcc
[fs/lustre-release.git] / lustre / include / lustre / seq_range.h
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
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.
9  *
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).
15  *
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
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2011, 2014, Intel Corporation.
27  *
28  * Copyright 2015 Cray Inc, all rights reserved.
29  * Author: Ben Evans.
30  *
31  * Define lu_seq_range  associated functions
32  */
33
34 #ifndef _SEQ_RANGE_H_
35 #define _SEQ_RANGE_H_
36
37 #include <lustre/lustre_idl.h>
38
39 /**
40  * computes the sequence range type \a range
41  */
42
43 static inline unsigned fld_range_type(const struct lu_seq_range *range)
44 {
45         return range->lsr_flags & LU_SEQ_RANGE_MASK;
46 }
47
48 /**
49  *  Is this sequence range an OST? \a range
50  */
51
52 static inline bool fld_range_is_ost(const struct lu_seq_range *range)
53 {
54         return fld_range_type(range) == LU_SEQ_RANGE_OST;
55 }
56
57 /**
58  *  Is this sequence range an MDT? \a range
59  */
60
61 static inline bool fld_range_is_mdt(const struct lu_seq_range *range)
62 {
63         return fld_range_type(range) == LU_SEQ_RANGE_MDT;
64 }
65
66 /**
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
70  * expected. /a range
71  */
72 static inline unsigned fld_range_is_any(const struct lu_seq_range *range)
73 {
74         return fld_range_type(range) == LU_SEQ_RANGE_ANY;
75 }
76
77 /**
78  * Apply flags to range \a range \a flags
79  */
80
81 static inline void fld_range_set_type(struct lu_seq_range *range,
82                                       unsigned flags)
83 {
84         range->lsr_flags |= flags;
85 }
86
87 /**
88  * Add MDT to range type \a range
89  */
90
91 static inline void fld_range_set_mdt(struct lu_seq_range *range)
92 {
93         fld_range_set_type(range, LU_SEQ_RANGE_MDT);
94 }
95
96 /**
97  * Add OST to range type \a range
98  */
99
100 static inline void fld_range_set_ost(struct lu_seq_range *range)
101 {
102         fld_range_set_type(range, LU_SEQ_RANGE_OST);
103 }
104
105 /**
106  * Add ANY to range type \a range
107  */
108
109 static inline void fld_range_set_any(struct lu_seq_range *range)
110 {
111         fld_range_set_type(range, LU_SEQ_RANGE_ANY);
112 }
113
114 /**
115  * computes width of given sequence range \a range
116  */
117
118 static inline __u64 lu_seq_range_space(const struct lu_seq_range *range)
119 {
120         return range->lsr_end - range->lsr_start;
121 }
122
123 /**
124  * initialize range to zero \a range
125  */
126
127 static inline void lu_seq_range_init(struct lu_seq_range *range)
128 {
129         memset(range, 0, sizeof(*range));
130 }
131
132 /**
133  * check if given seq id \a s is within given range \a range
134  */
135
136 static inline bool lu_seq_range_within(const struct lu_seq_range *range,
137                                        __u64 seq)
138 {
139         return seq >= range->lsr_start && seq < range->lsr_end;
140 }
141
142 /**
143  * Is the range sane?  Is the end after the beginning? \a range
144  */
145
146 static inline bool lu_seq_range_is_sane(const struct lu_seq_range *range)
147 {
148         return range->lsr_end >= range->lsr_start;
149 }
150
151 /**
152  * Is the range 0? \a range
153  */
154
155 static inline bool lu_seq_range_is_zero(const struct lu_seq_range *range)
156 {
157         return range->lsr_start == 0 && range->lsr_end == 0;
158 }
159
160 /**
161  * Is the range out of space? \a range
162  */
163
164 static inline bool lu_seq_range_is_exhausted(const struct lu_seq_range *range)
165 {
166         return lu_seq_range_space(range) == 0;
167 }
168
169 /**
170  * return 0 if two ranges have the same location, nonzero if they are
171  * different \a r1 \a r2
172  */
173
174 static inline int lu_seq_range_compare_loc(const struct lu_seq_range *r1,
175                                            const struct lu_seq_range *r2)
176 {
177         return r1->lsr_index != r2->lsr_index ||
178                 r1->lsr_flags != r2->lsr_flags;
179 }
180
181 #if !defined(__REQ_LAYOUT_USER__)
182 /**
183  * byte swap range structure \a range
184  */
185
186 void lustre_swab_lu_seq_range(struct lu_seq_range *range);
187 #endif
188 /**
189  * printf string and argument list for sequence range
190  */
191 #define DRANGE "[%#16.16llx-%#16.16llx]:%x:%s"
192
193 #define PRANGE(range)                           \
194         (unsigned long long)(range)->lsr_start, \
195         (unsigned long long)(range)->lsr_end,   \
196         (range)->lsr_index,                     \
197         fld_range_is_mdt(range) ? "mdt" : "ost"
198
199 #endif