linux/drivers/staging/lustre/lustre/include/seq_range.h
<<
>>
Prefs
   1// SPDX-License-Identifier: GPL-2.0
   2/*
   3 * GPL HEADER START
   4 *
   5 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   6 *
   7 * This program is free software; you can redistribute it and/or modify
   8 * it under the terms of the GNU General Public License version 2 only,
   9 * as published by the Free Software Foundation.
  10 *
  11 * This program is distributed in the hope that it will be useful, but
  12 * WITHOUT ANY WARRANTY; without even the implied warranty of
  13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14 * General Public License version 2 for more details (a copy is included
  15 * in the LICENSE file that accompanied this code).
  16 *
  17 * You should have received a copy of the GNU General Public License
  18 * version 2 along with this program; If not, see
  19 * http://www.gnu.org/licenses/gpl-2.0.html
  20 *
  21 * GPL HEADER END
  22 */
  23/*
  24 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  25 * Use is subject to license terms.
  26 *
  27 * Copyright (c) 2011, 2014, Intel Corporation.
  28 *
  29 * Copyright 2015 Cray Inc, all rights reserved.
  30 * Author: Ben Evans.
  31 *
  32 * Define lu_seq_range  associated functions
  33 */
  34
  35#ifndef _SEQ_RANGE_H_
  36#define _SEQ_RANGE_H_
  37
  38#include <uapi/linux/lustre/lustre_idl.h>
  39
  40/**
  41 * computes the sequence range type \a range
  42 */
  43
  44static inline unsigned int fld_range_type(const struct lu_seq_range *range)
  45{
  46        return range->lsr_flags & LU_SEQ_RANGE_MASK;
  47}
  48
  49/**
  50 *  Is this sequence range an OST? \a range
  51 */
  52
  53static inline bool fld_range_is_ost(const struct lu_seq_range *range)
  54{
  55        return fld_range_type(range) == LU_SEQ_RANGE_OST;
  56}
  57
  58/**
  59 *  Is this sequence range an MDT? \a range
  60 */
  61
  62static inline bool fld_range_is_mdt(const struct lu_seq_range *range)
  63{
  64        return fld_range_type(range) == LU_SEQ_RANGE_MDT;
  65}
  66
  67/**
  68 * ANY range is only used when the fld client sends a fld query request,
  69 * but it does not know whether the seq is an MDT or OST, so it will send the
  70 * request with ANY type, which means any seq type from the lookup can be
  71 * expected. /a range
  72 */
  73static inline unsigned int fld_range_is_any(const struct lu_seq_range *range)
  74{
  75        return fld_range_type(range) == LU_SEQ_RANGE_ANY;
  76}
  77
  78/**
  79 * Apply flags to range \a range \a flags
  80 */
  81
  82static inline void fld_range_set_type(struct lu_seq_range *range,
  83                                      unsigned int flags)
  84{
  85        range->lsr_flags |= flags;
  86}
  87
  88/**
  89 * Add MDT to range type \a range
  90 */
  91
  92static inline void fld_range_set_mdt(struct lu_seq_range *range)
  93{
  94        fld_range_set_type(range, LU_SEQ_RANGE_MDT);
  95}
  96
  97/**
  98 * Add OST to range type \a range
  99 */
 100
 101static inline void fld_range_set_ost(struct lu_seq_range *range)
 102{
 103        fld_range_set_type(range, LU_SEQ_RANGE_OST);
 104}
 105
 106/**
 107 * Add ANY to range type \a range
 108 */
 109
 110static inline void fld_range_set_any(struct lu_seq_range *range)
 111{
 112        fld_range_set_type(range, LU_SEQ_RANGE_ANY);
 113}
 114
 115/**
 116 * computes width of given sequence range \a range
 117 */
 118
 119static inline u64 lu_seq_range_space(const struct lu_seq_range *range)
 120{
 121        return range->lsr_end - range->lsr_start;
 122}
 123
 124/**
 125 * initialize range to zero \a range
 126 */
 127
 128static inline void lu_seq_range_init(struct lu_seq_range *range)
 129{
 130        memset(range, 0, sizeof(*range));
 131}
 132
 133/**
 134 * check if given seq id \a s is within given range \a range
 135 */
 136
 137static inline bool lu_seq_range_within(const struct lu_seq_range *range,
 138                                       u64 seq)
 139{
 140        return seq >= range->lsr_start && seq < range->lsr_end;
 141}
 142
 143/**
 144 * Is the range sane?  Is the end after the beginning? \a range
 145 */
 146
 147static inline bool lu_seq_range_is_sane(const struct lu_seq_range *range)
 148{
 149        return range->lsr_end >= range->lsr_start;
 150}
 151
 152/**
 153 * Is the range 0? \a range
 154 */
 155
 156static inline bool lu_seq_range_is_zero(const struct lu_seq_range *range)
 157{
 158        return range->lsr_start == 0 && range->lsr_end == 0;
 159}
 160
 161/**
 162 * Is the range out of space? \a range
 163 */
 164
 165static inline bool lu_seq_range_is_exhausted(const struct lu_seq_range *range)
 166{
 167        return lu_seq_range_space(range) == 0;
 168}
 169
 170/**
 171 * return 0 if two ranges have the same location, nonzero if they are
 172 * different \a r1 \a r2
 173 */
 174
 175static inline int lu_seq_range_compare_loc(const struct lu_seq_range *r1,
 176                                           const struct lu_seq_range *r2)
 177{
 178        return r1->lsr_index != r2->lsr_index ||
 179                r1->lsr_flags != r2->lsr_flags;
 180}
 181
 182#if !defined(__REQ_LAYOUT_USER__)
 183/**
 184 * byte swap range structure \a range
 185 */
 186
 187void lustre_swab_lu_seq_range(struct lu_seq_range *range);
 188#endif
 189/**
 190 * printf string and argument list for sequence range
 191 */
 192#define DRANGE "[%#16.16llx-%#16.16llx]:%x:%s"
 193
 194#define PRANGE(range)           \
 195        (range)->lsr_start,     \
 196        (range)->lsr_end,       \
 197        (range)->lsr_index,     \
 198        fld_range_is_mdt(range) ? "mdt" : "ost"
 199
 200#endif
 201