aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/staging/lustre/lustre/include/seq_range.h
blob: d7175485944dd405c46dd4fdebd3bd1c17173a4b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/*
 * GPL HEADER START
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 only,
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License version 2 for more details (a copy is included
 * in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU General Public License
 * version 2 along with this program; If not, see
 * http://www.gnu.org/licenses/gpl-2.0.html
 *
 * GPL HEADER END
 */
/*
 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
 * Use is subject to license terms.
 *
 * Copyright (c) 2011, 2014, Intel Corporation.
 *
 * Copyright 2015 Cray Inc, all rights reserved.
 * Author: Ben Evans.
 *
 * Define lu_seq_range  associated functions
 */

#ifndef _SEQ_RANGE_H_
#define _SEQ_RANGE_H_

#include <uapi/linux/lustre/lustre_idl.h>

/**
 * computes the sequence range type \a range
 */

static inline unsigned int fld_range_type(const struct lu_seq_range *range)
{
	return range->lsr_flags & LU_SEQ_RANGE_MASK;
}

/**
 *  Is this sequence range an OST? \a range
 */

static inline bool fld_range_is_ost(const struct lu_seq_range *range)
{
	return fld_range_type(range) == LU_SEQ_RANGE_OST;
}

/**
 *  Is this sequence range an MDT? \a range
 */

static inline bool fld_range_is_mdt(const struct lu_seq_range *range)
{
	return fld_range_type(range) == LU_SEQ_RANGE_MDT;
}

/**
 * ANY range is only used when the fld client sends a fld query request,
 * but it does not know whether the seq is an MDT or OST, so it will send the
 * request with ANY type, which means any seq type from the lookup can be
 * expected. /a range
 */
static inline unsigned int fld_range_is_any(const struct lu_seq_range *range)
{
	return fld_range_type(range) == LU_SEQ_RANGE_ANY;
}

/**
 * Apply flags to range \a range \a flags
 */

static inline void fld_range_set_type(struct lu_seq_range *range,
				      unsigned int flags)
{
	range->lsr_flags |= flags;
}

/**
 * Add MDT to range type \a range
 */

static inline void fld_range_set_mdt(struct lu_seq_range *range)
{
	fld_range_set_type(range, LU_SEQ_RANGE_MDT);
}

/**
 * Add OST to range type \a range
 */

static inline void fld_range_set_ost(struct lu_seq_range *range)
{
	fld_range_set_type(range, LU_SEQ_RANGE_OST);
}

/**
 * Add ANY to range type \a range
 */

static inline void fld_range_set_any(struct lu_seq_range *range)
{
	fld_range_set_type(range, LU_SEQ_RANGE_ANY);
}

/**
 * computes width of given sequence range \a range
 */

static inline u64 lu_seq_range_space(const struct lu_seq_range *range)
{
	return range->lsr_end - range->lsr_start;
}

/**
 * initialize range to zero \a range
 */

static inline void lu_seq_range_init(struct lu_seq_range *range)
{
	memset(range, 0, sizeof(*range));
}

/**
 * check if given seq id \a s is within given range \a range
 */

static inline bool lu_seq_range_within(const struct lu_seq_range *range,
				       u64 seq)
{
	return seq >= range->lsr_start && seq < range->lsr_end;
}

/**
 * Is the range sane?  Is the end after the beginning? \a range
 */

static inline bool lu_seq_range_is_sane(const struct lu_seq_range *range)
{
	return range->lsr_end >= range->lsr_start;
}

/**
 * Is the range 0? \a range
 */

static inline bool lu_seq_range_is_zero(const struct lu_seq_range *range)
{
	return range->lsr_start == 0 && range->lsr_end == 0;
}

/**
 * Is the range out of space? \a range
 */

static inline bool lu_seq_range_is_exhausted(const struct lu_seq_range *range)
{
	return lu_seq_range_space(range) == 0;
}

/**
 * return 0 if two ranges have the same location, nonzero if they are
 * different \a r1 \a r2
 */

static inline int lu_seq_range_compare_loc(const struct lu_seq_range *r1,
					   const struct lu_seq_range *r2)
{
	return r1->lsr_index != r2->lsr_index ||
		r1->lsr_flags != r2->lsr_flags;
}

#if !defined(__REQ_LAYOUT_USER__)
/**
 * byte swap range structure \a range
 */

void lustre_swab_lu_seq_range(struct lu_seq_range *range);
#endif
/**
 * printf string and argument list for sequence range
 */
#define DRANGE "[%#16.16llx-%#16.16llx]:%x:%s"

#define PRANGE(range)		\
	(range)->lsr_start,	\
	(range)->lsr_end,	\
	(range)->lsr_index,	\
	fld_range_is_mdt(range) ? "mdt" : "ost"

#endif