linux/drivers/staging/lustre/lustre/include/lustre_lib.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, 2012, Intel Corporation.
  28 */
  29/*
  30 * This file is part of Lustre, http://www.lustre.org/
  31 * Lustre is a trademark of Sun Microsystems, Inc.
  32 *
  33 * lustre/include/lustre_lib.h
  34 *
  35 * Basic Lustre library routines.
  36 */
  37
  38#ifndef _LUSTRE_LIB_H
  39#define _LUSTRE_LIB_H
  40
  41/** \defgroup lib lib
  42 *
  43 * @{
  44 */
  45
  46#include <linux/sched/signal.h>
  47#include <linux/signal.h>
  48#include <linux/types.h>
  49#include <linux/libcfs/libcfs.h>
  50#include <uapi/linux/lustre/lustre_idl.h>
  51#include <uapi/linux/lustre/lustre_ver.h>
  52#include <uapi/linux/lustre/lustre_cfg.h>
  53
  54/* target.c */
  55struct ptlrpc_request;
  56struct obd_export;
  57struct lu_target;
  58struct l_wait_info;
  59#include <lustre_ha.h>
  60#include <lustre_net.h>
  61
  62#define LI_POISON 0x5a5a5a5a
  63#if BITS_PER_LONG > 32
  64# define LL_POISON 0x5a5a5a5a5a5a5a5aL
  65#else
  66# define LL_POISON 0x5a5a5a5aL
  67#endif
  68#define LP_POISON ((void *)LL_POISON)
  69
  70int target_pack_pool_reply(struct ptlrpc_request *req);
  71int do_set_info_async(struct obd_import *imp,
  72                      int opcode, int version,
  73                      u32 keylen, void *key,
  74                      u32 vallen, void *val,
  75                      struct ptlrpc_request_set *set);
  76
  77void target_send_reply(struct ptlrpc_request *req, int rc, int fail_id);
  78
  79#define LUSTRE_FATAL_SIGS (sigmask(SIGKILL) | sigmask(SIGINT) |         \
  80                           sigmask(SIGTERM) | sigmask(SIGQUIT) |        \
  81                           sigmask(SIGALRM))
  82static inline int l_fatal_signal_pending(struct task_struct *p)
  83{
  84        return signal_pending(p) && sigtestsetmask(&p->pending.signal, LUSTRE_FATAL_SIGS);
  85}
  86
  87/** @} lib */
  88
  89
  90
  91/* l_wait_event_abortable() is a bit like wait_event_killable()
  92 * except there is a fixed set of signals which will abort:
  93 * LUSTRE_FATAL_SIGS
  94 */
  95#define l_wait_event_abortable(wq, condition)                           \
  96({                                                                      \
  97        sigset_t __old_blocked;                                         \
  98        int __ret = 0;                                                  \
  99        cfs_block_sigsinv(LUSTRE_FATAL_SIGS, &__old_blocked);           \
 100        __ret = wait_event_interruptible(wq, condition);                \
 101        cfs_restore_sigs(&__old_blocked);                               \
 102        __ret;                                                          \
 103})
 104
 105#define l_wait_event_abortable_timeout(wq, condition, timeout)          \
 106({                                                                      \
 107        sigset_t __old_blocked;                                         \
 108        int __ret = 0;                                                  \
 109        cfs_block_sigsinv(LUSTRE_FATAL_SIGS, &__old_blocked);           \
 110        __ret = wait_event_interruptible_timeout(wq, condition, timeout);\
 111        cfs_restore_sigs(&__old_blocked);                               \
 112        __ret;                                                          \
 113})
 114
 115#define l_wait_event_abortable_exclusive(wq, condition)                 \
 116({                                                                      \
 117        sigset_t __old_blocked;                                         \
 118        int __ret = 0;                                                  \
 119        cfs_block_sigsinv(LUSTRE_FATAL_SIGS, &__old_blocked);           \
 120        __ret = wait_event_interruptible_exclusive(wq, condition);      \
 121        cfs_restore_sigs(&__old_blocked);                               \
 122        __ret;                                                          \
 123})
 124#endif /* _LUSTRE_LIB_H */
 125